aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSam Roberts <vieuxtech@gmail.com>2011-08-08 16:11:47 -0700
committerSam Roberts <vieuxtech@gmail.com>2012-04-11 13:45:59 -0700
commit21698c7665ee1cb43e1b83c3ea5cf4dbf827c1df (patch)
tree9f0c59b09e760eb8ff18fb1c10c53235dfd93367
parentc37f71d062379ff4f48658cddd724b94df20fb66 (diff)
downloadluasocket-21698c7665ee1cb43e1b83c3ea5cf4dbf827c1df.tar.gz
luasocket-21698c7665ee1cb43e1b83c3ea5cf4dbf827c1df.tar.bz2
luasocket-21698c7665ee1cb43e1b83c3ea5cf4dbf827c1df.zip
Receive of zero for UDP is now possible.
Previously, receive of zero was considered to be "closed", but that is only true for stream-based protocols, like TCP.
-rw-r--r--src/udp.c6
1 files changed, 6 insertions, 0 deletions
diff --git a/src/udp.c b/src/udp.c
index e604bea..8168bf2 100644
--- a/src/udp.c
+++ b/src/udp.c
@@ -170,6 +170,9 @@ static int meth_receive(lua_State *L) {
170 count = MIN(count, sizeof(buffer)); 170 count = MIN(count, sizeof(buffer));
171 timeout_markstart(tm); 171 timeout_markstart(tm);
172 err = socket_recv(&udp->sock, buffer, count, &got, tm); 172 err = socket_recv(&udp->sock, buffer, count, &got, tm);
173 /* Unlike TCP, recv() of zero is not closed, but a zero-length packet. */
174 if (err == IO_CLOSED)
175 err = IO_DONE;
173 if (err != IO_DONE) { 176 if (err != IO_DONE) {
174 lua_pushnil(L); 177 lua_pushnil(L);
175 lua_pushstring(L, udp_strerror(err)); 178 lua_pushstring(L, udp_strerror(err));
@@ -194,6 +197,9 @@ static int meth_receivefrom(lua_State *L) {
194 count = MIN(count, sizeof(buffer)); 197 count = MIN(count, sizeof(buffer));
195 err = socket_recvfrom(&udp->sock, buffer, count, &got, 198 err = socket_recvfrom(&udp->sock, buffer, count, &got,
196 (SA *) &addr, &addr_len, tm); 199 (SA *) &addr, &addr_len, tm);
200 /* Unlike TCP, recv() of zero is not closed, but a zero-length packet. */
201 if (err == IO_CLOSED)
202 err = IO_DONE;
197 if (err == IO_DONE) { 203 if (err == IO_DONE) {
198 lua_pushlstring(L, buffer, got); 204 lua_pushlstring(L, buffer, got);
199 lua_pushstring(L, inet_ntoa(addr.sin_addr)); 205 lua_pushstring(L, inet_ntoa(addr.sin_addr));