| 240 | } |
| 241 | |
| 242 | int CBlockingSocket::Receive(char* pch, int nSize, int nSecs) const |
| 243 | { |
| 244 | ASSERT( pch != NULL ); |
| 245 | ASSERT( m_hSocket!=INVALID_SOCKET ); |
| 246 | |
| 247 | fd_set fd; |
| 248 | FD_ZERO(&fd); |
| 249 | FD_SET(m_hSocket, &fd); |
| 250 | TIMEVAL tv = { nSecs, 0 }; |
| 251 | |
| 252 | // static_cast is necessary to avoid compiler warning under WIN32; |
| 253 | // This is no problem because the first parameter is included only |
| 254 | // for compatibility with Berkeley sockets. |
| 255 | if( _select(m_hSocket+1, &fd, NULL, NULL, &tv)==0 ) |
| 256 | { |
| 257 | throw CBlockingSocketException(_T("Receive timeout")); |
| 258 | } |
| 259 | |
| 260 | const int nBytesReceived = recv(m_hSocket, pch, nSize, 0); |
| 261 | if( nBytesReceived==SOCKET_ERROR ) |
| 262 | { |
| 263 | throw CBlockingSocketException(_T("Receive")); |
| 264 | } |
| 265 | |
| 266 | return nBytesReceived; |
| 267 | } |
| 268 | |
| 269 | int CBlockingSocket::ReceiveDatagram(char* pch, int nSize, LPSOCKADDR psa, int nSecs) const |
| 270 | { |
no test coverage detected