Properly deal with closed TLS streams

fixes #6892
This commit is contained in:
Gunnar Beutner 2014-09-09 15:28:55 +02:00
parent 9a06b09366
commit 092983d5ad
2 changed files with 16 additions and 2 deletions

View File

@ -43,7 +43,7 @@ String I2_BASE_API SHA256(const String& s);
class I2_BASE_API openssl_error : virtual public std::exception, virtual public boost::exception { };
struct errinfo_openssl_error_;
typedef boost::error_info<struct errinfo_openssl_error_, int> errinfo_openssl_error;
typedef boost::error_info<struct errinfo_openssl_error_, unsigned long> errinfo_openssl_error;
inline std::string to_string(const errinfo_openssl_error& e)
{

View File

@ -116,7 +116,21 @@ void ApiClient::DisconnectSync(void)
bool ApiClient::ProcessMessage(void)
{
Dictionary::Ptr message = JsonRpc::ReadMessage(m_Stream);
Dictionary::Ptr message;
if (m_Stream->IsEof())
return false;
try {
message = JsonRpc::ReadMessage(m_Stream);
} catch (const openssl_error& ex) {
const unsigned long *pe = boost::get_error_info<errinfo_openssl_error>(ex);
if (pe && *pe == 0)
return false; /* Connection was closed cleanly */
throw;
}
if (!message)
return false;