Configurable socket queue size
This commit is contained in:
parent
ca96ce3319
commit
e3a2afd0f7
3 changed files with 13 additions and 10 deletions
|
|
@ -171,10 +171,10 @@ TEST (socket, drop_policy)
|
|||
|
||||
// We're going to write twice the queue size + 1, and the server isn't reading
|
||||
// The total number of drops should thus be 1 (the socket allows doubling the queue size for no_socket_drop)
|
||||
func (nano::transport::tcp_socket::queue_size * 2 + 1);
|
||||
func (nano::transport::tcp_socket::default_queue_size * 2 + 1);
|
||||
ASSERT_EQ (1, failed_writes);
|
||||
|
||||
func (nano::transport::tcp_socket::queue_size + 1);
|
||||
func (nano::transport::tcp_socket::default_queue_size + 1);
|
||||
ASSERT_EQ (0, failed_writes);
|
||||
}
|
||||
|
||||
|
|
@ -398,7 +398,7 @@ TEST (socket_timeout, write)
|
|||
// create a client socket and send lots of data to fill the socket queue on the local and remote side
|
||||
// eventually, the all tcp queues should fill up and async_write will not be able to progress
|
||||
// and the timeout should kick in and close the socket, which will cause the async_write to return an error
|
||||
auto socket = std::make_shared<nano::transport::tcp_socket> (*node, nano::transport::socket_endpoint::client); // socket with a max queue size much larger than OS buffers
|
||||
auto socket = std::make_shared<nano::transport::tcp_socket> (*node, nano::transport::socket_endpoint::client, 1024 * 1024); // socket with a max queue size much larger than OS buffers
|
||||
|
||||
socket->async_connect (acceptor.local_endpoint (), [&socket, &done] (boost::system::error_code const & ec_a) {
|
||||
EXPECT_FALSE (ec_a);
|
||||
|
|
@ -513,7 +513,7 @@ TEST (socket_timeout, write_overlapped)
|
|||
// create a client socket and send lots of data to fill the socket queue on the local and remote side
|
||||
// eventually, the all tcp queues should fill up and async_write will not be able to progress
|
||||
// and the timeout should kick in and close the socket, which will cause the async_write to return an error
|
||||
auto socket = std::make_shared<nano::transport::tcp_socket> (*node, nano::transport::socket_endpoint::client); // socket with a max queue size much larger than OS buffers
|
||||
auto socket = std::make_shared<nano::transport::tcp_socket> (*node, nano::transport::socket_endpoint::client, 1024 * 1024); // socket with a max queue size much larger than OS buffers
|
||||
socket->async_connect (acceptor.local_endpoint (), [&socket, &done] (boost::system::error_code const & ec_a) {
|
||||
EXPECT_FALSE (ec_a);
|
||||
|
||||
|
|
|
|||
|
|
@ -16,12 +16,13 @@
|
|||
* socket
|
||||
*/
|
||||
|
||||
nano::transport::tcp_socket::tcp_socket (nano::node & node_a, nano::transport::socket_endpoint endpoint_type_a) :
|
||||
tcp_socket{ node_a, boost::asio::ip::tcp::socket{ node_a.io_ctx }, {}, {}, endpoint_type_a }
|
||||
nano::transport::tcp_socket::tcp_socket (nano::node & node_a, nano::transport::socket_endpoint endpoint_type_a, size_t queue_size_a) :
|
||||
tcp_socket{ node_a, boost::asio::ip::tcp::socket{ node_a.io_ctx }, {}, {}, endpoint_type_a, queue_size_a }
|
||||
{
|
||||
}
|
||||
|
||||
nano::transport::tcp_socket::tcp_socket (nano::node & node_a, boost::asio::ip::tcp::socket raw_socket_a, boost::asio::ip::tcp::endpoint remote_endpoint_a, boost::asio::ip::tcp::endpoint local_endpoint_a, nano::transport::socket_endpoint endpoint_type_a) :
|
||||
nano::transport::tcp_socket::tcp_socket (nano::node & node_a, boost::asio::ip::tcp::socket raw_socket_a, boost::asio::ip::tcp::endpoint remote_endpoint_a, boost::asio::ip::tcp::endpoint local_endpoint_a, nano::transport::socket_endpoint endpoint_type_a, size_t queue_size_a) :
|
||||
queue_size{ queue_size_a },
|
||||
send_queue{ queue_size },
|
||||
node_w{ node_a.shared () },
|
||||
strand{ node_a.io_ctx.get_executor () },
|
||||
|
|
|
|||
|
|
@ -67,10 +67,10 @@ class tcp_socket final : public std::enable_shared_from_this<tcp_socket>
|
|||
friend class tcp_listener;
|
||||
|
||||
public:
|
||||
static size_t constexpr queue_size = 16;
|
||||
static size_t constexpr default_queue_size = 16;
|
||||
|
||||
public:
|
||||
explicit tcp_socket (nano::node &, nano::transport::socket_endpoint = socket_endpoint::client);
|
||||
explicit tcp_socket (nano::node &, nano::transport::socket_endpoint = socket_endpoint::client, size_t queue_size = default_queue_size);
|
||||
|
||||
// TODO: Accepting remote/local endpoints as a parameter is unnecessary, but is needed for now to keep compatibility with the legacy code
|
||||
tcp_socket (
|
||||
|
|
@ -78,7 +78,8 @@ public:
|
|||
boost::asio::ip::tcp::socket,
|
||||
boost::asio::ip::tcp::endpoint remote_endpoint,
|
||||
boost::asio::ip::tcp::endpoint local_endpoint,
|
||||
nano::transport::socket_endpoint = socket_endpoint::server);
|
||||
nano::transport::socket_endpoint = socket_endpoint::server,
|
||||
size_t queue_size = default_queue_size);
|
||||
|
||||
~tcp_socket ();
|
||||
|
||||
|
|
@ -141,6 +142,7 @@ public:
|
|||
}
|
||||
|
||||
private:
|
||||
size_t const queue_size;
|
||||
socket_queue send_queue;
|
||||
|
||||
protected:
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue