void TlsStream::OnEvent(int revents)
{
- int rc, err;
+ int rc;
size_t count;
boost::mutex::scoped_lock lock(m_Mutex);
}
}
+ bool success = false;
+
switch (m_CurrentAction) {
case TlsActionRead:
do {
if (rc > 0) {
m_RecvQ->Write(buffer, rc);
- m_CV.notify_all();
+ success = true;
}
- } while (SSL_pending(m_SSL.get()));
+ } while (rc > 0);
+
+ if (success)
+ m_CV.notify_all();
break;
case TlsActionWrite:
rc = SSL_write(m_SSL.get(), buffer, count);
- if (rc > 0)
+ if (rc > 0) {
m_SendQ->Read(NULL, rc, true);
+ success = true;
+ }
break;
case TlsActionHandshake:
rc = SSL_do_handshake(m_SSL.get());
if (rc > 0) {
+ success = true;
m_HandshakeOK = true;
m_CV.notify_all();
}
VERIFY(!"Invalid TlsAction");
}
- if (rc > 0) {
+ if (rc < 0) {
+ int err = SSL_get_error(m_SSL.get(), rc);
+
+ switch (err) {
+ case SSL_ERROR_WANT_READ:
+ m_Retry = true;
+ ChangeEvents(POLLIN);
+
+ break;
+ case SSL_ERROR_WANT_WRITE:
+ m_Retry = true;
+ ChangeEvents(POLLOUT);
+
+ break;
+ case SSL_ERROR_ZERO_RETURN:
+ lock.unlock();
+
+ Close();
+
+ break;
+ default:
+ m_ErrorCode = ERR_peek_error();
+ m_ErrorOccurred = true;
+
+ if (m_ErrorCode != 0) {
+ Log(LogWarning, "TlsStream")
+ << "OpenSSL error: " << ERR_error_string(m_ErrorCode, NULL);
+ } else {
+ Log(LogWarning, "TlsStream", "TLS stream was disconnected.");
+ }
+
+ lock.unlock();
+
+ Close();
+
+ break;
+ }
+ }
+
+ if (success) {
m_CurrentAction = TlsActionNone;
if (!m_Eof) {
if (m_Shutdown && !m_SendQ->IsDataAvailable())
Close();
-
- return;
}
- err = SSL_get_error(m_SSL.get(), rc);
-
- switch (err) {
- case SSL_ERROR_WANT_READ:
- m_Retry = true;
- ChangeEvents(POLLIN);
-
- break;
- case SSL_ERROR_WANT_WRITE:
- m_Retry = true;
- ChangeEvents(POLLOUT);
-
- break;
- case SSL_ERROR_ZERO_RETURN:
- lock.unlock();
-
- Close();
-
- break;
- default:
- m_ErrorCode = ERR_peek_error();
- m_ErrorOccurred = true;
-
- if (m_ErrorCode != 0) {
- Log(LogWarning, "TlsStream")
- << "OpenSSL error: " << ERR_error_string(m_ErrorCode, NULL);
- } else {
- Log(LogWarning, "TlsStream", "TLS stream was disconnected.");
- }
-
- lock.unlock();
-
- Close();
-
- break;
- }
}
void TlsStream::HandleError(void) const