MCPcopy Create free account
hub / github.com/acl-dev/acl / handle_pkg

Method handle_pkg

lib_acl_cpp/samples/aio/pkg_client/main.cpp:63–117  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

61
62private:
63 bool handle_pkg(acl::socket_stream& conn, int i)
64 {
65 DAT_HDR req_hdr;
66 req_hdr.len = htonl(length_);
67 ACL_SAFE_STRNCPY(req_hdr.cmd, "SEND", sizeof(req_hdr.cmd));
68
69 // ��д����ͷ
70 if (conn.write(&req_hdr, sizeof(req_hdr)) == -1) {
71 printf("write hdr to server failed\r\n");
72 return false;
73 }
74
75 // �������
76 if (conn.write(req_dat_, length_) == -1) {
77 printf("write dat to server failed\r\n");
78 return false;
79 }
80
81 //////////////////////////////////////////////////////////////
82
83 // �ȶ���Ӧͷ
84 DAT_HDR res;
85 if (conn.read(&res, sizeof(DAT_HDR)) == -1) {
86 printf("read DAT_HDR error\r\n");
87 return false;
88 }
89
90 // ����Ӧ�����ݳ���תΪ�����ֽ���
91 res.len = ntohl(res.len);
92 if (res.len <= 0) {
93 printf("invalid length: %d\r\n", res.len);
94 return false;
95 }
96
97 // ����Ƿ���Ҫ���·������Ӧ���ݵ��ڴ�
98 if (res.len + 1 >= res_max_) {
99 res_max_ = res.len + 1;
100 res_dat_ = (char*) realloc(res_dat_, res_max_);
101 }
102
103 // �ٶ���Ӧ��
104 if (conn.read(res_dat_, res.len) == -1) {
105 printf("read data error, len: %d\r\n", res.len);
106 return false;
107 }
108
109 res_dat_[res.len] = 0;
110 if (i < 10) {
111 printf("thread: %lu, cmd: %s, dat: %s, len: %d\r\n",
112 (unsigned long) thread_id(), res.cmd,
113 res_dat_, res.len);
114 }
115
116 return true;
117 }
118
119private:
120 acl::string addr_;

Callers

nothing calls this directly

Calls 3

reallocFunction · 0.85
writeMethod · 0.45
readMethod · 0.45

Tested by

no test coverage detected