| 211 | } |
| 212 | |
| 213 | Socket::Status TcpSocket::receive( void* data, std::size_t size, std::size_t& received ) { |
| 214 | // First clear the variables to fill |
| 215 | received = 0; |
| 216 | |
| 217 | // Check the destination buffer |
| 218 | if ( !data ) { |
| 219 | Log::error( "Cannot receive data from the network (the destination buffer is invalid)" ); |
| 220 | return Error; |
| 221 | } |
| 222 | |
| 223 | // Receive a chunk of bytes |
| 224 | int sizeReceived = |
| 225 | recv( getHandle(), static_cast<char*>( data ), static_cast<int>( size ), flags ); |
| 226 | |
| 227 | // Check the number of bytes received |
| 228 | if ( sizeReceived > 0 ) { |
| 229 | received = static_cast<std::size_t>( sizeReceived ); |
| 230 | return Done; |
| 231 | } else if ( sizeReceived == 0 ) { |
| 232 | return Socket::Disconnected; |
| 233 | } else { |
| 234 | return Private::SocketImpl::getErrorStatus(); |
| 235 | } |
| 236 | } |
| 237 | |
| 238 | Socket::Status TcpSocket::send( Packet& packet ) { |
| 239 | // TCP is a stream protocol, it doesn't preserve messages boundaries. |