diff options
author | Sam Roberts <vieuxtech@gmail.com> | 2011-06-17 13:51:34 -0700 |
---|---|---|
committer | Sam Roberts <vieuxtech@gmail.com> | 2012-04-11 13:45:59 -0700 |
commit | 51acb54760dc91095d59839e8ea2256557f42781 (patch) | |
tree | 080967bc57ac420d8654e2652a14c5499fd0467f /src/usocket.c | |
parent | a8b19e5367738f606a051f254858dc09de2a695a (diff) | |
download | luasocket-51acb54760dc91095d59839e8ea2256557f42781.tar.gz luasocket-51acb54760dc91095d59839e8ea2256557f42781.tar.bz2 luasocket-51acb54760dc91095d59839e8ea2256557f42781.zip |
Stop returning an error after successful send of zero length UDP packets
A zero-length send is invalid with TCP, but well defined with UDP.
udp:send"" was returning (nil,"refused"), indicating that it failed when
the packet was actually sent. The test script reproduces the bug, and
includes a tcpdump of the zero length packet being sent.
Diffstat (limited to 'src/usocket.c')
-rw-r--r-- | src/usocket.c | 11 |
1 files changed, 5 insertions, 6 deletions
diff --git a/src/usocket.c b/src/usocket.c index ef275b4..97f8b4f 100644 --- a/src/usocket.c +++ b/src/usocket.c | |||
@@ -213,14 +213,13 @@ int socket_send(p_socket ps, const char *data, size_t count, | |||
213 | for ( ;; ) { | 213 | for ( ;; ) { |
214 | long put = (long) send(*ps, data, count, 0); | 214 | long put = (long) send(*ps, data, count, 0); |
215 | /* if we sent anything, we are done */ | 215 | /* if we sent anything, we are done */ |
216 | if (put > 0) { | 216 | if (put >= 0) { |
217 | *sent = put; | 217 | *sent = put; |
218 | return IO_DONE; | 218 | return IO_DONE; |
219 | } | 219 | } |
220 | err = errno; | 220 | err = errno; |
221 | /* send can't really return 0, but EPIPE means the connection was | 221 | /* EPIPE means the connection was closed */ |
222 | closed */ | 222 | if (err == EPIPE) return IO_CLOSED; |
223 | if (put == 0 || err == EPIPE) return IO_CLOSED; | ||
224 | /* we call was interrupted, just try again */ | 223 | /* we call was interrupted, just try again */ |
225 | if (err == EINTR) continue; | 224 | if (err == EINTR) continue; |
226 | /* if failed fatal reason, report error */ | 225 | /* if failed fatal reason, report error */ |
@@ -243,12 +242,12 @@ int socket_sendto(p_socket ps, const char *data, size_t count, size_t *sent, | |||
243 | if (*ps == SOCKET_INVALID) return IO_CLOSED; | 242 | if (*ps == SOCKET_INVALID) return IO_CLOSED; |
244 | for ( ;; ) { | 243 | for ( ;; ) { |
245 | long put = (long) sendto(*ps, data, count, 0, addr, len); | 244 | long put = (long) sendto(*ps, data, count, 0, addr, len); |
246 | if (put > 0) { | 245 | if (put >= 0) { |
247 | *sent = put; | 246 | *sent = put; |
248 | return IO_DONE; | 247 | return IO_DONE; |
249 | } | 248 | } |
250 | err = errno; | 249 | err = errno; |
251 | if (put == 0 || err == EPIPE) return IO_CLOSED; | 250 | if (err == EPIPE) return IO_CLOSED; |
252 | if (err == EINTR) continue; | 251 | if (err == EINTR) continue; |
253 | if (err != EAGAIN) return err; | 252 | if (err != EAGAIN) return err; |
254 | if ((err = socket_waitfd(ps, WAITFD_W, tm)) != IO_DONE) return err; | 253 | if ((err = socket_waitfd(ps, WAITFD_W, tm)) != IO_DONE) return err; |