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
6 changes: 4 additions & 2 deletions src/net/proxy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,10 @@ void proxy::stop(const code& ec) NOEXCEPT
{
if (stopped())
{
// Ends an outstanding lazy stop, otherwise nothing.
socket_->stop();
// Hard stop ends outstanding lazy stop, otherwise nothing.
if (!lazy(ec))
socket_->stop();

return;
}

Expand Down
45 changes: 45 additions & 0 deletions test/net/proxy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,41 @@ class mock_zmtp_socket
}
};

class mock_stop_socket
: public network::socket
{
public:
using socket::socket;

void stop() NOEXCEPT override
{
++stops;
socket::stop();
}

size_t stops{};
};

// Obtain the count of hard socket stops for proxy stops with the codes.
static size_t get_stops(const code& first, const code& second) NOEXCEPT
{
const logger log{};
threadpool pool(1);
socket::parameters params
{
.maximum_request = 42,
.maximum_buffer = settings::tcp_server{ "test" }.maximum_buffer
};
auto socket_ptr = std::make_shared<mock_stop_socket>(log, pool.service(),
std::move(params));
auto proxy_ptr = std::make_shared<mock_proxy>(socket_ptr);

proxy_ptr->stop(first);
proxy_ptr->stop(second);
pool.stop();
return socket_ptr->stops;
}

// Obtain the deferral for a send of bytes that started at the given offset.
static milliseconds get_unconsumed(uint32_t rate_limit, size_t bytes,
const steady_clock::duration& elapsed) NOEXCEPT
Expand Down Expand Up @@ -1087,6 +1122,16 @@ BC_FIXTURE_TEST_CASE(proxy__stop__channel_expired__client_unread_bytes__client_e
BC_REQUIRE(ec == error::peer_disconnect);
}

BC_AUTO_TEST_CASE(proxy__stop__lazy_then_lazy__lazy_stop_retained)
{
BC_REQUIRE_EQUAL(get_stops(error::channel_expired, error::channel_expired), 0u);
}

BC_AUTO_TEST_CASE(proxy__stop__lazy_then_hard__hard_stop)
{
BC_REQUIRE_EQUAL(get_stops(error::channel_expired, error::service_stopped), 1u);
}

BC_FIXTURE_TEST_CASE(proxy__lazy__service_stopped__false, loopback_fixture)
{
BC_REQUIRE(!channel->lazy(error::service_stopped));
Expand Down
Loading