From 61fe2923e4f3ae00efcde38212a9e4d7b447ea51 Mon Sep 17 00:00:00 2001 From: Jeff Becker Date: Thu, 28 Jul 2016 09:53:39 -0400 Subject: [PATCH] don't set socket option for closed sockets --- I2PTunnel.cpp | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/I2PTunnel.cpp b/I2PTunnel.cpp index aadc15b6..d680fee9 100644 --- a/I2PTunnel.cpp +++ b/I2PTunnel.cpp @@ -13,8 +13,11 @@ namespace client /** set standard socket options */ static void I2PTunnelSetSocketOptions(std::shared_ptr socket) { - boost::asio::socket_base::receive_buffer_size option(I2P_TUNNEL_CONNECTION_BUFFER_SIZE); - socket->set_option(option); + if (socket && socket->is_open()) + { + boost::asio::socket_base::receive_buffer_size option(I2P_TUNNEL_CONNECTION_BUFFER_SIZE); + socket->set_option(option); + } } I2PTunnelConnection::I2PTunnelConnection (I2PService * owner, std::shared_ptr socket, @@ -22,7 +25,6 @@ namespace client I2PServiceHandler(owner), m_Socket (socket), m_RemoteEndpoint (socket->remote_endpoint ()), m_IsQuiet (true) { - I2PTunnelSetSocketOptions(m_Socket); m_Stream = GetOwner()->GetLocalDestination ()->CreateStream (leaseSet, port); } @@ -31,7 +33,6 @@ namespace client I2PServiceHandler(owner), m_Socket (socket), m_Stream (stream), m_RemoteEndpoint (socket->remote_endpoint ()), m_IsQuiet (true) { - I2PTunnelSetSocketOptions(m_Socket); } I2PTunnelConnection::I2PTunnelConnection (I2PService * owner, std::shared_ptr stream, @@ -39,7 +40,6 @@ namespace client I2PServiceHandler(owner), m_Socket (socket), m_Stream (stream), m_RemoteEndpoint (target), m_IsQuiet (quiet) { - I2PTunnelSetSocketOptions(m_Socket); } I2PTunnelConnection::~I2PTunnelConnection () @@ -61,6 +61,7 @@ namespace client void I2PTunnelConnection::Connect () { + I2PTunnelSetSocketOptions(m_Socket); if (m_Socket) m_Socket->async_connect (m_RemoteEndpoint, std::bind (&I2PTunnelConnection::HandleConnect, shared_from_this (), std::placeholders::_1));