diff -r f33974f0dce0 -r aa8393527b1e src/server/daemon/httplistener.c --- a/src/server/daemon/httplistener.c Thu Aug 31 16:29:49 2017 +0200 +++ b/src/server/daemon/httplistener.c Sat Jan 13 19:01:00 2018 +0100 @@ -403,33 +403,24 @@ conn->fd = clientfd; conn->listener = ls; if(ls->ssl) { + // SSL connections are always non-blocking + // set socket non blocking + int flags; + if((flags = fcntl(conn->fd, F_GETFL, 0)) == -1) { + flags = 0; + } + if(fcntl(conn->fd, F_SETFL, flags | O_NONBLOCK)) { + perror("Error: acceptor_thread: fcntl"); + // TODO: error + } + SSL *ssl = SSL_new(ls->ssl->sslctx); SSL_set_fd(ssl, clientfd); - int ssl_ar = SSL_accept(ssl); - if(ssl_ar <= 0) { - int error = SSL_get_error(ssl, ssl_ar); - char *errstr; - switch(error) { - default: errstr = "unknown"; break; - case SSL_ERROR_ZERO_RETURN: errstr = "SSL_ERROR_ZERO_RETURN"; break; - case SSL_ERROR_WANT_READ: errstr = "SSL_ERROR_WANT_READ"; break; - case SSL_ERROR_WANT_WRITE: errstr = "SSL_ERROR_WANT_WRITE"; break; - case SSL_ERROR_WANT_CONNECT: errstr = "SSL_ERROR_WANT_CONNECT"; break; - case SSL_ERROR_WANT_ACCEPT: errstr = "SSL_ERROR_WANT_ACCEPT"; break; - case SSL_ERROR_WANT_X509_LOOKUP: errstr = "SSL_ERROR_WANT_X509_LOOKUP"; break; - case SSL_ERROR_SYSCALL: errstr = "SSL_ERROR_SYSCALL"; break; - case SSL_ERROR_SSL: errstr = "SSL_ERROR_SSL"; break; - } - log_ereport(LOG_VERBOSE, "SSL accept error[%d]: %s", error, errstr); - free(conn); - conn = NULL; - system_close(clientfd); - } else { - conn->ssl = ssl; - conn->read = connection_ssl_read; - conn->write = connection_ssl_write; - conn->close = connection_ssl_close; - } + + conn->ssl = ssl; + conn->read = connection_ssl_read; + conn->write = connection_ssl_write; + conn->close = connection_ssl_close; } else { conn->ssl = NULL; conn->read = connection_read;