]> git.ipfire.org Git - thirdparty/bind9.git/commitdiff
1920. [bug] Update windows socket code. [RT #14965]
authorMark Andrews <marka@isc.org>
Thu, 1 Sep 2005 03:16:12 +0000 (03:16 +0000)
committerMark Andrews <marka@isc.org>
Thu, 1 Sep 2005 03:16:12 +0000 (03:16 +0000)
CHANGES
bin/dig/dighost.c
lib/dns/include/dns/masterdump.h
lib/isc/win32/errno2result.c
lib/isc/win32/socket.c

diff --git a/CHANGES b/CHANGES
index 455f5db19e5ddccf5ed942be64c70a09253bc773..07749e2b108030ae5f28d944f0e4106ffae83267 100644 (file)
--- a/CHANGES
+++ b/CHANGES
@@ -1,3 +1,5 @@
+1920.  [bug]           Update windows socket code. [RT #14965]
+
 1919.  [bug]           dig's +sigchase code overhauled. [RT #14933]
 
 1918.  [bug]           The DLV code has been re-worked to make no longer
index d07e09ce94c1fd1d73fe82012635cd043ba9f557..0e89d70ccc1db5fddef7f899bf2c50cc8f0bfe79 100644 (file)
@@ -15,7 +15,7 @@
  * PERFORMANCE OF THIS SOFTWARE.
  */
 
-/* $Id: dighost.c,v 1.221.2.19.2.27 2005/08/25 01:54:31 marka Exp $ */
+/* $Id: dighost.c,v 1.221.2.19.2.28 2005/09/01 03:16:10 marka Exp $ */
 
 /*
  * Notice to programmers:  Do not use this code as an example of how to
@@ -37,7 +37,6 @@
 #include <dns/dnssec.h>
 #include <dns/ds.h>
 #include <dns/nsec.h>
-#include <isc/file.h>
 #include <isc/random.h>
 #include <ctype.h>
 #endif
@@ -58,6 +57,7 @@
 #include <isc/app.h>
 #include <isc/base64.h>
 #include <isc/entropy.h>
+#include <isc/file.h>
 #include <isc/lang.h>
 #include <isc/netaddr.h>
 #ifdef DIG_SIGCHASE
@@ -945,7 +945,8 @@ setup_system(void) {
        if (lwresult != LWRES_R_SUCCESS)
                fatal("lwres_context_create failed");
 
-       lwresult = lwres_conf_parse(lwctx, RESOLV_CONF);
+       if (isc_file_exists(RESOLV_CONF))
+               lwresult = lwres_conf_parse(lwctx, RESOLV_CONF);
        if (lwresult != LWRES_R_SUCCESS)
                fatal("parse of %s failed", RESOLV_CONF);
 
index 5058945403b9b1238798d3dc3e80377cad0a5b91..659577aaa0bd99f65639568908b5d9a9c069d1a2 100644 (file)
@@ -15,7 +15,7 @@
  * PERFORMANCE OF THIS SOFTWARE.
  */
 
-/* $Id: masterdump.h,v 1.22.12.8 2004/03/19 05:00:49 marka Exp $ */
+/* $Id: masterdump.h,v 1.22.12.9 2005/09/01 03:16:11 marka Exp $ */
 
 #ifndef DNS_MASTERDUMP_H
 #define DNS_MASTERDUMP_H 1
@@ -122,7 +122,7 @@ LIBDNS_EXTERNAL_DATA extern const dns_master_style_t dns_master_style_full;
  * stop of its own, but the class and type share one.
  */
 LIBDNS_EXTERNAL_DATA extern const dns_master_style_t
-                                 dns_master_style_explicitttl;
+                                       dns_master_style_explicitttl;
 
 /*
  * A master style format designed for cache files.  It prints explicit TTL
index 46e52239c25bf202d66a08f874157f12ffee806c..8005d65f9e0ceb6f3804ec258756acbc71a6c413 100644 (file)
@@ -15,7 +15,7 @@
  * PERFORMANCE OF THIS SOFTWARE.
  */
 
-/* $Id: errno2result.c,v 1.4.2.5.2.5 2005/06/09 23:54:31 marka Exp $ */
+/* $Id: errno2result.c,v 1.4.2.5.2.6 2005/09/01 03:16:12 marka Exp $ */
 
 #include <config.h>
 
@@ -61,6 +61,24 @@ isc__errno2resultx(int posixerrno, const char *file, int line) {
        case EMFILE:
        case WSAEMFILE:
                return (ISC_R_TOOMANYOPENFILES);
+       case ERROR_OPERATION_ABORTED:
+               return (ISC_R_CONNECTIONRESET);
+       case ERROR_PORT_UNREACHABLE:
+               return (ISC_R_HOSTUNREACH);
+       case ERROR_HOST_UNREACHABLE:
+               return (ISC_R_HOSTUNREACH);
+       case ERROR_NETWORK_UNREACHABLE:
+               return (ISC_R_NETUNREACH);
+       case WSAEADDRNOTAVAIL:
+               return (ISC_R_ADDRNOTAVAIL);
+       case WSAEHOSTUNREACH:
+               return (ISC_R_HOSTUNREACH);
+       case WSAEHOSTDOWN:
+               return (ISC_R_HOSTUNREACH);
+       case WSAENETUNREACH:
+               return (ISC_R_NETUNREACH);
+       case WSAENOBUFS:
+               return (ISC_R_NORESOURCES);
        default:
                isc__strerror(posixerrno, strbuf, sizeof(strbuf));
                UNEXPECTED_ERROR(file, line, "unable to convert errno "
index 846cc9983704ea5cc59851be45f21e2fd99ad1bc..7f800ed15ac42ca27c8f65b581888cb193f16c18 100644 (file)
@@ -15,7 +15,7 @@
  * PERFORMANCE OF THIS SOFTWARE.
  */
 
-/* $Id: socket.c,v 1.5.2.13.2.15 2005/06/09 23:54:32 marka Exp $ */
+/* $Id: socket.c,v 1.5.2.13.2.16 2005/09/01 03:16:12 marka Exp $ */
 
 /* This code has been rewritten to take advantage of Windows Sockets
  * I/O Completion Ports and Events. I/O Completion Ports is ONLY
@@ -98,8 +98,8 @@
  * NOTE: This requires that Windows 2000 systems install Service Pack 2
  * or later.
  */
-#ifndef SIO_UDP_CONNRESET 
-#define SIO_UDP_CONNRESET _WSAIOW(IOC_VENDOR,12) 
+#ifndef SIO_UDP_CONNRESET
+#define SIO_UDP_CONNRESET _WSAIOW(IOC_VENDOR,12)
 #endif
 
 /*
 /*
  * Define what the possible "soft" errors can be.  These are non-fatal returns
  * of various network related functions, like recv() and so on.
- *
- * For some reason, BSDI (and perhaps others) will sometimes return <0
- * from recv() but will have errno==0.  This is broken, but we have to
- * work around it here.
  */
 #define SOFT_ERROR(e)  ((e) == WSAEINTR || \
-                        (e) == WSA_IO_PENDING || \
                         (e) == WSAEWOULDBLOCK || \
                         (e) == EWOULDBLOCK || \
                         (e) == EINTR || \
                         (e) == EAGAIN || \
                         (e) == 0)
 
+/*
+ * Pending errors are not really errors and should be
+ * kept separate
+ */
+#define PENDING_ERROR(e) ((e) == WSA_IO_PENDING || (e) == 0)
+
+#define DOIO_SUCCESS     0       /* i/o ok, event sent */
+#define DOIO_SOFT           1       /* i/o ok, soft error, no event sent */
+#define DOIO_HARD           2       /* i/o error, event sent */
+#define DOIO_EOF             3       /* EOF, no event sent */
+#define DOIO_PENDING     4       /* status when i/o is in process */
+
 #define DLVL(x) ISC_LOGCATEGORY_GENERAL, ISC_LOGMODULE_SOCKET, ISC_LOG_DEBUG(x)
 
 /*
@@ -163,15 +170,9 @@ typedef isc_event_t intev_t;
 #endif
 #endif
 
-/*
- * NetBSD and FreeBSD can timestamp packets.  XXXMLG Should we have
- * a setsockopt() like interface to request timestamps, and if the OS
- * doesn't do it for us, call gettimeofday() on every UDP receive?
- */
-
 /*
  * We really  don't want to try and use these control messages. Win32
- * doesn't have this mechanism
+ * doesn't have this mechanism before XP.
  */
 #undef USE_CMSG
 
@@ -182,17 +183,19 @@ typedef isc_event_t intev_t;
 
 
 struct msghdr {
-        void   *msg_name;              /* optional address */
-        u_int   msg_namelen;            /* size of address */
-        WSABUF  *msg_iov;              /* scatter/gather array */
-        u_int   msg_iovlen;             /* # elements in msg_iov */
-        void   *msg_control;           /* ancillary data, see below */
-        u_int   msg_controllen;         /* ancillary data buffer len */
-        int     msg_flags;              /* flags on received message */
+       void    *msg_name;              /* optional address */
+       u_int   msg_namelen;            /* size of address */
+       WSABUF  *msg_iov;               /* scatter/gather array */
+       u_int   msg_iovlen;             /* # elements in msg_iov */
+       void    *msg_control;           /* ancillary data, see below */
+       u_int   msg_controllen;         /* ancillary data buffer len */
+       int     msg_flags;              /* flags on received message */
+       int     msg_totallen;           /* total length of this message */
 } msghdr;
-       
+
 /*
- * The number of times a send operation is repeated if the result is EINTR.
+ * The number of times a send operation is repeated if the result
+ * is WSAEINTR.
  */
 #define NRETRIES 10
 
@@ -205,13 +208,11 @@ struct isc_socket {
        OVERLAPPED              overlapped;
        /* Pointers to scatter/gather buffers */
        WSABUF                  iov[ISC_SOCKET_MAXSCATTERGATHER];
-       size_t                  totalBytes;
        WSAEVENT                hEvent;         /* Event Handle */
        long                    wait_type;      /* Events to wait on */
        WSAEVENT                hAlert;         /* Alert Event Handle */
        DWORD                   evthread_id;    /* Event Thread Id for socket */
 
-
        /* Locked by socket lock. */
        ISC_LINK(isc_socket_t)  link;
        unsigned int            references;
@@ -282,7 +283,7 @@ struct event_change {
 
 /*
  * Note: We are using an array here since *WaitForMultiple* wants an array
- * WARNING: This value may not be greater than 64 since the 
+ * WARNING: This value may not be greater than 64 since the
  * WSAWaitForMultipleEvents function is limited to 64 events.
  */
 
@@ -333,10 +334,6 @@ struct isc_socketmgr {
        DWORD                           dwIOCPThreadIds[MAX_IOCPTHREADS];
 };
 
-#define CLOSED         0       /* this one must be zero */
-#define MANAGED                1
-#define CLOSE_PENDING  2
-
 /*
  * send() and recv() iovec counts
  */
@@ -497,13 +494,13 @@ iocompletionport_init(isc_socketmgr_t *manager) {
                                strbuf);
                exit(1);
        }
-       
+
        /*
         * Worker threads for servicing the I/O
         */
        iocompletionport_createthreads(manager->maxIOCPThreads, manager);
 }
-       
+
 
 void
 iocompletionport_exit(isc_socketmgr_t *manager) {
@@ -787,7 +784,7 @@ notify_eventlist(isc_socket_t *sock, isc_socketmgr_t *manager,
 
        REQUIRE(VALID_MANAGER(manager));
        REQUIRE(sock != NULL);
-       
+
        evchange = HeapAlloc(hHeapHandle, HEAP_ZERO_MEMORY,
                             sizeof(event_change_t));
        evchange->sock = sock;
@@ -824,7 +821,7 @@ socket_event_add(isc_socket_t *sock, long type) {
        if (hEvent == WSA_INVALID_EVENT) {
                stat = WSAGetLastError();
                isc__strerror(stat, strbuf, sizeof(strbuf));
-               msg = isc_msgcat_get(isc_msgcat, ISC_MSGSET_GENERAL,    
+               msg = isc_msgcat_get(isc_msgcat, ISC_MSGSET_GENERAL,
                                     ISC_MSG_FAILED, "failed"),
                UNEXPECTED_ERROR(__FILE__, __LINE__, "WSACreateEvent: %s: %s",
                                 msg, strbuf);
@@ -833,7 +830,7 @@ socket_event_add(isc_socket_t *sock, long type) {
        if (WSAEventSelect(sock->fd, hEvent, type) != 0) {
                stat = WSAGetLastError();
                isc__strerror(stat, strbuf, sizeof(strbuf));
-               msg = isc_msgcat_get(isc_msgcat, ISC_MSGSET_GENERAL,    
+               msg = isc_msgcat_get(isc_msgcat, ISC_MSGSET_GENERAL,
                                     ISC_MSG_FAILED, "failed");
                UNEXPECTED_ERROR(__FILE__, __LINE__, "WSAEventSelect: %s: %s",
                                 msg, strbuf);
@@ -899,7 +896,7 @@ BOOL InitSockets() {
 
        /* Need Winsock 2.0 or better */
        wVersionRequested = MAKEWORD(2, 0);
+
        err = WSAStartup(wVersionRequested, &wsaData);
        if ( err != 0 ) {
                /* Tell the user that we could not find a usable Winsock DLL */
@@ -918,24 +915,20 @@ internal_sendmsg(isc_socket_t *sock, IoCompletionInfo *lpo,
        int total_sent;
 
        *Error = 0;
-       Result = WSASendTo((SOCKET) sock->fd, 
-                       messagehdr->msg_iov, 
-                       messagehdr->msg_iovlen, 
-                       &BytesSent,
-                       Flags,
-                       messagehdr->msg_name,
-                       messagehdr->msg_namelen,
-                       (LPOVERLAPPED) lpo,
-                       NULL);
+       Result = WSASendTo((SOCKET) sock->fd, messagehdr->msg_iov,
+                          messagehdr->msg_iovlen, &BytesSent,
+                          Flags, messagehdr->msg_name,
+                          messagehdr->msg_namelen, (LPOVERLAPPED) lpo,
+                          NULL);
 
        total_sent = (int) BytesSent;
-    
+
        /* Check for errors.*/
        if (Result == SOCKET_ERROR) {
 
                *Error = WSAGetLastError();
-        
-               switch (*Error) {
+
+               switch (*Error) {
                case WSA_IO_INCOMPLETE :
                case WSA_WAIT_IO_COMPLETION :
                case WSA_IO_PENDING :
@@ -981,8 +974,8 @@ internal_recvmsg(isc_socket_t *sock, IoCompletionInfo *lpo,
        if (Result == SOCKET_ERROR) {
 
                *Error = WSAGetLastError();
-        
-               switch (*Error) {
+
+               switch (*Error) {
                case WSA_IO_INCOMPLETE:
                case WSA_WAIT_IO_COMPLETION:
                case WSA_IO_PENDING:
@@ -1003,7 +996,7 @@ internal_recvmsg(isc_socket_t *sock, IoCompletionInfo *lpo,
                return (-1);
        else
                return (total_bytes);
-} 
+}
 
 static void
 manager_log(isc_socketmgr_t *sockmgr, isc_logcategory_t *category,
@@ -1124,14 +1117,10 @@ connection_reset_fix(SOCKET fd) {
  *
  * Nothing can be NULL, and the done event must list at least one buffer
  * on the buffer linked list for this function to be meaningful.
- *
- * If write_countp != NULL, *write_countp will hold the number of bytes
- * this transaction can send.
  */
 static void
 build_msghdr_send(isc_socket_t *sock, isc_socketevent_t *dev,
-                 struct msghdr *msg, char *cmsg,
-                 WSABUF *iov, size_t *write_countp)
+                 struct msghdr *msg, char *cmsg, WSABUF *iov)
 {
        unsigned int iovcount;
        isc_buffer_t *buffer;
@@ -1199,9 +1188,7 @@ build_msghdr_send(isc_socket_t *sock, isc_socketevent_t *dev,
  config:
        msg->msg_iov = iov;
        msg->msg_iovlen = iovcount;
-
-       if (write_countp != NULL)
-               *write_countp = write_count;
+       msg->msg_totallen = write_count;
 }
 
 /*
@@ -1212,14 +1199,10 @@ build_msghdr_send(isc_socket_t *sock, isc_socketevent_t *dev,
  *
  * Nothing can be NULL, and the done event must list at least one buffer
  * on the buffer linked list for this function to be meaningful.
- *
- * If read_countp != NULL, *read_countp will hold the number of bytes
- * this transaction can receive.
  */
 static void
 build_msghdr_recv(isc_socket_t *sock, isc_socketevent_t *dev,
-                 struct msghdr *msg, char *cmsg,
-                 WSABUF *iov, size_t *read_countp)
+                 struct msghdr *msg, char *cmsg, WSABUF *iov)
 {
        unsigned int iovcount;
        isc_buffer_t *buffer;
@@ -1285,9 +1268,7 @@ build_msghdr_recv(isc_socket_t *sock, isc_socketevent_t *dev,
 
        msg->msg_iov = iov;
        msg->msg_iovlen = iovcount;
-
-       if (read_countp != NULL)
-               *read_countp = read_count;
+       msg->msg_totallen = read_count;
 }
 
 static void
@@ -1344,11 +1325,6 @@ dump_msg(struct msghdr *msg, isc_socket_t *sock) {
 }
 #endif
 
-#define DOIO_SUCCESS           0       /* i/o ok, event sent */
-#define DOIO_SOFT              1       /* i/o ok, soft error, no event sent */
-#define DOIO_HARD              2       /* i/o error, event sent */
-#define DOIO_EOF               3       /* EOF, no event sent */
-
 static int
 completeio_recv(isc_socket_t *sock, isc_socketevent_t *dev,
                struct msghdr *messagehdr, int cc, int recv_errno)
@@ -1389,6 +1365,7 @@ completeio_recv(isc_socket_t *sock, isc_socketevent_t *dev,
                ALWAYS_HARD(ERROR_PORT_UNREACHABLE, ISC_R_HOSTUNREACH);
                ALWAYS_HARD(ERROR_HOST_UNREACHABLE, ISC_R_HOSTUNREACH);
                ALWAYS_HARD(ERROR_NETWORK_UNREACHABLE, ISC_R_NETUNREACH);
+               ALWAYS_HARD(ERROR_NETNAME_DELETED, ISC_R_NETUNREACH);
                ALWAYS_HARD(WSAENOBUFS, ISC_R_NORESOURCES);
 
 #undef SOFT_OR_HARD
@@ -1412,7 +1389,7 @@ completeio_recv(isc_socket_t *sock, isc_socketevent_t *dev,
                        if (isc_log_wouldlog(isc_lctx, IOEVENT_LEVEL)) {
                                socket_log(sock, &dev->address, IOEVENT,
                                           isc_msgcat, ISC_MSGSET_SOCKET,
-                                          ISC_MSG_ZEROPORT, 
+                                          ISC_MSG_ZEROPORT,
                                           "dropping source port zero packet");
                        }
                        return (DOIO_SOFT);
@@ -1462,7 +1439,7 @@ completeio_recv(isc_socket_t *sock, isc_socketevent_t *dev,
         * If we read less than we expected, update counters,
         * and let the upper layer handle it.
         */
-       if (((size_t)cc != sock->totalBytes) && (dev->n < dev->minimum))
+       if ((cc != messagehdr->msg_totallen) && (dev->n < dev->minimum))
                return (DOIO_SOFT);
 
        /*
@@ -1490,8 +1467,7 @@ startio_recv(isc_socket_t *sock, isc_socketevent_t *dev, int *nbytes,
        msghdr = &lpo->messagehdr;
        memset(msghdr, 0, sizeof(struct msghdr));
 
-       build_msghdr_recv(sock, dev, msghdr, cmsg, sock->iov,
-                         &(sock->totalBytes));
+       build_msghdr_recv(sock, dev, msghdr, cmsg, sock->iov);
 
 #if defined(ISC_SOCKET_DEBUG)
        dump_msg(msghdr, sock);
@@ -1500,22 +1476,32 @@ startio_recv(isc_socket_t *sock, isc_socketevent_t *dev, int *nbytes,
        *nbytes = internal_recvmsg(sock, lpo, msghdr, 0, recv_errno);
 
        if (*nbytes < 0) {
+               /*
+                * I/O has been initiated
+                * return will be via the completion port
+                */
+               if (PENDING_ERROR(*recv_errno)) {
+                       status = DOIO_PENDING;
+                       goto done;
+               }
                if (SOFT_ERROR(*recv_errno)) {
                        status = DOIO_SOFT;
                        goto done;
                }
 
+               /*
+                * If we got this far something is wrong
+                */
                if (isc_log_wouldlog(isc_lctx, IOEVENT_LEVEL)) {
                        isc__strerror(*recv_errno, strbuf, sizeof(strbuf));
                        socket_log(sock, NULL, IOEVENT,
                                   isc_msgcat, ISC_MSGSET_SOCKET,
-                                  ISC_MSG_DOIORECV, 
+                                  ISC_MSG_DOIORECV,
                                  "startio_recv: recvmsg(%d) %d bytes, "
                                  "err %d/%s",
                                   sock->fd, *nbytes, *recv_errno, strbuf);
                }
-               status = completeio_recv(sock, dev, msghdr,
-                                        *nbytes, *recv_errno);
+               status = DOIO_HARD;
                goto done;
        }
        dev->result = ISC_R_SUCCESS;
@@ -1546,6 +1532,7 @@ completeio_send(isc_socket_t *sock, isc_socketevent_t *dev,
 
        if(send_errno != 0) {
 
+
                if (SOFT_ERROR(send_errno))
                        return (DOIO_SOFT);
 
@@ -1609,7 +1596,7 @@ completeio_send(isc_socket_t *sock, isc_socketevent_t *dev,
         * If we write less than we expected, update counters, poke.
         */
        dev->n += cc;
-       if ((size_t)cc != sock->totalBytes)
+       if (cc != messagehdr->msg_totallen)
                return (DOIO_SOFT);
 
        /*
@@ -1638,28 +1625,38 @@ startio_send(isc_socket_t *sock, isc_socketevent_t *dev, int *nbytes,
        msghdr = &lpo->messagehdr;
        memset(msghdr, 0, sizeof(struct msghdr));
 
-       build_msghdr_send(sock, dev, msghdr, cmsg, sock->iov,
-                       &(sock->totalBytes));
+       build_msghdr_send(sock, dev, msghdr, cmsg, sock->iov);
 
        *nbytes = internal_sendmsg(sock, lpo, msghdr, 0, send_errno);
 
+
        if (*nbytes < 0) {
+               /*
+                * I/O has been initiated
+                * completion will be through the completion port
+                */
+               if (PENDING_ERROR(*send_errno)) {
+                       status = DOIO_PENDING;
+                       goto done;
+               }
+
                if (SOFT_ERROR(*send_errno)) {
                        status = DOIO_SOFT;
                        goto done;
                }
 
+               /*
+                * If we got this far then something is wrong
+                */
                if (isc_log_wouldlog(isc_lctx, IOEVENT_LEVEL)) {
                        isc__strerror(*send_errno, strbuf, sizeof(strbuf));
                        socket_log(sock, NULL, IOEVENT,
                                   isc_msgcat, ISC_MSGSET_SOCKET,
-                                  ISC_MSG_INTERNALSEND, 
+                                  ISC_MSG_INTERNALSEND,
                                   "startio_send: internal_sendmsg(%d) %d "
                                   "bytes, err %d/%s",
                                   sock->fd, *nbytes, *send_errno, strbuf);
                }
-               status = completeio_send(sock, dev, msghdr,
-                                        *nbytes, *send_errno);
                goto done;
        }
        dev->result = ISC_R_SUCCESS;
@@ -1861,7 +1858,7 @@ isc_socket_create(isc_socketmgr_t *manager, int pf, isc_sockettype_t type,
                sock->fd = socket(pf, SOCK_STREAM, IPPROTO_TCP);
                break;
        }
-       
+
        if (sock->fd == INVALID_SOCKET) {
                socket_errno = WSAGetLastError();
                free_socket(&sock);
@@ -1931,7 +1928,7 @@ isc_socket_create(isc_socketmgr_t *manager, int pf, isc_sockettype_t type,
                                         strbuf);
                }
 #endif /* IPV6_RECVPKTINFO */
-#ifdef IPV6_USE_MIN_MTU        /*2292bis, not too common yet*/
+#ifdef IPV6_USE_MIN_MTU        /*2292bis, not too common yet*/
                /* use minimum MTU */
                if (pf == AF_INET6) {
                        (void)setsockopt(sock->fd, IPPROTO_IPV6,
@@ -2119,7 +2116,7 @@ internal_accept(isc_socket_t *sock, int accept_errno) {
                UNLOCK(&sock->lock);
                return;
        }
-       
+
        /*
         * Get the first item off the accept list.
         * If it is empty, unlock the socket and return.
@@ -2148,7 +2145,7 @@ internal_accept(isc_socket_t *sock, int accept_errno) {
 
        /*
         * Try to accept the new connection.  If the accept fails with
-        * EAGAIN or EINTR, the event wait will be notified again since
+        * WSAEINTR, the event wait will be notified again since
         * the event will be reset on return to caller.
         */
        addrlen = sizeof(dev->newsocket->address.type);
@@ -2186,7 +2183,7 @@ internal_accept(isc_socket_t *sock, int accept_errno) {
                        UNEXPECTED_ERROR(__FILE__, __LINE__,
                                         "internal_accept(): "
                                         "accept() returned peer address "
-                                        "family %u (expected %u)", 
+                                        "family %u (expected %u)",
                                         dev->newsocket->address.
                                         type.sa.sa_family,
                                         sock->pf);
@@ -2214,7 +2211,7 @@ internal_accept(isc_socket_t *sock, int accept_errno) {
                const char *msg;
                stat = WSAGetLastError();
                isc__strerror(stat, strbuf, sizeof(strbuf));
-               msg = isc_msgcat_get(isc_msgcat, ISC_MSGSET_GENERAL,    
+               msg = isc_msgcat_get(isc_msgcat, ISC_MSGSET_GENERAL,
                                     ISC_MSG_FAILED, "failed");
                UNEXPECTED_ERROR(__FILE__, __LINE__, "WSAEventSelect: %s: %s",
                                 msg, strbuf);
@@ -2254,7 +2251,7 @@ internal_accept(isc_socket_t *sock, int accept_errno) {
                        const char *msg;
                        stat = WSAGetLastError();
                        isc__strerror(stat, strbuf, sizeof(strbuf));
-                       msg = isc_msgcat_get(isc_msgcat, ISC_MSGSET_GENERAL,    
+                       msg = isc_msgcat_get(isc_msgcat, ISC_MSGSET_GENERAL,
                                             ISC_MSG_FAILED, "failed");
                        UNEXPECTED_ERROR(__FILE__, __LINE__,
                                         "WSAEventSelect: %s: %s", msg, strbuf);
@@ -2322,7 +2319,7 @@ internal_connect(isc_socket_t *sock, int connect_errno) {
         */
        if (connect_errno != 0) {
                /*
-                * If the error is EAGAIN, just try again on this
+                * If the error is SOFT, just try again on this
                 * fd and pretend nothing strange happened.
                 */
                if (SOFT_ERROR(connect_errno) ||
@@ -2433,8 +2430,6 @@ internal_send(isc_socket_t *sock, isc_socketevent_t *dev,
              struct msghdr *messagehdr, int nbytes, int send_errno)
 {
        isc_socketevent_t *ldev;
-       int io_state;
-       int cc;
 
        /*
         * Find out what socket this is and lock it.
@@ -2462,11 +2457,7 @@ internal_send(isc_socket_t *sock, isc_socketevent_t *dev,
         */
        switch (completeio_send(sock, dev, messagehdr, nbytes, send_errno)) {
        case DOIO_SOFT:
-               cc = 0;
-               send_errno = 0;
-               io_state = startio_send(sock, dev, &cc, &send_errno);
-               goto done;
-
+               break;
        case DOIO_HARD:
        case DOIO_SUCCESS:
                send_senddone_event(sock, &dev);
@@ -2519,12 +2510,10 @@ SocketIoThread(LPVOID ThreadContext) {
         * Loop forever waiting on I/O Completions and then processing them
         */
        while (TRUE) {
-               bSuccess = GetQueuedCompletionStatus (
-                                       manager->hIoCompletionPort,
-                                       &nbytes,
-                                       (LPDWORD) &sock,
-                                       (LPOVERLAPPED *)&lpo,
-                                       INFINITE);
+               bSuccess = GetQueuedCompletionStatus(manager->hIoCompletionPort,
+                                                    &nbytes, (LPDWORD) &sock,
+                                                    (LPOVERLAPPED *)&lpo,
+                                                    INFINITE);
                if (lpo == NULL) {
                        /*
                         * Received request to exit
@@ -2538,7 +2527,7 @@ SocketIoThread(LPVOID ThreadContext) {
                        /*
                         * Was this the socket closed under us?
                         */
-                       errstatus = WSAGetLastError();
+                       errstatus = GetLastError();
                        if (nbytes == 0 && errstatus == WSA_OPERATION_ABORTED) {
                                LOCK(&sock->lock);
                                switch (lpo->request_type) {
@@ -2635,7 +2624,7 @@ event_wait(void *uap) {
                        if (cc == WSA_WAIT_FAILED) {
                                event_errno = WSAGetLastError();
                                if (!SOFT_ERROR(event_errno)) {
-                                       isc__strerror(event_errno, strbuf,
+                                       isc__strerror(event_errno, strbuf,
                                              sizeof(strbuf));
                                        FATAL_ERROR(__FILE__, __LINE__,
                                           "WSAWaitForMultipleEvents() %s: %s",
@@ -2893,6 +2882,7 @@ socket_recv(isc_socket_t *sock, isc_socketevent_t *dev, isc_task_t *task,
        io_state = startio_recv(sock, dev, &cc, &recv_errno);
 
        switch (io_state) {
+       case DOIO_PENDING:      /* I/O Started. Nothing to be done */
        case DOIO_SOFT:
                /*
                 * We couldn't read all or part of the request right now, so
@@ -3071,31 +3061,33 @@ socket_send(isc_socket_t *sock, isc_socketevent_t *dev, isc_task_t *task,
        io_state = startio_send(sock, dev, &cc, &send_errno);
 
        switch (io_state) {
+       case DOIO_PENDING:      /* I/O started. Nothing more to do */
        case DOIO_SOFT:
                /*
                 * We couldn't send all or part of the request right now, so
                 * queue it unless ISC_SOCKFLAG_NORETRY is set.
                 */
-               isc_task_attach(task, &ntask);
-               dev->attributes |= ISC_SOCKEVENTATTR_ATTACHED;
-
-               if (!have_lock) {
-                       LOCK(&sock->lock);
-                       have_lock = ISC_TRUE;
-               }
+               if ((flags & ISC_SOCKFLAG_NORETRY) == 0) {
+                       isc_task_attach(task, &ntask);
+                       dev->attributes |= ISC_SOCKEVENTATTR_ATTACHED;
+                       if (!have_lock) {
+                               LOCK(&sock->lock);
+                               have_lock = ISC_TRUE;
+                       }
 
-               /*
-                * Enqueue the request.
-                */
-               ISC_LIST_ENQUEUE(sock->send_list, dev, ev_link);
+                       /*
+                        * Enqueue the request.
+                        */
+                       ISC_LIST_ENQUEUE(sock->send_list, dev, ev_link);
 
-               socket_log(sock, NULL, EVENT, NULL, 0, 0,
-                          "socket_send: event %p -> task %p",
-                          dev, ntask);
+                       socket_log(sock, NULL, EVENT, NULL, 0, 0,
+                                  "socket_send: event %p -> task %p",
+                                  dev, ntask);
 
-               if ((flags & ISC_SOCKFLAG_IMMEDIATE) != 0)
-                       result = ISC_R_INPROGRESS;
-               break;
+                       if ((flags & ISC_SOCKFLAG_IMMEDIATE) != 0)
+                               result = ISC_R_INPROGRESS;
+                       break;
+               }
 
        case DOIO_SUCCESS:
                break;
@@ -3269,10 +3261,10 @@ isc_socket_bind(isc_socket_t *sock, isc_sockaddr_t *sockaddr) {
 
 isc_result_t
 isc_socket_filter(isc_socket_t *sock, const char *filter) {
-        UNUSED(sock);
-        UNUSED(filter);
+       UNUSED(sock);
+       UNUSED(filter);
 
-        REQUIRE(VALID_SOCKET(sock));
+       REQUIRE(VALID_SOCKET(sock));
        return (ISC_R_NOTIMPLEMENTED);
 }
 
@@ -3326,7 +3318,6 @@ isc_socket_listen(isc_socket_t *sock, unsigned int backlog) {
                return (retstat);
        }
 
-
        UNLOCK(&sock->lock);
        return (ISC_R_SUCCESS);
 }
@@ -3392,7 +3383,7 @@ isc_socket_accept(isc_socket_t *sock,
                const char *msg;
                stat = WSAGetLastError();
                isc__strerror(stat, strbuf, sizeof(strbuf));
-               msg = isc_msgcat_get(isc_msgcat, ISC_MSGSET_GENERAL,    
+               msg = isc_msgcat_get(isc_msgcat, ISC_MSGSET_GENERAL,
                                     ISC_MSG_FAILED, "failed");
                UNEXPECTED_ERROR(__FILE__, __LINE__, "WSAEventSelect: %s: %s",
                                 msg, strbuf);
@@ -3693,7 +3684,7 @@ isc_socket_cancel(isc_socket_t *sock, isc_task_t *task, unsigned int how) {
                        const char *msg;
                        stat = WSAGetLastError();
                        isc__strerror(stat, strbuf, sizeof(strbuf));
-                       msg = isc_msgcat_get(isc_msgcat, ISC_MSGSET_GENERAL,    
+                       msg = isc_msgcat_get(isc_msgcat, ISC_MSGSET_GENERAL,
                                             ISC_MSG_FAILED, "failed");
                        UNEXPECTED_ERROR(__FILE__, __LINE__,
                                         "WSAEventSelect: %s: %s", msg, strbuf);