nghttp, nghttpd, h2load: Clear OpenSSL error queue and handle renegotiation

This commit is contained in:
Tatsuhiro Tsujikawa 2015-01-09 09:10:59 +09:00
parent 7add262721
commit 8f40bd4675
3 changed files with 32 additions and 14 deletions

View File

@ -471,6 +471,8 @@ int Http2Handler::write_clear() {
int Http2Handler::tls_handshake() { int Http2Handler::tls_handshake() {
ev_io_stop(sessions_->get_loop(), &wev_); ev_io_stop(sessions_->get_loop(), &wev_);
ERR_clear_error();
auto rv = SSL_do_handshake(ssl_); auto rv = SSL_do_handshake(ssl_);
if (rv == 0) { if (rv == 0) {
@ -511,6 +513,8 @@ int Http2Handler::tls_handshake() {
int Http2Handler::read_tls() { int Http2Handler::read_tls() {
uint8_t buf[8192]; uint8_t buf[8192];
ERR_clear_error();
for (;;) { for (;;) {
auto rv = SSL_read(ssl_, buf, sizeof(buf)); auto rv = SSL_read(ssl_, buf, sizeof(buf));
@ -524,8 +528,8 @@ int Http2Handler::read_tls() {
case SSL_ERROR_WANT_READ: case SSL_ERROR_WANT_READ:
goto fin; goto fin;
case SSL_ERROR_WANT_WRITE: case SSL_ERROR_WANT_WRITE:
ev_io_start(sessions_->get_loop(), &wev_); // renegotiation started
goto fin; return -1;
default: default:
return -1; return -1;
} }
@ -546,6 +550,9 @@ fin:
int Http2Handler::write_tls() { int Http2Handler::write_tls() {
auto loop = sessions_->get_loop(); auto loop = sessions_->get_loop();
ERR_clear_error();
for (;;) { for (;;) {
if (wb_.rleft() > 0) { if (wb_.rleft() > 0) {
const void *p; const void *p;
@ -562,8 +569,8 @@ int Http2Handler::write_tls() {
auto err = SSL_get_error(ssl_, rv); auto err = SSL_get_error(ssl_, rv);
switch (err) { switch (err) {
case SSL_ERROR_WANT_READ: case SSL_ERROR_WANT_READ:
ev_io_stop(loop, &wev_); // renegotiation started
return 0; return -1;
case SSL_ERROR_WANT_WRITE: case SSL_ERROR_WANT_WRITE:
ev_io_start(sessions_->get_loop(), &wev_); ev_io_start(sessions_->get_loop(), &wev_);
return 0; return 0;

View File

@ -567,6 +567,8 @@ int Client::connected() {
} }
int Client::tls_handshake() { int Client::tls_handshake() {
ERR_clear_error();
auto rv = SSL_do_handshake(ssl); auto rv = SSL_do_handshake(ssl);
if (rv == 0) { if (rv == 0) {
@ -601,6 +603,9 @@ int Client::tls_handshake() {
int Client::read_tls() { int Client::read_tls() {
uint8_t buf[8192]; uint8_t buf[8192];
ERR_clear_error();
for (;;) { for (;;) {
auto rv = SSL_read(ssl, buf, sizeof(buf)); auto rv = SSL_read(ssl, buf, sizeof(buf));
@ -614,8 +619,8 @@ int Client::read_tls() {
case SSL_ERROR_WANT_READ: case SSL_ERROR_WANT_READ:
return 0; return 0;
case SSL_ERROR_WANT_WRITE: case SSL_ERROR_WANT_WRITE:
ev_io_start(worker->loop, &wev); // renegotiation started
return 0; return -1;
default: default:
return -1; return -1;
} }
@ -628,6 +633,8 @@ int Client::read_tls() {
} }
int Client::write_tls() { int Client::write_tls() {
ERR_clear_error();
for (;;) { for (;;) {
if (wb.rleft() > 0) { if (wb.rleft() > 0) {
const void *p; const void *p;
@ -644,8 +651,8 @@ int Client::write_tls() {
auto err = SSL_get_error(ssl, rv); auto err = SSL_get_error(ssl, rv);
switch (err) { switch (err) {
case SSL_ERROR_WANT_READ: case SSL_ERROR_WANT_READ:
ev_io_stop(worker->loop, &wev); // renegotiation started
return 0; return -1;
case SSL_ERROR_WANT_WRITE: case SSL_ERROR_WANT_WRITE:
ev_io_start(worker->loop, &wev); ev_io_start(worker->loop, &wev);
return 0; return 0;

View File

@ -1123,6 +1123,8 @@ struct HttpClient {
int tls_handshake() { int tls_handshake() {
ev_timer_again(loop, &rt); ev_timer_again(loop, &rt);
ERR_clear_error();
auto rv = SSL_do_handshake(ssl); auto rv = SSL_do_handshake(ssl);
if (rv == 0) { if (rv == 0) {
@ -1161,6 +1163,8 @@ struct HttpClient {
int read_tls() { int read_tls() {
ev_timer_again(loop, &rt); ev_timer_again(loop, &rt);
ERR_clear_error();
uint8_t buf[8192]; uint8_t buf[8192];
for (;;) { for (;;) {
auto rv = SSL_read(ssl, buf, sizeof(buf)); auto rv = SSL_read(ssl, buf, sizeof(buf));
@ -1175,9 +1179,8 @@ struct HttpClient {
case SSL_ERROR_WANT_READ: case SSL_ERROR_WANT_READ:
return 0; return 0;
case SSL_ERROR_WANT_WRITE: case SSL_ERROR_WANT_WRITE:
ev_io_start(loop, &wev); // renegotiation started
ev_timer_again(loop, &wt); return -1;
return 0;
default: default:
return -1; return -1;
} }
@ -1192,6 +1195,8 @@ struct HttpClient {
int write_tls() { int write_tls() {
ev_timer_again(loop, &rt); ev_timer_again(loop, &rt);
ERR_clear_error();
for (;;) { for (;;) {
if (wb.rleft() > 0) { if (wb.rleft() > 0) {
const void *p; const void *p;
@ -1208,9 +1213,8 @@ struct HttpClient {
auto err = SSL_get_error(ssl, rv); auto err = SSL_get_error(ssl, rv);
switch (err) { switch (err) {
case SSL_ERROR_WANT_READ: case SSL_ERROR_WANT_READ:
ev_io_stop(loop, &wev); // renegotiation started
ev_timer_stop(loop, &wt); return -1;
return 0;
case SSL_ERROR_WANT_WRITE: case SSL_ERROR_WANT_WRITE:
ev_io_start(loop, &wev); ev_io_start(loop, &wev);
ev_timer_again(loop, &wt); ev_timer_again(loop, &wt);