From c009b1e65cbfecc4c93dac8828eee8251d804ee2 Mon Sep 17 00:00:00 2001 From: Tatsuhiro Tsujikawa Date: Mon, 7 May 2012 23:22:40 +0900 Subject: [PATCH] Call ERR_clear_error() before SSL I/O functions. --- examples/SpdyServer.cc | 3 +++ examples/spdycli.c | 3 +++ examples/spdylay_ssl.cc | 3 +++ 3 files changed, 9 insertions(+) diff --git a/examples/SpdyServer.cc b/examples/SpdyServer.cc index 3ce11bd7..945dd2ec 100644 --- a/examples/SpdyServer.cc +++ b/examples/SpdyServer.cc @@ -243,6 +243,7 @@ bool SpdyEventHandler::finish() ssize_t SpdyEventHandler::send_data(const uint8_t *data, size_t len, int flags) { ssize_t r; + ERR_clear_error(); r = SSL_write(ssl_, data, len); return r; } @@ -251,6 +252,7 @@ ssize_t SpdyEventHandler::recv_data(uint8_t *data, size_t len, int flags) { ssize_t r; want_write_ = false; + ERR_clear_error(); r = SSL_read(ssl_, data, len); if(r < 0) { if(SSL_get_error(ssl_, r) == SSL_ERROR_WANT_WRITE) { @@ -663,6 +665,7 @@ public: virtual int execute(Sessions *sessions) { want_read_ = want_write_ = false; + ERR_clear_error(); int r = SSL_accept(ssl_); if(r == 1) { finish_ = true; diff --git a/examples/spdycli.c b/examples/spdycli.c index b70b6a82..f24dc098 100644 --- a/examples/spdycli.c +++ b/examples/spdycli.c @@ -170,6 +170,7 @@ static ssize_t send_callback(spdylay_session *session, ssize_t rv; connection = (struct Connection*)user_data; connection->want_io = IO_NONE; + ERR_clear_error(); rv = SSL_write(connection->ssl, data, length); if(rv < 0) { int err = SSL_get_error(connection->ssl, rv); @@ -198,6 +199,7 @@ static ssize_t recv_callback(spdylay_session *session, ssize_t rv; connection = (struct Connection*)user_data; connection->want_io = IO_NONE; + ERR_clear_error(); rv = SSL_read(connection->ssl, buf, length); if(rv < 0) { 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) { dief("SSL_set_fd", ERR_error_string(ERR_get_error(), NULL)); } + ERR_clear_error(); rv = SSL_connect(ssl); if(rv <= 0) { dief("SSL_connect", ERR_error_string(ERR_get_error(), NULL)); diff --git a/examples/spdylay_ssl.cc b/examples/spdylay_ssl.cc index 105e778c..33c045a5 100644 --- a/examples/spdylay_ssl.cc +++ b/examples/spdylay_ssl.cc @@ -74,6 +74,7 @@ int Spdylay::send() ssize_t Spdylay::send_data(const uint8_t *data, size_t len, int flags) { ssize_t r; + ERR_clear_error(); r = SSL_write(ssl_, data, len); return r; } @@ -82,6 +83,7 @@ ssize_t Spdylay::recv_data(uint8_t *data, size_t len, int flags) { ssize_t r; want_write_ = false; + ERR_clear_error(); r = SSL_read(ssl_, data, len); if(r < 0) { 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; return -1; } + ERR_clear_error(); int r = SSL_connect(ssl); if(r <= 0) { std::cerr << ERR_error_string(ERR_get_error(), 0) << std::endl;