handle unlikely error when ssl-handshake could not be started
This commit is contained in:
parent
06dc23190d
commit
34f84e1ab7
|
|
@ -189,26 +189,28 @@ public:
|
||||||
*/
|
*/
|
||||||
TcpState *proceed(const Monitor &monitor)
|
TcpState *proceed(const Monitor &monitor)
|
||||||
{
|
{
|
||||||
// do we have a valid socket?
|
// prevent exceptions
|
||||||
if (_socket >= 0)
|
try
|
||||||
{
|
{
|
||||||
|
// socket should be connected by now
|
||||||
|
if (_socket < 0) throw std::runtime_error(_error.data());
|
||||||
|
|
||||||
// report that the network-layer is connected
|
// report that the network-layer is connected
|
||||||
_parent->onConnected(this);
|
_parent->onConnected(this);
|
||||||
|
|
||||||
// handler callback might have destroyed connection
|
// handler callback might have destroyed connection
|
||||||
if (!monitor.valid()) return nullptr;
|
if (!monitor.valid()) return nullptr;
|
||||||
|
|
||||||
// if we need a secure connection, we move to the tls handshake
|
// if we need a secure connection, we move to the tls handshake (this could throw)
|
||||||
// @todo catch possible exception
|
if (_secure) return new SslHandshake(this, std::move(_hostname), std::move(_buffer));
|
||||||
if (_secure) return new SslHandshake(this, _hostname, std::move(_buffer));
|
|
||||||
|
|
||||||
// otherwise we have a valid regular tcp connection
|
// otherwise we have a valid regular tcp connection
|
||||||
return new TcpConnected(this, std::move(_buffer));
|
else return new TcpConnected(this, std::move(_buffer));
|
||||||
}
|
}
|
||||||
else
|
catch (const std::runtime_error &error)
|
||||||
{
|
{
|
||||||
// report error
|
// report error
|
||||||
_parent->onError(this, _error.data(), false);
|
_parent->onError(this, error.what(), false);
|
||||||
|
|
||||||
// handler callback might have destroyed connection
|
// handler callback might have destroyed connection
|
||||||
if (!monitor.valid()) return nullptr;
|
if (!monitor.valid()) return nullptr;
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue