Bug 710176, Part 2: Import ssl_Poll fix from bug 542832, r=kaie
authorBrian Smith <bsmith@mozilla.com>
Tue, 31 Jan 2012 04:24:16 -0800
changeset 87058 b26ac73e455441df4adb5aef4de0e1c049038436
parent 87057 fc9db5c753795359ac867efdfdcdc6551d55e7e1
child 87059 69daa03d3ce35a4a36f33be1522a14df83fe42d8
push id805
push userakeybl@mozilla.com
push dateWed, 01 Feb 2012 18:17:35 +0000
treeherdermozilla-aurora@6fb3bf232436 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerskaie
bugs710176, 542832
milestone12.0a1
Bug 710176, Part 2: Import ssl_Poll fix from bug 542832, r=kaie
security/nss/lib/ssl/sslsock.c
security/patches/README
security/patches/bug-710176-ssl-restart-7-poll-v5.patch
--- a/security/nss/lib/ssl/sslsock.c
+++ b/security/nss/lib/ssl/sslsock.c
@@ -1950,17 +1950,31 @@ ssl_Poll(PRFileDesc *fd, PRInt16 how_fla
 	    }
 	}
     } else if ((new_flags & PR_POLL_READ) && (SSL_DataPending(fd) > 0)) {
 	*p_out_flags = PR_POLL_READ;	/* it's ready already. */
 	return new_flags;
     } else if ((ss->lastWriteBlocked) && (how_flags & PR_POLL_READ) &&
 	       (ss->pendingBuf.len != 0)) { /* write data waiting to be sent */
 	new_flags |=  PR_POLL_WRITE;   /* also select on write. */
-    } 
+    }
+
+    if (ss->version >= SSL_LIBRARY_VERSION_3_0 &&
+	ss->ssl3.hs.restartTarget != NULL) {
+	/* Read and write will block until the asynchronous callback completes
+	 * (e.g. until SSL_AuthCertificateComplete is called), so don't tell
+	 * the caller to poll the socket unless there is pending write data.
+	 */
+	if (ss->lastWriteBlocked && ss->pendingBuf.len != 0) {
+	    new_flags &= (PR_POLL_WRITE | PR_POLL_EXCEPT);
+	} else {
+	    new_flags = 0;
+	}
+    }
+
     if (new_flags && (fd->lower->methods->poll != NULL)) {
 	PRInt16    lower_out_flags = 0;
 	PRInt16    lower_new_flags;
         lower_new_flags = fd->lower->methods->poll(fd->lower, new_flags, 
 					           &lower_out_flags);
 	if ((lower_new_flags & lower_out_flags) && (how_flags != new_flags)) {
 	    PRInt16 out_flags = lower_out_flags & ~PR_POLL_RW;
 	    if (lower_out_flags & PR_POLL_READ) 
--- a/security/patches/README
+++ b/security/patches/README
@@ -1,8 +1,9 @@
 This directory contains patches that were added locally
 on top of the NSS release.
 
 bug-542832-ssl-restart-4.patch and bug-542832-ssl-restart-tstclnt-4.patch were
 added so that we could test the new PSM SSL threading code (bug 674147) and
 SPDY (bug 528288). bug-717906-lowhash was added to fix an issue with recent
-Mozilla builds on fedora. These patches will be removed when the NSS 3.13.2
+Mozilla builds on fedora. bug-710176-ssl-restart-7-poll-v5.patch were added
+to fix a bug 710176. These patches will be removed when the NSS 3.13.2
 release that includes them is imported into mozilla-central.
new file mode 100644
--- /dev/null
+++ b/security/patches/bug-710176-ssl-restart-7-poll-v5.patch
@@ -0,0 +1,40 @@
+# HG changeset patch
+# Parent 4560e2c22b83f85f9238b9094de7a190042676df
+# User Brian Smith <bsmith@mozilla.com>
+
+diff --git a/security/nss/lib/ssl/sslsock.c b/security/nss/lib/ssl/sslsock.c
+--- a/security/nss/lib/ssl/sslsock.c
++++ b/security/nss/lib/ssl/sslsock.c
+@@ -1950,17 +1950,31 @@ ssl_Poll(PRFileDesc *fd, PRInt16 how_fla
+ 	    }
+ 	}
+     } else if ((new_flags & PR_POLL_READ) && (SSL_DataPending(fd) > 0)) {
+ 	*p_out_flags = PR_POLL_READ;	/* it's ready already. */
+ 	return new_flags;
+     } else if ((ss->lastWriteBlocked) && (how_flags & PR_POLL_READ) &&
+ 	       (ss->pendingBuf.len != 0)) { /* write data waiting to be sent */
+ 	new_flags |=  PR_POLL_WRITE;   /* also select on write. */
+-    } 
++    }
++
++    if (ss->version >= SSL_LIBRARY_VERSION_3_0 &&
++	ss->ssl3.hs.restartTarget != NULL) {
++	/* Read and write will block until the asynchronous callback completes
++	 * (e.g. until SSL_AuthCertificateComplete is called), so don't tell
++	 * the caller to poll the socket unless there is pending write data.
++	 */
++	if (ss->lastWriteBlocked && ss->pendingBuf.len != 0) {
++	    new_flags &= (PR_POLL_WRITE | PR_POLL_EXCEPT);
++	} else {
++	    new_flags = 0;
++	}
++    }
++
+     if (new_flags && (fd->lower->methods->poll != NULL)) {
+ 	PRInt16    lower_out_flags = 0;
+ 	PRInt16    lower_new_flags;
+         lower_new_flags = fd->lower->methods->poll(fd->lower, new_flags, 
+ 					           &lower_out_flags);
+ 	if ((lower_new_flags & lower_out_flags) && (how_flags != new_flags)) {
+ 	    PRInt16 out_flags = lower_out_flags & ~PR_POLL_RW;
+ 	    if (lower_out_flags & PR_POLL_READ)