[Libreoffice-commits] online.git: Branch 'private/Ashod/nonblocking' - net/socket.hpp

Ashod Nakashian ashod.nakashian at collabora.co.uk
Sat Feb 18 21:19:57 UTC 2017


 net/socket.hpp |   73 +++++++++++++++++++++++++++------------------------------
 1 file changed, 35 insertions(+), 38 deletions(-)

New commits:
commit 78a99f019b310ba2cb6b7a3f9aa411ba63480331
Author: Ashod Nakashian <ashod.nakashian at collabora.co.uk>
Date:   Sat Feb 18 16:14:48 2017 -0500

    nb: refactor and reuse ssl handshake handler
    
    Change-Id: Ie65b7d1bac8391ccb2905fa8376a26ee4c3d4e30
    Reviewed-on: https://gerrit.libreoffice.org/34416
    Reviewed-by: Ashod Nakashian <ashnakash at gmail.com>
    Tested-by: Ashod Nakashian <ashnakash at gmail.com>

diff --git a/net/socket.hpp b/net/socket.hpp
index dc04d4d..1a6c4a1 100644
--- a/net/socket.hpp
+++ b/net/socket.hpp
@@ -417,25 +417,10 @@ class SslStreamSocket : public BufferingSocket
 public:
     bool readIncomingData() override
     {
-        if (_doHandshake)
+        const int rc = doHandshake();
+        if (rc <= 0)
         {
-            int rc;
-            do
-            {
-                rc = SSL_do_handshake(_ssl);
-            }
-            while (rc < 0 && errno == EINTR);
-
-            if (rc <= 0)
-            {
-                rc = handleSslState(rc);
-                if (rc <= 0)
-                {
-                    return (rc != 0);
-                }
-            }
-
-            _doHandshake = false;
+            return (rc != 0);
         }
 
         // Default implementation.
@@ -444,25 +429,10 @@ public:
 
     void writeOutgoingData() override
     {
-        if (_doHandshake)
+        const int rc = doHandshake();
+        if (rc <= 0)
         {
-            int rc;
-            do
-            {
-                rc = SSL_do_handshake(_ssl);
-            }
-            while (rc < 0 && errno == EINTR);
-
-            if (rc <= 0)
-            {
-                rc = handleSslState(rc);
-                if (rc <= 0)
-                {
-                    return;
-                }
-            }
-
-            _doHandshake = false;
+            return;
         }
 
         // Default implementation.
@@ -493,8 +463,8 @@ public:
             return POLLOUT;
         }
 
-        // Do whatever makes sense based on buffer state.
-        return (_outBuffer.empty() ? POLLIN : (POLLIN | POLLOUT));
+        // Do the default.
+        return BufferingSocket::getPollEvents();
     }
 
 protected:
@@ -538,6 +508,33 @@ private:
         Write
     };
 
+    int doHandshake()
+    {
+        if (_doHandshake)
+        {
+            int rc;
+            do
+            {
+                rc = SSL_do_handshake(_ssl);
+            }
+            while (rc < 0 && errno == EINTR);
+
+            if (rc <= 0)
+            {
+                rc = handleSslState(rc);
+                if (rc <= 0)
+                {
+                    return (rc != 0);
+                }
+            }
+
+            _doHandshake = false;
+        }
+
+        // Handshake complete.
+        return 1;
+    }
+
     /// Handles the state of SSL after read or write.
     int handleSslState(const int rc)
     {


More information about the Libreoffice-commits mailing list