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

View File

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

View File

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