diff options
Diffstat (limited to 'src/wsocket.c')
| -rw-r--r-- | src/wsocket.c | 9 |
1 files changed, 9 insertions, 0 deletions
diff --git a/src/wsocket.c b/src/wsocket.c index d3af9d4..b2b668c 100644 --- a/src/wsocket.c +++ b/src/wsocket.c | |||
| @@ -247,6 +247,7 @@ int socket_recv(p_socket ps, char *data, size_t count, size_t *got, | |||
| 247 | int err, prev = IO_DONE; | 247 | int err, prev = IO_DONE; |
| 248 | *got = 0; | 248 | *got = 0; |
| 249 | if (*ps == SOCKET_INVALID) return IO_CLOSED; | 249 | if (*ps == SOCKET_INVALID) return IO_CLOSED; |
| 250 | if (count == 0) return IO_DONE; | ||
| 250 | for ( ;; ) { | 251 | for ( ;; ) { |
| 251 | int taken = recv(*ps, data, (int) count, 0); | 252 | int taken = recv(*ps, data, (int) count, 0); |
| 252 | if (taken > 0) { | 253 | if (taken > 0) { |
| @@ -285,6 +286,14 @@ int socket_recvfrom(p_socket ps, char *data, size_t count, size_t *got, | |||
| 285 | } | 286 | } |
| 286 | if (taken == 0) return IO_CLOSED; | 287 | if (taken == 0) return IO_CLOSED; |
| 287 | err = WSAGetLastError(); | 288 | err = WSAGetLastError(); |
| 289 | /* a zero-length request is trivially "too small" for any | ||
| 290 | * non-empty datagram; unlike POSIX, which truncates and succeeds | ||
| 291 | * silently, Windows reports this as WSAEMSGSIZE even though the | ||
| 292 | * datagram -- and its sender's address, already written to addr/ | ||
| 293 | * len above -- was still consumed. Normalize it to match POSIX's | ||
| 294 | * silent-truncation instead of surfacing a platform-specific | ||
| 295 | * error for what is otherwise a successful, if empty, receive. */ | ||
| 296 | if (count == 0 && err == WSAEMSGSIZE) return IO_DONE; | ||
| 288 | /* On UDP, a connreset simply means the previous send failed. | 297 | /* On UDP, a connreset simply means the previous send failed. |
| 289 | * So we try again. | 298 | * So we try again. |
| 290 | * On TCP, it means our socket is now useless, so the error passes. | 299 | * On TCP, it means our socket is now useless, so the error passes. |
