Call ERR_clear_error() before SSL I/O functions.

This commit is contained in:
Tatsuhiro Tsujikawa 2012-05-07 23:22:40 +09:00
parent 7972bd79b9
commit c009b1e65c
3 changed files with 9 additions and 0 deletions

View File

@ -243,6 +243,7 @@ bool SpdyEventHandler::finish()
ssize_t SpdyEventHandler::send_data(const uint8_t *data, size_t len, int flags) ssize_t SpdyEventHandler::send_data(const uint8_t *data, size_t len, int flags)
{ {
ssize_t r; ssize_t r;
ERR_clear_error();
r = SSL_write(ssl_, data, len); r = SSL_write(ssl_, data, len);
return r; return r;
} }
@ -251,6 +252,7 @@ ssize_t SpdyEventHandler::recv_data(uint8_t *data, size_t len, int flags)
{ {
ssize_t r; ssize_t r;
want_write_ = false; want_write_ = false;
ERR_clear_error();
r = SSL_read(ssl_, data, len); r = SSL_read(ssl_, data, len);
if(r < 0) { if(r < 0) {
if(SSL_get_error(ssl_, r) == SSL_ERROR_WANT_WRITE) { if(SSL_get_error(ssl_, r) == SSL_ERROR_WANT_WRITE) {
@ -663,6 +665,7 @@ public:
virtual int execute(Sessions *sessions) virtual int execute(Sessions *sessions)
{ {
want_read_ = want_write_ = false; want_read_ = want_write_ = false;
ERR_clear_error();
int r = SSL_accept(ssl_); int r = SSL_accept(ssl_);
if(r == 1) { if(r == 1) {
finish_ = true; finish_ = true;

View File

@ -170,6 +170,7 @@ static ssize_t send_callback(spdylay_session *session,
ssize_t rv; ssize_t rv;
connection = (struct Connection*)user_data; connection = (struct Connection*)user_data;
connection->want_io = IO_NONE; connection->want_io = IO_NONE;
ERR_clear_error();
rv = SSL_write(connection->ssl, data, length); rv = SSL_write(connection->ssl, data, length);
if(rv < 0) { if(rv < 0) {
int err = SSL_get_error(connection->ssl, rv); int err = SSL_get_error(connection->ssl, rv);
@ -198,6 +199,7 @@ static ssize_t recv_callback(spdylay_session *session,
ssize_t rv; ssize_t rv;
connection = (struct Connection*)user_data; connection = (struct Connection*)user_data;
connection->want_io = IO_NONE; connection->want_io = IO_NONE;
ERR_clear_error();
rv = SSL_read(connection->ssl, buf, length); rv = SSL_read(connection->ssl, buf, length);
if(rv < 0) { if(rv < 0) {
int err = SSL_get_error(connection->ssl, rv); int err = SSL_get_error(connection->ssl, rv);
@ -418,6 +420,7 @@ static void ssl_handshake(SSL *ssl, int fd)
if(SSL_set_fd(ssl, fd) == 0) { if(SSL_set_fd(ssl, fd) == 0) {
dief("SSL_set_fd", ERR_error_string(ERR_get_error(), NULL)); dief("SSL_set_fd", ERR_error_string(ERR_get_error(), NULL));
} }
ERR_clear_error();
rv = SSL_connect(ssl); rv = SSL_connect(ssl);
if(rv <= 0) { if(rv <= 0) {
dief("SSL_connect", ERR_error_string(ERR_get_error(), NULL)); dief("SSL_connect", ERR_error_string(ERR_get_error(), NULL));

View File

@ -74,6 +74,7 @@ int Spdylay::send()
ssize_t Spdylay::send_data(const uint8_t *data, size_t len, int flags) ssize_t Spdylay::send_data(const uint8_t *data, size_t len, int flags)
{ {
ssize_t r; ssize_t r;
ERR_clear_error();
r = SSL_write(ssl_, data, len); r = SSL_write(ssl_, data, len);
return r; return r;
} }
@ -82,6 +83,7 @@ ssize_t Spdylay::recv_data(uint8_t *data, size_t len, int flags)
{ {
ssize_t r; ssize_t r;
want_write_ = false; want_write_ = false;
ERR_clear_error();
r = SSL_read(ssl_, data, len); r = SSL_read(ssl_, data, len);
if(r < 0) { if(r < 0) {
if(SSL_get_error(ssl_, r) == SSL_ERROR_WANT_WRITE) { if(SSL_get_error(ssl_, r) == SSL_ERROR_WANT_WRITE) {
@ -502,6 +504,7 @@ int ssl_handshake(SSL *ssl, int fd)
std::cerr << ERR_error_string(ERR_get_error(), 0) << std::endl; std::cerr << ERR_error_string(ERR_get_error(), 0) << std::endl;
return -1; return -1;
} }
ERR_clear_error();
int r = SSL_connect(ssl); int r = SSL_connect(ssl);
if(r <= 0) { if(r <= 0) {
std::cerr << ERR_error_string(ERR_get_error(), 0) << std::endl; std::cerr << ERR_error_string(ERR_get_error(), 0) << std::endl;