| 90 | } |
| 91 | |
| 92 | bool CConnection::Read(int maxSize) |
| 93 | { |
| 94 | if (DataReady == -1) |
| 95 | { |
| 96 | Error(Network, "CConnection::Read, m_DataReady=%i", DataReady); |
| 97 | Disconnect(); |
| 98 | } |
| 99 | else if (Connected && m_Socket != nullptr) |
| 100 | { |
| 101 | std::vector<uint8_t> data(maxSize); |
| 102 | const int size = tcp_recv(m_Socket, &data[0], maxSize); |
| 103 | |
| 104 | if (size > 0) |
| 105 | { |
| 106 | //TRACE(Network, "CConnection::Read size=%i", size); |
| 107 | data.resize(size); |
| 108 | data = Decompression(data); |
| 109 | m_MessageParser->Append(data); |
| 110 | return true; |
| 111 | } |
| 112 | |
| 113 | Error(Network, "CConnection::Read, bad size=%i", size); |
| 114 | } |
| 115 | else |
| 116 | { |
| 117 | Error(Network, "CConnection::Read, unknown state, m_Connected=%i", Connected); |
| 118 | } |
| 119 | return false; |
| 120 | } |
| 121 | |
| 122 | int CConnection::Send(uint8_t *data, int size) |
| 123 | { |