[TLS] better handling of SSL_ERROR_WANT_READ/WRITE

better handling of SSL_ERROR_WANT_READ and SSL_ERROR_WANT_WRITE
personal/stbuehler/mod-csrf-old
Glenn Strauss 2016-07-27 02:24:53 -04:00
parent 565dec2ff1
commit bce293e4a7
3 changed files with 15 additions and 1 deletions

View File

@ -133,8 +133,9 @@ static int connection_handle_read_ssl(server *srv, connection *con) {
if (len < 0) {
int oerrno = errno;
switch ((r = SSL_get_error(con->ssl, len))) {
case SSL_ERROR_WANT_READ:
case SSL_ERROR_WANT_WRITE:
con->is_writable = -1;
case SSL_ERROR_WANT_READ:
con->is_readable = 0;
/* the manual says we have to call SSL_read with the same arguments next time.

View File

@ -207,6 +207,7 @@ static void connection_handle_shutdown(server *srv, connection *con) {
case SSL_ERROR_ZERO_RETURN:
break;
case SSL_ERROR_WANT_WRITE:
/*con->is_writable = -1;*//*(no effect; shutdown() called below)*/
case SSL_ERROR_WANT_READ:
break;
case SSL_ERROR_SYSCALL:
@ -1400,6 +1401,14 @@ int connection_state_machine(server *srv, connection *con) {
}
if (-1 != con->fd) {
const int events = fdevent_event_get_interest(srv->ev, con->fd);
if (con->is_readable < 0) {
con->is_readable = 0;
r |= FDEVENT_IN;
}
if (con->is_writable < 0) {
con->is_writable = 0;
r |= FDEVENT_OUT;
}
if (r != events) {
/* update timestamps when enabling interest in events */
if ((r & FDEVENT_IN) && !(events & FDEVENT_IN)) {

View File

@ -125,7 +125,11 @@ int network_write_chunkqueue_openssl(server *srv, connection *con, SSL *ssl, chu
unsigned long err;
switch ((ssl_r = SSL_get_error(ssl, r))) {
case SSL_ERROR_WANT_READ:
con->is_readable = -1;
return 0; /* try again later */
case SSL_ERROR_WANT_WRITE:
con->is_writable = -1;
return 0; /* try again later */
case SSL_ERROR_SYSCALL:
/* perhaps we have error waiting in our error-queue */