| 234 | return allSize; |
| 235 | } |
| 236 | int SocketReceive(SOCKET sck, char* destination, size_t size, int timeOut) |
| 237 | { |
| 238 | TIMEVAL tv = { timeOut, 0 }; |
| 239 | fd_set fdSet; |
| 240 | FD_ZERO(&fdSet); |
| 241 | FD_SET(sck, &fdSet); |
| 242 | |
| 243 | int active = select(0, &fdSet, NULL, NULL, &tv); |
| 244 | if(active == SOCKET_ERROR) |
| 245 | { |
| 246 | printf("SocketReceive: select failed\n"); |
| 247 | return -1; |
| 248 | } |
| 249 | if(!FD_ISSET(sck, &fdSet)) |
| 250 | { |
| 251 | printf("SocketReceive: select timeout\n"); |
| 252 | return 0; |
| 253 | } |
| 254 | |
| 255 | int allSize = (int)size; |
| 256 | while(size) |
| 257 | { |
| 258 | int bytesRecv; |
| 259 | if((bytesRecv = recv(sck, destination + (allSize - size), (int)size, 0)) == SOCKET_ERROR || bytesRecv == 0) |
| 260 | { |
| 261 | printf("recv failed\n"); |
| 262 | return -1; |
| 263 | } |
| 264 | size -= bytesRecv; |
| 265 | if(size) |
| 266 | printf("Partial recv\n"); |
| 267 | } |
| 268 | return allSize; |
| 269 | } |
| 270 | } |
| 271 | |
| 272 | char* GetLastErrorDesc() |
no outgoing calls
no test coverage detected