diff options
author | Determinant <[email protected]> | 2020-02-14 15:13:47 -0500 |
---|---|---|
committer | Determinant <[email protected]> | 2020-02-14 15:13:47 -0500 |
commit | 853a6503391a05a3f60b50bb40a7dd4f35588293 (patch) | |
tree | c25dc16a0f5170611d0aa8e3a12d63e98a036342 | |
parent | 7dc5ec52b1c419c58c68d7359870a292ab12d7db (diff) |
change queue_capacity to max_send_buff_size; adjust the C API
-rw-r--r-- | include/salticidae/conn.h | 22 | ||||
-rw-r--r-- | include/salticidae/network.h | 3 | ||||
-rw-r--r-- | src/conn.cpp | 4 | ||||
-rw-r--r-- | src/network.cpp | 8 | ||||
-rw-r--r-- | test/bench_network.cpp | 2 | ||||
-rw-r--r-- | test/bench_network_tls.cpp | 2 | ||||
-rw-r--r-- | test/test_bounded_recv_buffer.cpp | 2 |
7 files changed, 24 insertions, 19 deletions
diff --git a/include/salticidae/conn.h b/include/salticidae/conn.h index 9afc813..b43d3c2 100644 --- a/include/salticidae/conn.h +++ b/include/salticidae/conn.h @@ -139,7 +139,7 @@ class ConnPool { /** Write data to the connection (non-blocking). The data will be sent * whenever I/O is available. */ bool write(bytearray_t &&data) { - return send_buffer.push(std::move(data), !cpool->queue_capacity); + return send_buffer.push(std::move(data), !cpool->max_send_buff_size); } }; @@ -185,7 +185,7 @@ class ConnPool { const double conn_server_timeout; const size_t seg_buff_size; const size_t max_recv_buff_size; - const size_t queue_capacity; + const size_t max_send_buff_size; tls_context_t tls_ctx; conn_callback_t conn_cb; @@ -363,8 +363,8 @@ class ConnPool { double _conn_server_timeout; size_t _seg_buff_size; size_t _max_recv_buff_size; + size_t _max_send_buff_size; size_t _nworker; - size_t _queue_capacity; bool _enable_tls; std::string _tls_cert_file; std::string _tls_key_file; @@ -379,8 +379,8 @@ class ConnPool { _conn_server_timeout(2), _seg_buff_size(4096), _max_recv_buff_size(4096), + _max_send_buff_size(0), _nworker(1), - _queue_capacity(0), _enable_tls(false), _tls_cert_file(""), _tls_key_file(""), @@ -404,18 +404,18 @@ class ConnPool { return *this; } - Config &max_recv_buff_size(size_t x) { - _max_recv_buff_size = x; + Config &nworker(size_t x) { + _nworker = std::max((size_t)1, x); return *this; } - Config &nworker(size_t x) { - _nworker = std::max((size_t)1, x); + Config &max_recv_buff_size(size_t x) { + _max_recv_buff_size = x; return *this; } - Config &queue_capacity(size_t x) { - _queue_capacity = x; + Config &max_send_buff_size(size_t x) { + _max_send_buff_size = x; return *this; } @@ -463,7 +463,7 @@ class ConnPool { conn_server_timeout(config._conn_server_timeout), seg_buff_size(config._seg_buff_size), max_recv_buff_size(config._max_recv_buff_size), - queue_capacity(config._queue_capacity), + max_send_buff_size(config._max_send_buff_size), tls_ctx(nullptr), listen_fd(-1), nworker(config._nworker) { diff --git a/include/salticidae/network.h b/include/salticidae/network.h index 3ecffe7..6fe8395 100644 --- a/include/salticidae/network.h +++ b/include/salticidae/network.h @@ -1313,7 +1313,8 @@ void msgnetwork_config_max_listen_backlog(msgnetwork_config_t *self, int backlog void msgnetwork_config_conn_server_timeout(msgnetwork_config_t *self, double timeout); void msgnetwork_config_seg_buff_size(msgnetwork_config_t *self, size_t size); void msgnetwork_config_nworker(msgnetwork_config_t *self, size_t nworker); -void msgnetwork_config_queue_capacity(msgnetwork_config_t *self, size_t cap); +void msgnetwork_config_max_recv_buff_size(msgnetwork_config_t *self, size_t size); +void msgnetwork_config_max_send_buff_size(msgnetwork_config_t *self, size_t size); void msgnetwork_config_enable_tls(msgnetwork_config_t *self, bool enabled); void msgnetwork_config_tls_key_file(msgnetwork_config_t *self, const char *pem_fname); void msgnetwork_config_tls_cert_file(msgnetwork_config_t *self, const char *pem_fname); diff --git a/src/conn.cpp b/src/conn.cpp index 311b1f8..ba584c1 100644 --- a/src/conn.cpp +++ b/src/conn.cpp @@ -319,7 +319,7 @@ void ConnPool::accept_client(int fd, int) { NetAddr addr((struct sockaddr_in *)&client_addr); conn_t conn = create_conn(); - conn->send_buffer.set_capacity(queue_capacity); + conn->send_buffer.set_capacity(max_send_buff_size); conn->seg_buff_size = seg_buff_size; conn->max_recv_buff_size = max_recv_buff_size; conn->fd = client_fd; @@ -400,7 +400,7 @@ ConnPool::conn_t ConnPool::_connect(const NetAddr &addr) { if (fcntl(fd, F_SETFL, O_NONBLOCK) == -1) throw ConnPoolError(SALTI_ERROR_CONNECT, errno); conn_t conn = create_conn(); - conn->send_buffer.set_capacity(queue_capacity); + conn->send_buffer.set_capacity(max_send_buff_size); conn->seg_buff_size = seg_buff_size; conn->max_recv_buff_size = max_recv_buff_size; conn->fd = fd; diff --git a/src/network.cpp b/src/network.cpp index 2e98439..4717953 100644 --- a/src/network.cpp +++ b/src/network.cpp @@ -43,8 +43,12 @@ void msgnetwork_config_nworker(msgnetwork_config_t *self, size_t nworker) { self->nworker(nworker); } -void msgnetwork_config_queue_capacity(msgnetwork_config_t *self, size_t cap) { - self->queue_capacity(cap); +void msgnetwork_config_max_recv_buff_size(msgnetwork_config_t *self, size_t size) { + self->max_recv_buff_size(size); +} + +void msgnetwork_config_max_send_buff_size(msgnetwork_config_t *self, size_t size) { + self->max_send_buff_size(size); } void msgnetwork_config_enable_tls(msgnetwork_config_t *self, bool enabled) { diff --git a/test/bench_network.cpp b/test/bench_network.cpp index 1d52c39..13d9282 100644 --- a/test/bench_network.cpp +++ b/test/bench_network.cpp @@ -81,7 +81,7 @@ struct MyNet: public MsgNetworkByteOp { double stat_timeout = -1): MsgNetworkByteOp(ec, MsgNetworkByteOp::Config( ConnPool::Config() - .queue_capacity(65536) + .max_send_buff_size(65536) ).burst_size(1000)), name(name), ev_period_stat(ec, [this, stat_timeout](TimerEvent &) { diff --git a/test/bench_network_tls.cpp b/test/bench_network_tls.cpp index 47b9347..576056d 100644 --- a/test/bench_network_tls.cpp +++ b/test/bench_network_tls.cpp @@ -81,7 +81,7 @@ struct MyNet: public MsgNetworkByteOp { double stat_timeout = -1): MsgNetworkByteOp(ec, MsgNetworkByteOp::Config( ConnPool::Config() - .queue_capacity(65536) + .max_send_buff_size(65536) .enable_tls(true) .tls_cert_file("alice.pem") .tls_key_file("alice.pem")).burst_size(1000)), diff --git a/test/test_bounded_recv_buffer.cpp b/test/test_bounded_recv_buffer.cpp index b092260..2ea34f6 100644 --- a/test/test_bounded_recv_buffer.cpp +++ b/test/test_bounded_recv_buffer.cpp @@ -83,7 +83,7 @@ struct MyNet: public MsgNetworkByteOp { MsgNetworkByteOp(ec, MsgNetworkByteOp::Config( ConnPool::Config() .max_recv_buff_size(10) - .queue_capacity(10) + .max_send_buff_size(10) ).burst_size(10)), name(name), ev_period_stat(ec, [this, stat_timeout](TimerEvent &) { |