# HG changeset patch # User Olaf Wintermann # Date 1455103196 -3600 # Node ID c3a0f1275d71fe1fe5cdad7212fcb39902895996 # Parent 57e706fed20aa831ce6bdb14742eca0531ad93b0 fixed keep alive bug diff -r 57e706fed20a -r c3a0f1275d71 src/server/daemon/httpparser.h --- a/src/server/daemon/httpparser.h Tue Feb 09 22:53:59 2016 +0100 +++ b/src/server/daemon/httpparser.h Wed Feb 10 12:19:56 2016 +0100 @@ -51,7 +51,7 @@ int state; sstr_t start_line; - /* local parser varaibles */ + /* local parser variables */ int wl; /* only white space */ int tk; /* token: 0: header name 1: header value */ int offset; /* offset of parsed string */ diff -r 57e706fed20a -r c3a0f1275d71 src/server/daemon/httprequest.c --- a/src/server/daemon/httprequest.c Tue Feb 09 22:53:59 2016 +0100 +++ b/src/server/daemon/httprequest.c Wed Feb 10 12:19:56 2016 +0100 @@ -59,7 +59,8 @@ } void http_request_cleanup(HTTPRequest *req) { - // TODO: implement + header_array_free(req->headers); + free(req); } sstr_t http_request_get_abspath(HTTPRequest *req) { @@ -344,7 +345,7 @@ // execute nsapi functions on a different thread pool nsapi_change_threadpool(sn, rq, lstp); } - + return 0; } @@ -493,10 +494,8 @@ * unref it */ } else { - close(sn->connection->fd); - free(sn->connection); + connection_destroy(sn->connection); cfg_unref(sn->config); - // TODO: create connection_close function } // free all memory @@ -504,7 +503,7 @@ free(sn->netbuf); pool_destroy(sn->sn.pool); - + return 0; } diff -r 57e706fed20a -r c3a0f1275d71 src/server/daemon/sessionhandler.c --- a/src/server/daemon/sessionhandler.c Tue Feb 09 22:53:59 2016 +0100 +++ b/src/server/daemon/sessionhandler.c Wed Feb 10 12:19:56 2016 +0100 @@ -70,6 +70,15 @@ close(conn->fd); } +void connection_destroy(Connection *conn) { + if(conn->ssl) { + SSL_free(conn->ssl); + } + conn->close(conn); + + free(conn); +} + SessionHandler* create_basic_session_handler() { BasicSessionHandler *handler = malloc(sizeof(BasicSessionHandler)); handler->threadpool = threadpool_new(4, 8); @@ -108,7 +117,7 @@ int state; int r; r = conn->read(conn, buf->inbuf + buf->pos, buf->maxsize - buf->pos); - if(r == -1) { + if(r <= 0) { // TODO: error handling fprintf(stderr, "%s\n", "Error: Cannot read from socket"); return NULL; @@ -225,7 +234,7 @@ conn, buf->inbuf + buf->pos, buf->maxsize - buf->pos); - if(r == -1) { + if(r <= 0) { event->finish = evt_request_error; return 0; } @@ -286,9 +295,7 @@ * * don't free request->netbuf and request->connection */ - header_array_free(request->headers); - free(request); - + http_request_cleanup(request); http_parser_free(parser); free(io); @@ -302,12 +309,13 @@ HttpParser *parser = io->parser; HTTPRequest *request = io->request; - close(request->connection->fd); - cfg_unref(request->connection->listener->cfg); + free(request->netbuf->inbuf); + free(request->netbuf); - header_array_free(request->headers); - free(request); + cfg_unref(request->connection->listener->cfg); + connection_destroy(request->connection); + http_request_cleanup(request); http_parser_free(parser); free(io); diff -r 57e706fed20a -r c3a0f1275d71 src/server/daemon/sessionhandler.h --- a/src/server/daemon/sessionhandler.h Tue Feb 09 22:53:59 2016 +0100 +++ b/src/server/daemon/sessionhandler.h Wed Feb 10 12:19:56 2016 +0100 @@ -108,6 +108,8 @@ int connection_ssl_write(Connection *conn, const void *buf, int len); void connection_ssl_close(Connection *conn); +void connection_destroy(Connection *conn); + SessionHandler* create_basic_session_handler(); diff -r 57e706fed20a -r c3a0f1275d71 src/server/util/util.c --- a/src/server/util/util.c Tue Feb 09 22:53:59 2016 +0100 +++ b/src/server/util/util.c Wed Feb 10 12:19:56 2016 +0100 @@ -475,18 +475,12 @@ sstr_t parent = sstr(path); sstr_t child = sstr(ch); sstr_t newstr; - sstr_t s; - if(parent.ptr[parent.length-1] == '/') { - s.length = 0; - } else { - s = S("/"); - } UcxAllocator a = util_pool_allocator(pool); - if(s.length == 1) { - newstr = sstrcat_a(&a, 3, parent, s, child); + if(parent.ptr[parent.length-1] == '/') { + newstr = sstrcat_a(&a, 2, parent, child); } else { - newstr = sstrcat_a(&a, 2, parent, child); + newstr = sstrcat_a(&a, 3, parent, S("/"), child); } return newstr;