mirror of
https://github.com/lunarmodules/luasocket.git
synced 2025-07-23 09:20:23 +02:00
Fixed inet_pton and a new Winsock UDP bug.
inet_pton was copying the entire sockaddr_in struct, rather than just the sin_addr field... I am a bit unsure about the UDP fix, because it may affect TCP as well. On UDP sockets, when a sendto fails, the next receive/receivefrom fails with CONNRESET. I changed sock_recv/sock_recvfrom in wsocket.c to skip the CONNRESET from the recv/recvfrom, hoping that if the socket is TCP, sock_waitfd will get the CONNRESET again. The tests pass, but this should be tested more thoroughly.
This commit is contained in:
@ -250,7 +250,11 @@ int socket_recv(p_socket ps, char *data, size_t count, size_t *got, p_timeout tm
|
||||
}
|
||||
if (taken == 0) return IO_CLOSED;
|
||||
err = WSAGetLastError();
|
||||
if (err != WSAEWOULDBLOCK) return err;
|
||||
/* On Windows, and on UDP, a connreset simply means the
|
||||
* previous send failed. On TCP, it means our socket
|
||||
* is now useless, so the error must pass. I am
|
||||
* hoping waitfd will still get the error. */
|
||||
if (err != WSAEWOULDBLOCK && err != WSAECONNRESET) return err;
|
||||
if ((err = socket_waitfd(ps, WAITFD_R, tm)) != IO_DONE) return err;
|
||||
}
|
||||
}
|
||||
@ -271,7 +275,11 @@ int socket_recvfrom(p_socket ps, char *data, size_t count, size_t *got,
|
||||
}
|
||||
if (taken == 0) return IO_CLOSED;
|
||||
err = WSAGetLastError();
|
||||
if (err != WSAEWOULDBLOCK) return err;
|
||||
/* On Windows, and on UDP, a connreset simply means the
|
||||
* previous send failed. On TCP, it means our socket
|
||||
* is now useless, so the error must pass. I am
|
||||
* hoping waitfd will still get the error. */
|
||||
if (err != WSAEWOULDBLOCK && err != WSAECONNRESET) return err;
|
||||
if ((err = socket_waitfd(ps, WAITFD_R, tm)) != IO_DONE) return err;
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user