-
Notifications
You must be signed in to change notification settings - Fork 0
/
echo_task.cc
55 lines (46 loc) · 1.48 KB
/
echo_task.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
/*******************************************
Author : Jun Zhang
Email : ewalker.zj@gmail.com
Last Modified : 2019-06-15 14:54
Filename : echo_task.cc
Description :
*******************************************/
#include "echo_task.h"
void EchoTask::Run(){
// handle
//printf("recv msg: %s\n", input.getBuffer());
printf("recv msg: %s\n", input.c_str());
}
bool EchoTask::Read(){
}
bool EchoTask::Write(){
}
bool EchoTask::ParseRequest() {
if(!request_.ParseFromString(input)) {
return -1;
}
width_val = request_.width_val();
req_id = request_.req_id();
body_item = request_.data();
}
bool EchoTask::MakeResponse(const std::string &content) {
response_.set_req_id(req_id);
response_.set_width_val(width_val);
response_.set_data(content);
}
bool EchoTask::send_data(const std::string& content) {
//(sock_item_ -> out).strscat(content.c_str(), content.size());
printf("out size: %d\n", (sock_item_ -> out).size());
//(sock_item_ -> out).memcpy(content.c_str(), content.size());
//printf("content: %s\n", content.c_str());
MakeResponse(content);
std::string response_data;
if(!response_.SerializeToString(&response_data)) {
}
(sock_item_ -> data).clear();
(sock_item_ -> data).append(response_data);
struct epoll_event ev;
ev.data.fd = epoll_offset_;
ev.events = EPOLLOUT | EPOLLET;
epoll_ctl(epoll_fd_, EPOLL_CTL_MOD, sock_item_ -> sock, &ev);
}