Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 8 Jul 2011 10:50:13 +0000 (UTC)
From:      Andre Oppermann <andre@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org
Subject:   svn commit: r223863 - head/sys/kern
Message-ID:  <201107081050.p68AoD9D004336@svn.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: andre
Date: Fri Jul  8 10:50:13 2011
New Revision: 223863
URL: http://svn.freebsd.org/changeset/base/223863

Log:
  In the experimental soreceive_stream():
  
   o Move the non-blocking socket test below the SBS_CANTRCVMORE so that EOF
     is correctly returned on a remote connection close.
   o In the non-blocking socket test compare SS_NBIO against the so->so_state
     field instead of the incorrect sb->sb_state field.
   o Simplify the ENOTCONN test by removing cases that can't occur.
  
  Submitted by:	trociny (with some further tweaks by committer)
  Tested by:	trociny

Modified:
  head/sys/kern/uipc_socket.c

Modified: head/sys/kern/uipc_socket.c
==============================================================================
--- head/sys/kern/uipc_socket.c	Fri Jul  8 09:38:33 2011	(r223862)
+++ head/sys/kern/uipc_socket.c	Fri Jul  8 10:50:13 2011	(r223863)
@@ -1954,20 +1954,9 @@ soreceive_stream(struct socket *so, stru
 	}
 	oresid = uio->uio_resid;
 
-	/* We will never ever get anything unless we are connected. */
+	/* We will never ever get anything unless we are or were connected. */
 	if (!(so->so_state & (SS_ISCONNECTED|SS_ISDISCONNECTED))) {
-		/* When disconnecting there may be still some data left. */
-		if (sb->sb_cc > 0)
-			goto deliver;
-		if (!(so->so_state & SS_ISDISCONNECTED))
-			error = ENOTCONN;
-		goto out;
-	}
-
-	/* Socket buffer is empty and we shall not block. */
-	if (sb->sb_cc == 0 &&
-	    ((sb->sb_flags & SS_NBIO) || (flags & (MSG_DONTWAIT|MSG_NBIO)))) {
-		error = EAGAIN;
+		error = ENOTCONN;
 		goto out;
 	}
 
@@ -1994,6 +1983,13 @@ restart:
 			goto out;
 	}
 
+	/* Socket buffer is empty and we shall not block. */
+	if (sb->sb_cc == 0 &&
+	    ((so->so_state & SS_NBIO) || (flags & (MSG_DONTWAIT|MSG_NBIO)))) {
+		error = EAGAIN;
+		goto out;
+	}
+
 	/* Socket buffer got some data that we shall deliver now. */
 	if (sb->sb_cc > 0 && !(flags & MSG_WAITALL) &&
 	    ((sb->sb_flags & SS_NBIO) ||



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201107081050.p68AoD9D004336>