src/server/daemon/sessionhandler.c

changeset 106
b122f34ddc80
parent 79
f48cea237ec3
child 114
c3a0f1275d71
--- a/src/server/daemon/sessionhandler.c	Wed Oct 28 17:59:34 2015 +0100
+++ b/src/server/daemon/sessionhandler.c	Sat Oct 31 15:01:07 2015 +0100
@@ -44,11 +44,37 @@
     HttpParser  *parser;
 } EventHttpIO;
 
+
+int connection_read(Connection *conn, void *buf, int len) {
+    return (int)read(conn->fd, buf, len);
+}
+
+int connection_write(Connection *conn, const void *buf, int len) {
+    return (int)write(conn->fd, buf, len);
+}
+
+void connection_close(Connection *conn) {
+    close(conn->fd);
+}
+
+int connection_ssl_read(Connection *conn, void *buf, int len) {
+    return SSL_read(conn->ssl, buf, len);
+}
+
+int connection_ssl_write(Connection *conn, const void *buf, int len) {
+    return SSL_write(conn->ssl, buf, len);
+}
+
+void connection_ssl_close(Connection *conn) {
+    SSL_shutdown(conn->ssl);
+    close(conn->fd);
+}
+
 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;
 
     return (SessionHandler*)handler;
 }
@@ -81,7 +107,7 @@
     HttpParser *parser = http_parser_new(&request);
     int state;
     int r;
-    r = read(conn->fd, buf->inbuf + buf->pos, buf->maxsize - buf->pos);
+    r = conn->read(conn, buf->inbuf + buf->pos, buf->maxsize - buf->pos);
     if(r == -1) {
          // TODO: error handling
         fprintf(stderr, "%s\n", "Error: Cannot read from socket");
@@ -94,7 +120,7 @@
             fprintf(stderr, "%s\n", "Error: Cannot parse http request");
             return NULL;
         }
-        r = read(conn->fd, buf->inbuf + buf->pos, buf->maxsize - buf->pos);
+        r = conn->read(conn, buf->inbuf + buf->pos, buf->maxsize - buf->pos);
         if(r == -1) {
             // TODO: error handling
             fprintf(stderr, "%s\n", "Error: Cannot read from socket");
@@ -102,7 +128,7 @@
         }
         buf->cursize += r;
     }
-
+    
     // process request
     r = handle_request(&request, NULL); // TODO: use correct thread pool
     
@@ -190,12 +216,13 @@
     EventHttpIO *io = event->cookie;
     HttpParser  *parser  = io->parser;
     HTTPRequest *request = io->request;
+    Connection  *conn = io->request->connection;
     netbuf      *buf     = request->netbuf;
     
     int state;
     int r;
-    r = read(
-            request->connection->fd,
+    r = conn->read(
+            conn,
             buf->inbuf + buf->pos,
             buf->maxsize - buf->pos);
     if(r == -1) {

mercurial