Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 0 additions & 4 deletions include/bitcoin/network/net/proxy.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,6 @@ class BCT_API proxy
/// Stop socket, no delay, called by stop notify when iocontext is closing.
virtual void stop(const code& ec) NOEXCEPT;

/// Idempotent, may be called multiple times.
/// Same as stop but provides graceful shutdown for websocket connections.
virtual void async_stop(const code& ec) NOEXCEPT;

/// Subscribe to stop notification with completion handler.
/// Completion and event handlers are always invoked on the channel strand.
void subscribe_stop(result_handler&& handler,
Expand Down
6 changes: 3 additions & 3 deletions src/channels/channel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ channel::~channel() NOEXCEPT
// Start/stop/resume (started/paused upon create).
// ----------------------------------------------------------------------------

// This should not be called internally (invoked by stop() or async_stop()).
// This should not be called internally (invoked by stop()).
void channel::stopping(const code& ec) NOEXCEPT
{
BC_ASSERT(stranded());
Expand Down Expand Up @@ -163,7 +163,7 @@ void channel::handle_expiration(const code& ec) NOEXCEPT
return;
}

async_stop(error::channel_expired);
stop(error::channel_expired);
}

void channel::stop_inactivity() NOEXCEPT
Expand Down Expand Up @@ -202,7 +202,7 @@ void channel::handle_inactivity(const code& ec) NOEXCEPT
return;
}

async_stop(error::channel_inactive);
stop(error::channel_inactive);
}

// Properties.
Expand Down
44 changes: 23 additions & 21 deletions src/net/proxy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,26 +52,28 @@ void proxy::stop(const code& ec) NOEXCEPT
if (stopped())
return;

// Stop the read loop, stop accepting new work, cancel pending work.
socket_->stop();

// Overruled by stop, set only for consistency.
paused_.store(true);

boost::asio::post(strand(),
std::bind(&proxy::stopping, shared_from_this(), ec));
}

void proxy::async_stop(const code& ec) NOEXCEPT
{
if (stopped())
return;

// Stop the read loop, stop accepting new work, cancel pending work.
// Allows for graceful ws/ssl::close, which would hang the threadpool if
// attempted within socket::stop(), as it issues a follow-on iocontext job.
// A subsequent call to socket::stop() will terminate directly.
socket_->lazy_stop();
// Client or timer initated stop is async (graceful).
// error::channel_stopped is send in various contexts, however the only
// ones in which the channel is not stopped are those arising directly from
// socket read handlers, resulting in a stop(ec) call. This is interpreted
// as client socket cancellation, which along with timer cancellations are
// allowed to close gracefully. error::service_stopped will invoke socket
// stop() below, which will immediately terminate outstanding lazy_stop().
if (ec == error::channel_stopped ||
ec == error::channel_expired ||
ec == error::channel_inactive)
{
// Stop the read loop, stop accepting new work, cancel pending work.
// Allows for graceful ws/ssl::close, which would hang threadpool if
// attempted within socket::stop(), as it issues a follow-on iocontext
// job. A subsequent call to socket::stop() will terminate directly.
socket_->lazy_stop();
}
else
{
// Stop the read loop, stop accepting new work, cancel pending work.
socket_->stop();
}

// Overruled by stop, set only for consistency.
paused_.store(true);
Expand All @@ -81,7 +83,7 @@ void proxy::async_stop(const code& ec) NOEXCEPT
}

// protected
// This should not be called internally (invoked by stop() or async_stop()).
// This should not be called internally (invoked by stop()).
void proxy::stopping(const code& ec) NOEXCEPT
{
BC_ASSERT(stranded());
Expand Down
Loading