moves IOStream creation to the sessionhandler aio

Sat, 13 Jan 2018 16:44:05 +0100

author
Olaf Wintermann <olaf.wintermann@gmail.com>
date
Sat, 13 Jan 2018 16:44:05 +0100
branch
aio
changeset 191
391ccd490d97
parent 190
1f73302461e0
child 192
6a145e13d933

moves IOStream creation to the sessionhandler

src/server/daemon/httplistener.c file | annotate | diff | comparison | revisions
src/server/daemon/httprequest.c file | annotate | diff | comparison | revisions
src/server/daemon/sessionhandler.c file | annotate | diff | comparison | revisions
src/server/daemon/sessionhandler.h file | annotate | diff | comparison | revisions
--- a/src/server/daemon/httplistener.c	Fri Jan 12 18:36:47 2018 +0100
+++ b/src/server/daemon/httplistener.c	Sat Jan 13 16:44:05 2018 +0100
@@ -402,7 +402,7 @@
         conn->fd = clientfd;
         conn->listener = ls;
         if(ls->ssl) {
-            // SSL connections are always non-blocking
+            // SSL connections are always non-blocking 
             // set socket non blocking
             int flags;
             if((flags = fcntl(conn->fd, F_GETFL, 0)) == -1) {
--- a/src/server/daemon/httprequest.c	Fri Jan 12 18:36:47 2018 +0100
+++ b/src/server/daemon/httprequest.c	Sat Jan 13 16:44:05 2018 +0100
@@ -112,17 +112,11 @@
     sn->connection = request->connection;
     sn->netbuf = request->netbuf;
     sn->sn.pool = pool;
-    //sn->sn.csd = stream_new_from_fd(pool, request->connection->fd);
-    //sn->sn.csd = net_stream_from_fd(pool, request->connection->fd);
-    IOStream *io;
-    if(request->connection->ssl) {
-        io = sslstream_new(pool, request->connection->ssl);
-        sn->sn.ssl = 1;
-    } else {
-        io = sysstream_new(pool, request->connection->fd);
-    }
+    SessionHandler *sh = request->connection->session_handler;
+    WSBool ssl;
+    IOStream *io = sh->create_iostream(sh, request->connection, pool, &ssl);
     sn->sn.csd = httpstream_new(pool, io);
-    
+    sn->sn.ssl = ssl;
     
     sn->sn.client = pblock_create_pool(sn->sn.pool, 8);
     sn->sn.next = NULL;
--- a/src/server/daemon/sessionhandler.c	Fri Jan 12 18:36:47 2018 +0100
+++ b/src/server/daemon/sessionhandler.c	Sat Jan 13 16:44:05 2018 +0100
@@ -93,11 +93,25 @@
     free(conn);    
 }
 
+IOStream* create_connection_iostream(SessionHandler *sh, Connection *conn, pool_handle_t *pool, WSBool *ssl) {
+    IOStream *io = NULL;
+    if(conn->ssl) {
+        io = sslstream_new(pool, conn->ssl);
+        *ssl = 1;
+    } else {
+        io = sysstream_new(pool, conn->fd);
+        *ssl = 0;
+    }
+    return io;
+}
+
+
 SessionHandler* create_basic_session_handler() {
     BasicSessionHandler *handler = malloc(sizeof(BasicSessionHandler));
     handler->threadpool = threadpool_new(4, 8);
     handler->sh.enqueue_connection = basic_enq_conn;
     handler->sh.keep_alive = basic_keep_alive;
+    handler->sh.create_iostream = create_connection_iostream;
 
     return (SessionHandler*)handler;
 }
@@ -172,6 +186,7 @@
     handler->eventhandler = get_default_event_handler();
     handler->sh.enqueue_connection = evt_enq_conn;
     handler->sh.keep_alive = evt_keep_alive;
+    handler->sh.create_iostream = create_connection_iostream;
     return (SessionHandler*)handler;
 }
 
--- a/src/server/daemon/sessionhandler.h	Fri Jan 12 18:36:47 2018 +0100
+++ b/src/server/daemon/sessionhandler.h	Sat Jan 13 16:44:05 2018 +0100
@@ -31,6 +31,7 @@
 
 #include "../util/thrpool.h"
 #include "../public/nsapi.h"
+#include "../util/io.h"
 #include "event.h"
 
 #include <openssl/bio.h> 
@@ -72,6 +73,11 @@
      * available
      */
     void(*keep_alive)(SessionHandler*, Connection *conn);
+    
+    /*
+     * Creates an IOStream object for the connection
+     */
+    IOStream*(*create_iostream)(SessionHandler *sh, Connection *conn, pool_handle_t *pool, WSBool *ssl);
 };
 
 /*
@@ -111,6 +117,12 @@
 
 void connection_destroy(Connection *conn);
 
+/*
+ * generic create_iostream function for BasicSessionHandler
+ * and EventSessionHandler
+ */
+IOStream* create_connection_iostream(SessionHandler *sh, Connection *conn, pool_handle_t *pool, WSBool *ssl);
+
 
 SessionHandler* create_basic_session_handler();
 

mercurial