From 8423b244ec8a3a0ef76e3559d1a40e5117501ca5 Mon Sep 17 00:00:00 2001 From: Danny Mayer Date: Sun, 16 Sep 2001 06:19:22 +0000 Subject: [PATCH] doio_recv was not catching a ECONNRESET error. Fixed this and added code to catch other possible errors. Miscellaneous errno handling cleanup [RT #1745] --- lib/isc/win32/socket.c | 98 +++++++++++++++++++----------------------- 1 file changed, 44 insertions(+), 54 deletions(-) diff --git a/lib/isc/win32/socket.c b/lib/isc/win32/socket.c index b1e0985907..afd51fa235 100644 --- a/lib/isc/win32/socket.c +++ b/lib/isc/win32/socket.c @@ -15,7 +15,7 @@ * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ -/* $Id: socket.c,v 1.5 2001/07/17 20:29:31 gson Exp $ */ +/* $Id: socket.c,v 1.6 2001/09/16 06:19:22 mayer Exp $ */ #define MAKE_EXTERNAL 1 @@ -27,6 +27,8 @@ #define _WINSOCKAPI_ /* Prevent inclusion of winsock.h in windows.h */ #endif +#include "errno2result.h" + #include #include #include @@ -69,8 +71,8 @@ * work around it here. */ #define SOFT_ERROR(e) ((e) == EAGAIN || \ - (e) == EWOULDBLOCK || \ - (e) == EINTR || \ + (e) == WSAEWOULDBLOCK || \ + (e) == WSAEINTR || \ (e) == 0) #define DLVL(x) ISC_LOGCATEGORY_GENERAL, ISC_LOGMODULE_SOCKET, ISC_LOG_DEBUG(x) @@ -317,14 +319,7 @@ internal_sendmsg(int sock, const struct msghdr *msg, int flags) { BytesSent = -1; /* There is an error... */ Error = WSAGetLastError(); - if (Error == WSAEWOULDBLOCK) { - - /* - * WSAEWOULDBLOCK means we have to wait for an FD_WRITE - * before we can send. - */ - errno = EWOULDBLOCK; - } else if (Error == WSA_IO_PENDING) { + if (Error == WSA_IO_PENDING) { /* Overlapped send successfully initiated. */ errno = EAGAIN; } else { @@ -997,7 +992,7 @@ doio_recv(isc_socket_t *sock, isc_socketevent_t *dev) { ISC_MSG_DOIORECV, "doio_recv: internal_recvmsg(%d) %d bytes, " "err %d/%s", - sock->fd, cc, errno, strerror(errno)); + sock->fd, cc, errno, NTstrerror(errno)); #define SOFT_OR_HARD(_system, _isc) \ if (errno == _system) { \ @@ -1013,10 +1008,14 @@ doio_recv(isc_socket_t *sock, isc_socketevent_t *dev) { return (DOIO_HARD); \ } - SOFT_OR_HARD(ECONNREFUSED, ISC_R_CONNREFUSED); - SOFT_OR_HARD(ENETUNREACH, ISC_R_NETUNREACH); - SOFT_OR_HARD(EHOSTUNREACH, ISC_R_HOSTUNREACH); - ALWAYS_HARD(ENOBUFS, ISC_R_NORESOURCES); + SOFT_OR_HARD(WSAECONNREFUSED, ISC_R_CONNREFUSED); + SOFT_OR_HARD(WSAENETUNREACH, ISC_R_NETUNREACH); + SOFT_OR_HARD(WSAEHOSTUNREACH, ISC_R_HOSTUNREACH); + SOFT_OR_HARD(WSAECONNRESET, ISC_R_CONNECTIONRESET); + SOFT_OR_HARD(WSAENETRESET, ISC_R_CONNECTIONRESET); + SOFT_OR_HARD(WSAEDISCON, ISC_R_CONNECTIONRESET); + SOFT_OR_HARD(WSAENETDOWN, ISC_R_NETDOWN); + ALWAYS_HARD(WSAENOBUFS, ISC_R_NORESOURCES); #undef SOFT_OR_HARD #undef ALWAYS_HARD @@ -1147,16 +1146,18 @@ doio_send(isc_socket_t *sock, isc_socketevent_t *dev) { return (DOIO_HARD); \ } - SOFT_OR_HARD(EACCES, ISC_R_NOPERM); - SOFT_OR_HARD(EAFNOSUPPORT, ISC_R_ADDRNOTAVAIL); - SOFT_OR_HARD(ECONNREFUSED, ISC_R_CONNREFUSED); - ALWAYS_HARD(EADDRNOTAVAIL, ISC_R_ADDRNOTAVAIL); - ALWAYS_HARD(EHOSTUNREACH, ISC_R_HOSTUNREACH); -#ifdef EHOSTDOWN - ALWAYS_HARD(EHOSTDOWN, ISC_R_HOSTUNREACH); -#endif - ALWAYS_HARD(ENETUNREACH, ISC_R_NETUNREACH); - ALWAYS_HARD(ENOBUFS, ISC_R_NORESOURCES); + SOFT_OR_HARD(WSAEACCES, ISC_R_NOPERM); + SOFT_OR_HARD(WSAEAFNOSUPPORT, ISC_R_ADDRNOTAVAIL); + SOFT_OR_HARD(WSAECONNREFUSED, ISC_R_CONNREFUSED); + SOFT_OR_HARD(WSAECONNRESET, ISC_R_CONNECTIONRESET); + SOFT_OR_HARD(WSAENETRESET, ISC_R_CONNECTIONRESET); + SOFT_OR_HARD(WSAEDISCON, ISC_R_CONNECTIONRESET); + SOFT_OR_HARD(WSAENETDOWN, ISC_R_NETDOWN); + ALWAYS_HARD(WSAEADDRNOTAVAIL, ISC_R_ADDRNOTAVAIL); + ALWAYS_HARD(WSAEHOSTUNREACH, ISC_R_HOSTUNREACH); + ALWAYS_HARD(WSAEHOSTDOWN, ISC_R_HOSTUNREACH); + ALWAYS_HARD(WSAENETUNREACH, ISC_R_NETUNREACH); + ALWAYS_HARD(WSAENOBUFS, ISC_R_NORESOURCES); ALWAYS_HARD(EPERM, ISC_R_HOSTUNREACH); ALWAYS_HARD(EPIPE, ISC_R_NOTCONNECTED); @@ -1391,13 +1392,6 @@ isc_socket_create(isc_socketmgr_t *manager, int pf, isc_sockettype_t type, case EPROTONOSUPPORT: case EPFNOSUPPORT: case EAFNOSUPPORT: -#ifdef LINUX - /* - * Linux 2.2 (and maybe others) return EINVAL instead of - * EAFNOSUPPORT. - */ - case EINVAL: -#endif return (ISC_R_FAMILYNOSUPPORT); default: @@ -2914,16 +2908,14 @@ isc_socket_connect(isc_socket_t *sock, isc_sockaddr_t *addr, switch (errno) { #define ERROR_MATCH(a, b) case a: dev->result = b; goto err_exit; - ERROR_MATCH(EACCES, ISC_R_NOPERM); - ERROR_MATCH(EADDRNOTAVAIL, ISC_R_ADDRNOTAVAIL); - ERROR_MATCH(EAFNOSUPPORT, ISC_R_ADDRNOTAVAIL); - ERROR_MATCH(ECONNREFUSED, ISC_R_CONNREFUSED); - ERROR_MATCH(EHOSTUNREACH, ISC_R_HOSTUNREACH); -#ifdef EHOSTDOWN - ERROR_MATCH(EHOSTDOWN, ISC_R_HOSTUNREACH); -#endif - ERROR_MATCH(ENETUNREACH, ISC_R_NETUNREACH); - ERROR_MATCH(ENOBUFS, ISC_R_NORESOURCES); + ERROR_MATCH(WSAEACCES, ISC_R_NOPERM); + ERROR_MATCH(WSAEADDRNOTAVAIL, ISC_R_ADDRNOTAVAIL); + ERROR_MATCH(WSAEAFNOSUPPORT, ISC_R_ADDRNOTAVAIL); + ERROR_MATCH(WSAECONNREFUSED, ISC_R_CONNREFUSED); + ERROR_MATCH(WSAEHOSTUNREACH, ISC_R_HOSTUNREACH); + ERROR_MATCH(WSAEHOSTDOWN, ISC_R_HOSTUNREACH); + ERROR_MATCH(WSAENETUNREACH, ISC_R_NETUNREACH); + ERROR_MATCH(WSAENOBUFS, ISC_R_NORESOURCES); ERROR_MATCH(EPERM, ISC_R_HOSTUNREACH); ERROR_MATCH(EPIPE, ISC_R_NOTCONNECTED); #undef ERROR_MATCH @@ -3057,19 +3049,17 @@ internal_connect(isc_task_t *me, isc_event_t *ev) { */ switch (errno) { #define ERROR_MATCH(a, b) case a: dev->result = b; break; - ERROR_MATCH(EACCES, ISC_R_NOPERM); - ERROR_MATCH(EADDRNOTAVAIL, ISC_R_ADDRNOTAVAIL); - ERROR_MATCH(EAFNOSUPPORT, ISC_R_ADDRNOTAVAIL); - ERROR_MATCH(ECONNREFUSED, ISC_R_CONNREFUSED); - ERROR_MATCH(EHOSTUNREACH, ISC_R_HOSTUNREACH); -#ifdef EHOSTDOWN - ERROR_MATCH(EHOSTDOWN, ISC_R_HOSTUNREACH); -#endif - ERROR_MATCH(ENETUNREACH, ISC_R_NETUNREACH); - ERROR_MATCH(ENOBUFS, ISC_R_NORESOURCES); + ERROR_MATCH(WSAEACCES, ISC_R_NOPERM); + ERROR_MATCH(WSAEADDRNOTAVAIL, ISC_R_ADDRNOTAVAIL); + ERROR_MATCH(WSAEAFNOSUPPORT, ISC_R_ADDRNOTAVAIL); + ERROR_MATCH(WSAECONNREFUSED, ISC_R_CONNREFUSED); + ERROR_MATCH(WSAEHOSTUNREACH, ISC_R_HOSTUNREACH); + ERROR_MATCH(WSAEHOSTDOWN, ISC_R_HOSTUNREACH); + ERROR_MATCH(WSAENETUNREACH, ISC_R_NETUNREACH); + ERROR_MATCH(WSAENOBUFS, ISC_R_NORESOURCES); ERROR_MATCH(EPERM, ISC_R_HOSTUNREACH); ERROR_MATCH(EPIPE, ISC_R_NOTCONNECTED); - ERROR_MATCH(ETIMEDOUT, ISC_R_TIMEDOUT); + ERROR_MATCH(WSAETIMEDOUT, ISC_R_TIMEDOUT); #undef ERROR_MATCH default: dev->result = ISC_R_UNEXPECTED;