From c98dc991998c724a3f6a1fdd90b5d1d8a80e3af3 Mon Sep 17 00:00:00 2001 From: Diego Nehab Date: Fri, 28 May 2004 07:24:43 +0000 Subject: Bug feioso no UDP e possivelmente no TCP também. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/udp.c | 12 ++++++++---- src/usocket.c | 8 ++++---- src/wsocket.c | 21 ++++++--------------- 3 files changed, 18 insertions(+), 23 deletions(-) (limited to 'src') diff --git a/src/udp.c b/src/udp.c index a2dff34..19cefe6 100644 --- a/src/udp.c +++ b/src/udp.c @@ -109,7 +109,8 @@ static int meth_send(lua_State *L) int err; const char *data = luaL_checklstring(L, 2, &count); tm_markstart(tm); - err = sock_send(&udp->sock, data, count, &sent, tm_get(tm)); + do err = sock_send(&udp->sock, data, count, &sent, tm_getretry(tm)); + while (err == IO_RETRY); if (err == IO_DONE) lua_pushnumber(L, sent); else lua_pushnil(L); /* a 'closed' error on an unconnected means the target address was not @@ -137,8 +138,9 @@ static int meth_sendto(lua_State *L) addr.sin_family = AF_INET; addr.sin_port = htons(port); tm_markstart(tm); - err = sock_sendto(&udp->sock, data, count, &sent, + do err = sock_sendto(&udp->sock, data, count, &sent, (SA *) &addr, sizeof(addr), tm_get(tm)); + while (err == IO_RETRY); if (err == IO_DONE) lua_pushnumber(L, sent); else lua_pushnil(L); /* a 'closed' error on an unconnected means the target address was not @@ -159,7 +161,8 @@ static int meth_receive(lua_State *L) p_tm tm = &udp->tm; count = MIN(count, sizeof(buffer)); tm_markstart(tm); - err = sock_recv(&udp->sock, buffer, count, &got, tm_get(tm)); + do err = sock_recv(&udp->sock, buffer, count, &got, tm_get(tm)); + while (err == IO_RETRY); if (err == IO_DONE) lua_pushlstring(L, buffer, got); else lua_pushnil(L); io_pusherror(L, err); @@ -180,8 +183,9 @@ static int meth_receivefrom(lua_State *L) p_tm tm = &udp->tm; tm_markstart(tm); count = MIN(count, sizeof(buffer)); - err = sock_recvfrom(&udp->sock, buffer, count, &got, + do err = sock_recvfrom(&udp->sock, buffer, count, &got, (SA *) &addr, &addr_len, tm_get(tm)); + while (err == IO_RETRY); if (err == IO_DONE) { lua_pushlstring(L, buffer, got); lua_pushstring(L, inet_ntoa(addr.sin_addr)); diff --git a/src/usocket.c b/src/usocket.c index eb1a49a..9e6efd3 100644 --- a/src/usocket.c +++ b/src/usocket.c @@ -211,7 +211,7 @@ int sock_send(p_sock ps, const char *data, size_t count, size_t *sent, /* here there was no data before timeout */ else return IO_TIMEOUT; /* here we didn't send anything, but now we can */ - } else return IO_DONE; + } else return IO_RETRY; /* here we successfully sent something */ } else { *sent = put; @@ -239,7 +239,7 @@ int sock_sendto(p_sock ps, const char *data, size_t count, size_t *sent, if (sock_select(sock+1, NULL, &fds, NULL, timeout) <= 0) { if (errno == EINTR) return IO_RETRY; else return IO_TIMEOUT; - } else return IO_DONE; + } else return IO_RETRY; } else { *sent = put; return IO_DONE; @@ -266,7 +266,7 @@ int sock_recv(p_sock ps, char *data, size_t count, size_t *got, int timeout) ret = sock_select(sock+1, &fds, NULL, NULL, timeout); if (ret < 0 && errno == EINTR) return IO_RETRY; if (ret == 0) return IO_TIMEOUT; - else return IO_DONE; + return IO_RETRY; } else { *got = taken; return IO_DONE; @@ -294,7 +294,7 @@ int sock_recvfrom(p_sock ps, char *data, size_t count, size_t *got, ret = sock_select(sock+1, &fds, NULL, NULL, timeout); if (ret < 0 && errno == EINTR) return IO_RETRY; if (ret == 0) return IO_TIMEOUT; - else return IO_DONE; + return IO_RETRY; } else { *got = taken; return IO_DONE; diff --git a/src/wsocket.c b/src/wsocket.c index af3f8d8..023f470 100644 --- a/src/wsocket.c +++ b/src/wsocket.c @@ -207,9 +207,9 @@ int sock_send(p_sock ps, const char *data, size_t count, size_t *sent, FD_ZERO(&fds); FD_SET(sock, &fds); ret = sock_select(0, NULL, &fds, NULL, timeout); - /* tell the caller to call us again because there is more data */ - if (ret > 0) return IO_DONE; - /* tell the caller there was no data before timeout */ + /* tell the caller to call us again because now we can send */ + if (ret > 0) return IO_RETRY; + /* tell the caller we can't send anything before timint out */ else return IO_TIMEOUT; /* here we know the connection has been closed */ } else return IO_CLOSED; @@ -229,27 +229,18 @@ int sock_sendto(p_sock ps, const char *data, size_t count, size_t *sent, t_sock sock = *ps; int put; int ret; - /* avoid making system calls on closed sockets */ if (sock == SOCK_INVALID) return IO_CLOSED; - /* try to send something */ put = sendto(sock, data, (int) count, 0, addr, addr_len); - /* deal with failure */ if (put <= 0) { - /* in any case, nothing has been sent */ *sent = 0; - /* run select to avoid busy wait */ if (WSAGetLastError() == WSAEWOULDBLOCK) { fd_set fds; FD_ZERO(&fds); FD_SET(sock, &fds); ret = sock_select(0, NULL, &fds, NULL, timeout); - /* tell the caller to call us again because there is more data */ - if (ret > 0) return IO_DONE; - /* tell the caller there was no data before timeout */ + if (ret > 0) return IO_RETRY; else return IO_TIMEOUT; - /* here we know the connection has been closed */ } else return IO_CLOSED; - /* here we successfully sent something */ } else { *sent = put; return IO_DONE; @@ -273,7 +264,7 @@ int sock_recv(p_sock ps, char *data, size_t count, size_t *got, int timeout) FD_ZERO(&fds); FD_SET(sock, &fds); ret = sock_select(0, &fds, NULL, NULL, timeout); - if (ret > 0) return IO_DONE; + if (ret > 0) return IO_RETRY; else return IO_TIMEOUT; } else { *got = taken; @@ -299,7 +290,7 @@ int sock_recvfrom(p_sock ps, char *data, size_t count, size_t *got, FD_ZERO(&fds); FD_SET(sock, &fds); ret = sock_select(0, &fds, NULL, NULL, timeout); - if (ret > 0) return IO_DONE; + if (ret > 0) return IO_RETRY; else return IO_TIMEOUT; } else { *got = taken; -- cgit v1.2.3-55-g6feb