]> git.ipfire.org Git - thirdparty/unbound.git/commitdiff
- wait for sendto to drain socket buffers when they are full.
authorWouter Wijngaards <wouter@nlnetlabs.nl>
Mon, 15 Feb 2016 09:54:52 +0000 (09:54 +0000)
committerWouter Wijngaards <wouter@nlnetlabs.nl>
Mon, 15 Feb 2016 09:54:52 +0000 (09:54 +0000)
git-svn-id: file:///svn/unbound/trunk@3624 be551aaa-1e26-0410-a405-d3ace91eadb9

doc/Changelog
util/netevent.c

index 2ad8ae40981182d4426934a66e3abf535723c6fd..b290fbe40d189a3b4a11e6909d4199f648ca9e19 100644 (file)
@@ -1,5 +1,6 @@
 15 February 2016: Wouter
        - ip-transparent option for FreeBSD with IP_BINDANY socket option.
+       - wait for sendto to drain socket buffers when they are full.
 
 9 February 2016: Wouter
        - Test for type OPENPGPKEY.
index d7ab218aaf3744555768530d7870bf537778041a..b827e6540b1f9c9f1208e7e4706909f76a051b69 100644 (file)
@@ -400,6 +400,31 @@ comm_point_send_udp_msg(struct comm_point *c, sldns_buffer* packet,
        sent = sendto(c->fd, (void*)sldns_buffer_begin(packet), 
                sldns_buffer_remaining(packet), 0,
                addr, addrlen);
+       if(sent == -1) {
+               /* try again and block, waiting for IO to complete,
+                * we want to send the answer, and we will wait for
+                * the ethernet interface buffer to have space. */
+#ifndef USE_WINSOCK
+               if(errno == EAGAIN || 
+#  ifdef EWOULDBLOCK
+                       errno == EWOULDBLOCK ||
+#  endif
+                       errno == ENOBUFS) {
+#else
+               if(WSAGetLastError() == WSAEINPROGRESS ||
+                       WSAGetLastError() == WSAENOBUFS ||
+                       WSAGetLastError() == WSAEWOULDBLOCK) {
+#endif
+                       int e;
+                       fd_set_block(c->fd);
+                       sent = sendto(c->fd, (void*)sldns_buffer_begin(packet), 
+                               sldns_buffer_remaining(packet), 0,
+                               addr, addrlen);
+                       e = errno;
+                       fd_set_nonblock(c->fd);
+                       errno = e;
+               }
+       }
        if(sent == -1) {
                if(!udp_send_errno_needs_log(addr, addrlen))
                        return 0;
@@ -553,6 +578,29 @@ comm_point_send_udp_msg_if(struct comm_point *c, sldns_buffer* packet,
        if(verbosity >= VERB_ALGO)
                p_ancil("send_udp over interface", r);
        sent = sendmsg(c->fd, &msg, 0);
+       if(sent == -1) {
+               /* try again and block, waiting for IO to complete,
+                * we want to send the answer, and we will wait for
+                * the ethernet interface buffer to have space. */
+#ifndef USE_WINSOCK
+               if(errno == EAGAIN || 
+#  ifdef EWOULDBLOCK
+                       errno == EWOULDBLOCK ||
+#  endif
+                       errno == ENOBUFS) {
+#else
+               if(WSAGetLastError() == WSAEINPROGRESS ||
+                       WSAGetLastError() == WSAENOBUFS ||
+                       WSAGetLastError() == WSAEWOULDBLOCK) {
+#endif
+                       int e;
+                       fd_set_block(c->fd);
+                       sent = sendmsg(c->fd, &msg, 0);
+                       e = errno;
+                       fd_set_nonblock(c->fd);
+                       errno = e;
+               }
+       }
        if(sent == -1) {
                if(!udp_send_errno_needs_log(addr, addrlen))
                        return 0;