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

Ashod Nakashian ashod.nakashian at collabora.co.uk
Fri Feb 17 06:47:21 UTC 2017


 net/socket.hpp |   85 ++++++++++++++++++++++++++++++++++++++++++++++-----------
 1 file changed, 70 insertions(+), 15 deletions(-)

New commits:
commit 1dad5291aa5bd69dfcc17d9735e8106cd5418d34
Author: Ashod Nakashian <ashod.nakashian at collabora.co.uk>
Date:   Thu Feb 16 21:57:25 2017 -0500

    nb: refactor buffer management into BufferingSocket
    
    Now we have plain and ssl sockets based on
    the BufferingSocket, each is responsible for
    the socket IO only.
    
    The SSL socket is only shell missing implementation.
    
    Change-Id: I51d274a9335cec52c13b6a19927ddd46d98265a0
    Reviewed-on: https://gerrit.libreoffice.org/34352
    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 0ca0eb6..0f8345a 100644
--- a/net/socket.hpp
+++ b/net/socket.hpp
@@ -278,13 +278,11 @@ private:
     std::vector<pollfd> _pollFds;
 };
 
-
-/// A non-blocking, data streaming socket.
-/// Buffers and pumps data based on poll events.
-class StreamSocket : public Socket
+/// Abstract buffering socket.
+class BufferingSocket : public Socket
 {
 public:
-    StreamSocket() :
+    BufferingSocket() :
         Socket()
     {
     }
@@ -312,7 +310,43 @@ public:
                              HandleResult::CONTINUE;
     }
 
-    bool readIncomingData()
+    /// Override to reading data from socket.
+    virtual bool readIncomingData() = 0;
+
+    /// Override to write data out to socket.
+    virtual void writeOutgoingData() = 0;
+
+    int getPollEvents() override
+    {
+        int pollFor = POLLIN;
+        if (_outBuffer.size() > 0)
+            pollFor |= POLLOUT;
+        return pollFor;
+    }
+
+    /// Override to handle read data.
+    /// Called after successful socket reads.
+    virtual void handleIncomingMessage() = 0;
+
+protected:
+    BufferingSocket(const int fd) :
+        Socket(fd)
+    {
+    }
+};
+
+/// A plain, non-blocking, data streaming socket.
+class StreamSocket : public BufferingSocket
+{
+public:
+    StreamSocket() :
+        BufferingSocket()
+    {
+    }
+
+  public:
+
+    bool readIncomingData() override
     {
         ssize_t len;
         char buf[4096];
@@ -330,7 +364,7 @@ public:
         return len != 0; // zero is eof / clean socket close.
     }
 
-    void writeOutgoingData()
+    void writeOutgoingData() override
     {
         assert (_outBuffer.size() > 0);
         ssize_t len;
@@ -345,19 +379,40 @@ public:
         // else poll will handle errors
     }
 
-    int getPollEvents() override
+protected:
+    StreamSocket(const int fd) :
+        BufferingSocket(fd)
     {
-        int pollFor = POLLIN;
-        if (_outBuffer.size() > 0)
-            pollFor |= POLLOUT;
-        return pollFor;
     }
 
-    virtual void handleIncomingMessage() = 0;
+    friend class ServerSocket;
+};
+
+/// A SSL/TSL, non-blocking, data streaming socket.
+class SslStreamSocket : public BufferingSocket
+{
+public:
+    SslStreamSocket() :
+        BufferingSocket()
+    {
+    }
+
+  public:
+
+    bool readIncomingData() override
+    {
+        //TODO:
+        return true;
+    }
+
+    void writeOutgoingData() override
+    {
+        //TODO;
+    }
 
 protected:
-    StreamSocket(const int fd) :
-        Socket(fd)
+    SslStreamSocket(const int fd) :
+        BufferingSocket(fd)
     {
     }
 


More information about the Libreoffice-commits mailing list