| 228 | class TCPConnection { |
| 229 | public: |
| 230 | TCPConnection(const SocketAddress& peerAddress,SocketFile& file,const SocketManager& manager) : _client(peerAddress,file, manager) { |
| 231 | onData = [this](PoolBuffer& pBuffer) { |
| 232 | Exception ex; |
| 233 | CHECK(_client.send(ex, pBuffer->data(), pBuffer->size()) && !ex); |
| 234 | return pBuffer->size(); |
| 235 | }; |
| 236 | onError = [this](const Exception& ex) { |
| 237 | FATAL_ERROR("Client, ",ex.error()); |
| 238 | }; |
| 239 | onDisconnection = [this](TCPClient& client, const SocketAddress& peerAddress){ |
| 240 | CHECK(!_client.connected()); |
| 241 | }; |
| 242 | _client.OnError::subscribe(onError); |
| 243 | _client.OnData::subscribe(onData); |
| 244 | _client.OnDisconnection::subscribe(onDisconnection); |
| 245 | } |
| 246 | |
| 247 | ~TCPConnection() { |
| 248 | _client.OnError::unsubscribe(onError); |