This is the mail archive of the cygwin-cvs@cygwin.com mailing list for the Cygwin project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[newlib-cygwin] Ensure that send() interrupted by a signal returns sucessfully


https://sourceware.org/git/gitweb.cgi?p=newlib-cygwin.git;h=5ca286666a0cd71436a84797d5d66831790004e0

commit 5ca286666a0cd71436a84797d5d66831790004e0
Author: Erik M. Bray <erik.m.bray@gmail.com>
Date:   Thu Jun 15 15:30:08 2017 +0200

    Ensure that send() interrupted by a signal returns sucessfully
    
    When SA_RESTART is not set on a socket, a blocking send() that is
    interrupted mid-transition by a signal should return success (and
    report just how many bytes were actually transmitted).
    
    The err variable used here was not always guaranteed to be set
    correctly in the loop, so better to just remove it and call
    WSAGetLastError() explicitly.

Diff:
---
 winsup/cygwin/fhandler_socket.cc | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/winsup/cygwin/fhandler_socket.cc b/winsup/cygwin/fhandler_socket.cc
index f3d1d69..7a6dbdc 100644
--- a/winsup/cygwin/fhandler_socket.cc
+++ b/winsup/cygwin/fhandler_socket.cc
@@ -1769,7 +1769,7 @@ inline ssize_t
 fhandler_socket::send_internal (struct _WSAMSG *wsamsg, int flags)
 {
   ssize_t res = 0;
-  DWORD ret = 0, err = 0, sum = 0;
+  DWORD ret = 0, sum = 0;
   WSABUF out_buf[wsamsg->dwBufferCount];
   bool use_sendmsg = false;
   DWORD wait_flags = flags & MSG_DONTWAIT;
@@ -1830,14 +1830,14 @@ fhandler_socket::send_internal (struct _WSAMSG *wsamsg, int flags)
 	    res = WSASendTo (get_socket (), wsamsg->lpBuffers,
 			     wsamsg->dwBufferCount, &ret, flags,
 			     wsamsg->name, wsamsg->namelen, NULL, NULL);
-	  if (res && (err = WSAGetLastError ()) == WSAEWOULDBLOCK)
+	  if (res && (WSAGetLastError () == WSAEWOULDBLOCK))
 	    {
 	      LOCK_EVENTS;
 	      wsock_events->events &= ~FD_WRITE;
 	      UNLOCK_EVENTS;
 	    }
 	}
-      while (res && err == WSAEWOULDBLOCK
+      while (res && (WSAGetLastError () == WSAEWOULDBLOCK)
 	     && !(res = wait_for_events (FD_WRITE | FD_CLOSE, wait_flags)));
 
       if (!res)
@@ -1851,7 +1851,7 @@ fhandler_socket::send_internal (struct _WSAMSG *wsamsg, int flags)
 	  if (get_socket_type () != SOCK_STREAM || ret < out_len)
 	    break;
 	}
-      else if (is_nonblocking () || err != WSAEWOULDBLOCK)
+      else if (is_nonblocking () || WSAGetLastError() != WSAEWOULDBLOCK)
 	break;
     }


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]