Skip to content

Commit

Permalink
This fix by Adam Langley fixes the SSL False-Start and 1/N-1 issues w…
Browse files Browse the repository at this point in the history
…ith SSL. Adam we are very grateful for your help.
  • Loading branch information
skinkie committed Jun 24, 2012
1 parent daa0698 commit cbe47e2
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 7 deletions.
26 changes: 19 additions & 7 deletions cherokee/cryptor_libssl.c
Expand Up @@ -574,6 +574,8 @@ socket_initialize (cherokee_cryptor_socket_libssl_t *cryp,
return ret_error; return ret_error;
} }


cryp->is_pending = false;

#ifndef OPENSSL_NO_TLSEXT #ifndef OPENSSL_NO_TLSEXT
SSL_set_app_data (cryp->session, conn); SSL_set_app_data (cryp->session, conn);
#else #else
Expand Down Expand Up @@ -882,11 +884,22 @@ _socket_read (cherokee_cryptor_socket_libssl_t *cryp,


CLEAR_LIBSSL_ERRORS; CLEAR_LIBSSL_ERRORS;


len = SSL_read (cryp->session, buf, buf_size); *pcnt_read = 0;
if (likely (len > 0)) {
*pcnt_read = len; while (buf_size > 0) {
if (SSL_pending (cryp->session)) len = SSL_read (cryp->session, buf, buf_size);
return ret_eagain; if (len < 1)
break;
*pcnt_read += len;
buf += len;
buf_size -= len;
}

/* We have more data than buffer space. Mark the socket as
* having pending data. */
cryp->is_pending = (buf_size == 0);

if (*pcnt_read > 0) {
return ret_ok; return ret_ok;
} }


Expand Down Expand Up @@ -927,8 +940,7 @@ _socket_read (cherokee_cryptor_socket_libssl_t *cryp,
static int static int
_socket_pending (cherokee_cryptor_socket_libssl_t *cryp) _socket_pending (cherokee_cryptor_socket_libssl_t *cryp)
{ {
SSL_read(cryp->session, NULL, 0); return cryp->is_pending;
return (SSL_pending (cryp->session) > 0);
} }


static ret_t static ret_t
Expand Down
1 change: 1 addition & 0 deletions cherokee/cryptor_libssl.h
Expand Up @@ -80,6 +80,7 @@ typedef struct {
cherokee_cryptor_socket_t base; cherokee_cryptor_socket_t base;
SSL *session; SSL *session;
SSL_CTX *ssl_ctx; SSL_CTX *ssl_ctx;
cherokee_boolean_t is_pending;
struct { struct {
char *buf; char *buf;
off_t buf_len; off_t buf_len;
Expand Down
11 changes: 11 additions & 0 deletions cherokee/thread.c
Expand Up @@ -1479,6 +1479,17 @@ process_active_connections (cherokee_thread_t *thd)


} /* list */ } /* list */


list_for_each_safe (i, tmp, LIST(&thd->active_list)) {
conn = CONN(i);

/* Check whether we have data sitting in SSL buffers that needs
* to be processed before we wait for file descriptors. */
if (conn->socket.cryptor &&
cherokee_cryptor_socket_pending(conn->socket.cryptor)) {
thd->pending_read_num++;
}
} /* list */

return ret_ok; return ret_ok;
} }


Expand Down

0 comments on commit cbe47e2

Please sign in to comment.