return IsDataAvailable() || IsEof();
}
+void Stream::Close(void)
+{
+ OnDataAvailable.disconnect_all_slots();
+}
+
StreamReadStatus Stream::ReadLine(String *line, StreamReadContext& context, bool may_wait)
{
if (context.Eof)
/**
* Closes the stream and releases resources.
*/
- virtual void Close(void) = 0;
+ virtual void Close(void);
/**
* Checks whether we've reached the end-of-file condition.
TlsStream::~TlsStream(void)
{
- SocketEvents::Unregister();
+ Close();
}
int TlsStream::ValidateCertificate(int preverify_ok, X509_STORE_CTX *ctx)
break;
case SSL_ERROR_ZERO_RETURN:
- SocketEvents::Unregister();
-
- m_SSL.reset();
- m_Socket->Close();
- m_Socket.reset();
+ lock.unlock();
- m_Eof = true;
+ if (IsHandlingEvents())
+ SignalDataAvailable();
- m_CV.notify_all();
+ Close();
break;
default:
- SocketEvents::Unregister();
-
- m_SSL.reset();
- m_Socket->Close();
- m_Socket.reset();
-
- m_Eof = true;
-
m_ErrorCode = ERR_peek_error();
m_ErrorOccurred = true;
- Log(LogWarning, "TlsStream")
- << "OpenSSL error: " << ERR_error_string(m_ErrorCode, NULL);
+ 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();
+
+ if (IsHandlingEvents())
+ SignalDataAvailable();
- m_CV.notify_all();
+ Close();
break;
}
*/
void TlsStream::Close(void)
{
+ Stream::Close();
+
SocketEvents::Unregister();
boost::mutex::scoped_lock lock(m_Mutex);
if (!m_SSL)
return;
- (void) SSL_shutdown(m_SSL.get());
+ (void)SSL_shutdown(m_SSL.get());
m_SSL.reset();
m_Socket->Close();
m_Socket.reset();
+
+ m_CV.notify_all();
}
bool TlsStream::IsEof(void) const