src/server/daemon/sessionhandler.c

changeset 133
87b405d61f64
parent 129
fd324464f56f
child 135
471e28cca288
--- a/src/server/daemon/sessionhandler.c	Tue Dec 27 14:02:28 2016 +0100
+++ b/src/server/daemon/sessionhandler.c	Tue Dec 27 17:19:00 2016 +0100
@@ -60,7 +60,7 @@
 int connection_ssl_read(Connection *conn, void *buf, int len) {
     int ret = SSL_read(conn->ssl, buf, len);
     if(ret <= 0) {
-        conn->ssl_error = ERR_get_error();
+        conn->ssl_error = SSL_get_error(conn->ssl, ret);
     }
     return ret;
 }
@@ -68,13 +68,17 @@
 int connection_ssl_write(Connection *conn, const void *buf, int len) {
     int ret = SSL_write(conn->ssl, buf, len);
     if(ret <= 0) {
-        conn->ssl_error = ERR_get_error();
+        conn->ssl_error = SSL_get_error(conn->ssl, ret);
     }
     return ret;
 }
 
 void connection_ssl_close(Connection *conn) {
-    SSL_shutdown(conn->ssl);
+    int ret = SSL_shutdown(conn->ssl);
+    if(ret != 1) {
+        conn->ssl_error = SSL_get_error(conn->ssl, ret);
+        log_ereport(LOG_VERBOSE, "SSL_shutdown failed: %d", conn->ssl_error);
+    }
     close(conn->fd);
 }
 
@@ -222,8 +226,8 @@
     
     if(ev_pollin(ev, conn->fd, event) != 0) {
         // TODO: ev_pollin should log, intercept some errors here
-        log_ereport(LOG_WARN, "ev_pollin failed: %s", strerror(errno));
-        close(conn->fd);
+        log_ereport(LOG_FAILURE, "Cannot enqueue connection");
+        connection_destroy(conn);
         // TODO: free stuff
     }
 }
@@ -242,6 +246,20 @@
             buf->inbuf + buf->pos,
             buf->maxsize - buf->pos);
     if(r <= 0) {
+        if(conn->ssl) {
+            // SSL specific error handling
+            switch(conn->ssl_error) {
+                case SSL_ERROR_WANT_READ: {
+                    event->poll = EVENT_POLLIN;
+                    return 1;
+                }
+                case SSL_ERROR_WANT_WRITE: {
+                    event->poll = EVENT_POLLOUT;
+                    return 1;
+                }
+            }
+        }
+        
         event->finish = evt_request_error;
         return 0;
     }
@@ -260,6 +278,7 @@
          * we need more data -> return 1 to tell the event handler to
          * continue polling
          */
+        event->poll = EVENT_POLLIN;
         return 1;
     }
     

mercurial