[tbb-commits] [tor-browser/tor-browser-38.4.0esr-5.5-1] fixup! Bug 3875: Use Optimistic Data SOCKS variant.

gk at torproject.org gk at torproject.org
Fri Dec 11 12:40:26 UTC 2015


commit bbd7c24a1019ecfac43aeaac959143b575cca07f
Author: Kathy Brade <brade at pearlcrescent.com>
Date:   Tue Nov 10 12:00:44 2015 -0500

    fixup! Bug 3875: Use Optimistic Data SOCKS variant.
    
    Avoid a CPU loop when processing HTTP requests, do not alter the
    behavior of the socket transport state machine when SOCKS is not
    being used, and improve comments. Fixes bug 9659.
---
 netwerk/base/nsSocketTransport2.cpp |   38 ++++++++++++++++++++++-------------
 1 file changed, 24 insertions(+), 14 deletions(-)

diff --git a/netwerk/base/nsSocketTransport2.cpp b/netwerk/base/nsSocketTransport2.cpp
index 07a92c4..c98365e 100644
--- a/netwerk/base/nsSocketTransport2.cpp
+++ b/netwerk/base/nsSocketTransport2.cpp
@@ -1836,22 +1836,32 @@ nsSocketTransport::OnSocketReady(PRFileDesc *fd, int16_t outFlags)
         mPollTimeout = mTimeouts[TIMEOUT_READ_WRITE];
     }
 
-//STATE_SENDINGGET: handshake proceeded to state "sent connect"
-//one more poll to OnSocketReady will trigger the get request, and state STATE_SENTGET
-//STATE_SENTGET: continue and finish handshake
+    // Tor 3875: Use optimistic data with SOCKS.
+    // To accomplish this, two new states were added that are only used with
+    // SOCKS connections:
+    //   STATE_SENDINGGET - The SOCKS handshake has proceeded to the
+    //                        "sent connect" state; now it is okay to
+    //                         optimistically send some application data (e.g.,
+    //                         an HTTP GET request).
+    //   STATE_SENTGET -    Optimistic data has been sent; make a second call
+    //                        to PR_ConnectContinue() to allow the SOCKS
+    //                        handshake to finish.
     else if (mState == STATE_SENDINGGET) {
         if ((mPollFlags & PR_POLL_WRITE) && (outFlags & ~PR_POLL_READ)) {
-            mOutput.OnSocketReady(NS_OK);
+            mOutput.OnSocketReady(NS_OK);  // Allow application data to be sent.
         }
         mPollTimeout = mTimeouts[TIMEOUT_READ_WRITE];
-        mState = STATE_SENTGET;
+        mPollFlags = (PR_POLL_EXCEPT | PR_POLL_READ);
+        mState = STATE_SENTGET;  // Wait for SOCKS handshake response.
     }
-
     else if (mState == STATE_CONNECTING || mState == STATE_SENTGET) {
         PRStatus status = PR_ConnectContinue(fd, outFlags);
+        bool isUsingSocks = mProxyTransparent && !mProxyHost.IsEmpty();
         if (status == PR_SUCCESS && mState == STATE_CONNECTING) {
             OnSocketConnected();
-            mState = STATE_SENDINGGET;
+            if (isUsingSocks) {
+                mState = STATE_SENDINGGET;
+            }
         }
         else if (status == PR_SUCCESS && mState == STATE_SENTGET) {
             //
@@ -1868,17 +1878,17 @@ nsSocketTransport::OnSocketReady(PRFileDesc *fd, int16_t outFlags)
             // If the connect is still not ready, then continue polling...
             //
             if ((PR_WOULD_BLOCK_ERROR == code) || (PR_IN_PROGRESS_ERROR == code)) {
-                // Set up the select flags for connect...
-                mPollFlags = (PR_POLL_EXCEPT | PR_POLL_WRITE);
-                // Update poll timeout in case it was changed
-                mPollTimeout = mTimeouts[TIMEOUT_CONNECT];
+                if (mState != STATE_SENTGET) {
+                    // Set up the select flags for connect...
+                    mPollFlags = (PR_POLL_EXCEPT | PR_POLL_WRITE);
+                    // Update poll timeout in case it was changed
+                    mPollTimeout = mTimeouts[TIMEOUT_CONNECT];
+                }
             }
             //
             // The SOCKS proxy rejected our request. Find out why.
             //
-            else if (PR_UNKNOWN_ERROR == code &&
-                     mProxyTransparent &&
-                     !mProxyHost.IsEmpty()) {
+            else if (PR_UNKNOWN_ERROR == code && isUsingSocks) {
                 code = PR_GetOSError();
                 mCondition = ErrorAccordingToNSPR(code);
             }



More information about the tbb-commits mailing list