| 87 | } |
| 88 | |
| 89 | int NetIO::Receive(const int &fd, string *data) { |
| 90 | if (fd < 0) |
| 91 | return SOCKET_FAIL; |
| 92 | |
| 93 | char header[1024]; |
| 94 | int header_len = 4; |
| 95 | |
| 96 | int ret = Receive(fd, header, header_len); |
| 97 | if (ret) { |
| 98 | return ret; |
| 99 | } |
| 100 | |
| 101 | int body_len = 0; |
| 102 | memcpy(&body_len, header, 3); |
| 103 | |
| 104 | data->resize(body_len + header_len); |
| 105 | memcpy((char *) data->c_str(), header, header_len); |
| 106 | |
| 107 | return Receive(fd, (char *) data->c_str() + header_len, body_len); |
| 108 | } |
| 109 | |
| 110 | int NetIO::Receive(const int &fd, char *buffer, const size_t &buffer_len) { |
| 111 | if (fd < 0) |
nothing calls this directly
no test coverage detected