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.
This commit is contained in:
Sam Roberts 2011-06-17 13:51:34 -07:00
parent a8b19e5367
commit 51acb54760
2 changed files with 30 additions and 6 deletions

View file

@ -213,14 +213,13 @@ int socket_send(p_socket ps, const char *data, size_t count,
for ( ;; ) {
long put = (long) send(*ps, data, count, 0);
/* if we sent anything, we are done */
if (put > 0) {
if (put >= 0) {
*sent = put;
return IO_DONE;
}
err = errno;
/* send can't really return 0, but EPIPE means the connection was
closed */
if (put == 0 || err == EPIPE) return IO_CLOSED;
/* EPIPE means the connection was closed */
if (err == EPIPE) return IO_CLOSED;
/* we call was interrupted, just try again */
if (err == EINTR) continue;
/* 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,
if (*ps == SOCKET_INVALID) return IO_CLOSED;
for ( ;; ) {
long put = (long) sendto(*ps, data, count, 0, addr, len);
if (put > 0) {
if (put >= 0) {
*sent = put;
return IO_DONE;
}
err = errno;
if (put == 0 || err == EPIPE) return IO_CLOSED;
if (err == EPIPE) return IO_CLOSED;
if (err == EINTR) continue;
if (err != EAGAIN) return err;
if ((err = socket_waitfd(ps, WAITFD_W, tm)) != IO_DONE) return err;