diff options
| author | Diego Nehab <diego@tecgraf.puc-rio.br> | 2004-06-23 01:08:54 +0000 |
|---|---|---|
| committer | Diego Nehab <diego@tecgraf.puc-rio.br> | 2004-06-23 01:08:54 +0000 |
| commit | a193c087a406f3f9b9d86f452a80b749f8d88301 (patch) | |
| tree | 5576013d24b48d493dba776bc549e25daf1e0d81 /src/wsocket.c | |
| parent | 1ce47ebe3942a8b18b3b709f1ad915ac9ce82782 (diff) | |
| download | luasocket-a193c087a406f3f9b9d86f452a80b749f8d88301.tar.gz luasocket-a193c087a406f3f9b9d86f452a80b749f8d88301.tar.bz2 luasocket-a193c087a406f3f9b9d86f452a80b749f8d88301.zip | |
Fixing send/recv and optimizing.
Diffstat (limited to 'src/wsocket.c')
| -rw-r--r-- | src/wsocket.c | 9 |
1 files changed, 7 insertions, 2 deletions
diff --git a/src/wsocket.c b/src/wsocket.c index e276fe0..7f3e066 100644 --- a/src/wsocket.c +++ b/src/wsocket.c | |||
| @@ -200,7 +200,6 @@ int sock_send(p_sock ps, const char *data, size_t count, size_t *sent, | |||
| 200 | { | 200 | { |
| 201 | t_sock sock = *ps; | 201 | t_sock sock = *ps; |
| 202 | int put; | 202 | int put; |
| 203 | int ret; | ||
| 204 | /* avoid making system calls on closed sockets */ | 203 | /* avoid making system calls on closed sockets */ |
| 205 | if (sock == SOCK_INVALID) return IO_CLOSED; | 204 | if (sock == SOCK_INVALID) return IO_CLOSED; |
| 206 | /* try to send something */ | 205 | /* try to send something */ |
| @@ -212,6 +211,9 @@ int sock_send(p_sock ps, const char *data, size_t count, size_t *sent, | |||
| 212 | /* run select to avoid busy wait */ | 211 | /* run select to avoid busy wait */ |
| 213 | if (WSAGetLastError() == WSAEWOULDBLOCK) { | 212 | if (WSAGetLastError() == WSAEWOULDBLOCK) { |
| 214 | fd_set fds; | 213 | fd_set fds; |
| 214 | int ret; | ||
| 215 | /* optimize for the timeout = 0 case */ | ||
| 216 | if (timeout == 0) return IO_TIMEOUT; | ||
| 215 | FD_ZERO(&fds); | 217 | FD_ZERO(&fds); |
| 216 | FD_SET(sock, &fds); | 218 | FD_SET(sock, &fds); |
| 217 | ret = sock_select(0, NULL, &fds, NULL, timeout); | 219 | ret = sock_select(0, NULL, &fds, NULL, timeout); |
| @@ -236,13 +238,14 @@ int sock_sendto(p_sock ps, const char *data, size_t count, size_t *sent, | |||
| 236 | { | 238 | { |
| 237 | t_sock sock = *ps; | 239 | t_sock sock = *ps; |
| 238 | int put; | 240 | int put; |
| 239 | int ret; | ||
| 240 | if (sock == SOCK_INVALID) return IO_CLOSED; | 241 | if (sock == SOCK_INVALID) return IO_CLOSED; |
| 241 | put = sendto(sock, data, (int) count, 0, addr, addr_len); | 242 | put = sendto(sock, data, (int) count, 0, addr, addr_len); |
| 242 | if (put <= 0) { | 243 | if (put <= 0) { |
| 243 | *sent = 0; | 244 | *sent = 0; |
| 244 | if (WSAGetLastError() == WSAEWOULDBLOCK) { | 245 | if (WSAGetLastError() == WSAEWOULDBLOCK) { |
| 245 | fd_set fds; | 246 | fd_set fds; |
| 247 | int ret; | ||
| 248 | if (timeout == 0) return IO_TIMEOUT; | ||
| 246 | FD_ZERO(&fds); | 249 | FD_ZERO(&fds); |
| 247 | FD_SET(sock, &fds); | 250 | FD_SET(sock, &fds); |
| 248 | ret = sock_select(0, NULL, &fds, NULL, timeout); | 251 | ret = sock_select(0, NULL, &fds, NULL, timeout); |
| @@ -269,6 +272,7 @@ int sock_recv(p_sock ps, char *data, size_t count, size_t *got, int timeout) | |||
| 269 | int ret; | 272 | int ret; |
| 270 | *got = 0; | 273 | *got = 0; |
| 271 | if (taken == 0 || WSAGetLastError() != WSAEWOULDBLOCK) return IO_CLOSED; | 274 | if (taken == 0 || WSAGetLastError() != WSAEWOULDBLOCK) return IO_CLOSED; |
| 275 | if (timeout == 0) return IO_TIMEOUT; | ||
| 272 | FD_ZERO(&fds); | 276 | FD_ZERO(&fds); |
| 273 | FD_SET(sock, &fds); | 277 | FD_SET(sock, &fds); |
| 274 | ret = sock_select(0, &fds, NULL, NULL, timeout); | 278 | ret = sock_select(0, &fds, NULL, NULL, timeout); |
| @@ -295,6 +299,7 @@ int sock_recvfrom(p_sock ps, char *data, size_t count, size_t *got, | |||
| 295 | int ret; | 299 | int ret; |
| 296 | *got = 0; | 300 | *got = 0; |
| 297 | if (taken == 0 || WSAGetLastError() != WSAEWOULDBLOCK) return IO_CLOSED; | 301 | if (taken == 0 || WSAGetLastError() != WSAEWOULDBLOCK) return IO_CLOSED; |
| 302 | if (timeout == 0) return IO_TIMEOUT; | ||
| 298 | FD_ZERO(&fds); | 303 | FD_ZERO(&fds); |
| 299 | FD_SET(sock, &fds); | 304 | FD_SET(sock, &fds); |
| 300 | ret = sock_select(0, &fds, NULL, NULL, timeout); | 305 | ret = sock_select(0, &fds, NULL, NULL, timeout); |
