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

Ashod Nakashian ashod.nakashian at collabora.co.uk
Sat Feb 18 00:43:28 UTC 2017


 net/loolnb.cpp |   12 +++++++-----
 net/socket.hpp |    6 ++++--
 2 files changed, 11 insertions(+), 7 deletions(-)

New commits:
commit d15a3d3945ee8fbab0381644de1be5857ca6f9c0
Author: Ashod Nakashian <ashod.nakashian at collabora.co.uk>
Date:   Fri Feb 17 18:17:16 2017 -0500

    nb: server can create any socket type on accept
    
    Change-Id: I1a786421628500844277e6a2f1d2fd7b0ac0c3e4
    Reviewed-on: https://gerrit.libreoffice.org/34392
    Reviewed-by: Ashod Nakashian <ashnakash at gmail.com>
    Tested-by: Ashod Nakashian <ashnakash at gmail.com>

diff --git a/net/loolnb.cpp b/net/loolnb.cpp
index d819a1c..9fb6dc0 100644
--- a/net/loolnb.cpp
+++ b/net/loolnb.cpp
@@ -280,6 +280,8 @@ Poco::Net::SocketAddress addrHttp("127.0.0.1", HttpPortNumber);
 Poco::Net::SocketAddress addrSsl("127.0.0.1", SslPortNumber);
 
 /// A non-blocking, streaming socket.
+/// T is the socket type created by accept.
+template <class T>
 class ServerSocket : public Socket
 {
     SocketPoll& _clientPoller;
@@ -317,8 +319,7 @@ public:
     /// Accepts an incoming connection (Servers only).
     /// Does not retry on error.
     /// Returns a valid Socket shared_ptr on success only.
-    template <typename T>
-       std::shared_ptr<T> accept()
+    std::shared_ptr<Socket> accept()
     {
         // Accept a connection (if any) and set it to non-blocking.
         // We don't care about the client's address, so ignored.
@@ -333,7 +334,7 @@ public:
 
     HandleResult handlePoll( int /* events */ ) override
     {
-        std::shared_ptr<SimpleResponseClient> clientSocket = accept<SimpleResponseClient>();
+        std::shared_ptr<Socket> clientSocket = accept();
         if (!clientSocket)
         {
             const std::string msg = "Failed to accept. (errno: ";
@@ -347,10 +348,11 @@ public:
     }
 };
 
+template <typename T>
 void server(const Poco::Net::SocketAddress& addr, SocketPoll& clientPoller)
 {
     // Start server.
-    auto server = std::make_shared<ServerSocket>(clientPoller);
+    auto server = std::make_shared<ServerSocket<T>>(clientPoller);
     if (!server->bind(addr))
     {
         const std::string msg = "Failed to bind. (errno: ";
@@ -394,7 +396,7 @@ int main(int, const char**)
     });
 
     // Start the server.
-    server(addrHttp, poller);
+    server<SimpleResponseClient>(addrHttp, poller);
 
     std::cout << "Shutting down server." << std::endl;
 
diff --git a/net/socket.hpp b/net/socket.hpp
index 8982380..fae37a2 100644
--- a/net/socket.hpp
+++ b/net/socket.hpp
@@ -383,7 +383,8 @@ protected:
     {
     }
 
-    friend class ServerSocket;
+    // Will construct us upon accept.
+    template<class T> friend class ServerSocket;
 };
 
 /// A SSL/TSL, non-blocking, data streaming socket.
@@ -432,7 +433,8 @@ protected:
         SSL_set_accept_state(_ssl);
     }
 
-    friend class ServerSocket;
+    // Will construct us upon accept.
+    template<class T> friend class ServerSocket;
 
 private:
     SSL* _ssl;


More information about the Libreoffice-commits mailing list