2
0
mirror of https://gitlab.isc.org/isc-projects/bind9 synced 2025-08-31 06:25:31 +00:00

Change the isc_nm_(get|set)timeouts() to work with milliseconds

The RFC7828 specifies the keepalive interval to be 16-bit, specified in
units of 100 milliseconds and the configuration options tcp-*-timeouts
are following the suit.  The units of 100 milliseconds are very
unintuitive and while we can't change the configuration and presentation
format, we should not follow this weird unit in the API.

This commit changes the isc_nm_(get|set)timeouts() functions to work
with milliseconds and convert the values to milliseconds before passing
them to the function, not just internally.
This commit is contained in:
Ondřej Surý
2021-03-18 11:16:45 +01:00
parent 1ef232f93d
commit 36ddefacb4
7 changed files with 78 additions and 57 deletions

View File

@@ -166,7 +166,7 @@ void
isc_nmhandle_cleartimeout(isc_nmhandle_t *handle);
/*%<
* Set/clear the read/recv timeout for the socket connected to 'handle'
* to 'timeout', and reset the timer, in miliseconds.
* to 'timeout' (in milliseconds), and reset the timer.
*
* When this is called on a 'wrapper' socket handle (for example,
* a TCPDNS socket wrapping a TCP connection), the timer is set for
@@ -433,10 +433,10 @@ void
isc_nm_settimeouts(isc_nm_t *mgr, uint32_t init, uint32_t idle,
uint32_t keepalive, uint32_t advertised);
/*%<
* Sets the initial, idle, and keepalive timeout values to use for
* TCP connections, and the timeout value to advertise in responses using
* Sets the initial, idle, and keepalive timeout values (in milliseconds) to use
* for TCP connections, and the timeout value to advertise in responses using
* the EDNS TCP Keepalive option (which should ordinarily be the same
* as 'keepalive'), in tenths of seconds.
* as 'keepalive').
*
* Requires:
* \li 'mgr' is a valid netmgr.
@@ -447,7 +447,7 @@ isc_nm_gettimeouts(isc_nm_t *mgr, uint32_t *initial, uint32_t *idle,
uint32_t *keepalive, uint32_t *advertised);
/*%<
* Gets the initial, idle, keepalive, or advertised timeout values,
* in tenths of seconds.
* in milliseconds.
*
* Any integer pointer parameter not set to NULL will be updated to
* contain the corresponding timeout value.

View File

@@ -1705,7 +1705,7 @@ isc__nm_socket_dontfrag(uv_os_sock_t fd, sa_family_t sa_family);
isc_result_t
isc__nm_socket_connectiontimeout(uv_os_sock_t fd, int timeout_ms);
/*%<
* Set the connection timeout in miliseconds, on non-Linux platforms,
* Set the connection timeout in milliseconds, on non-Linux platforms,
* the minimum value must be at least 1000 (1 second).
*/

View File

@@ -509,10 +509,10 @@ isc_nm_settimeouts(isc_nm_t *mgr, uint32_t init, uint32_t idle,
uint32_t keepalive, uint32_t advertised) {
REQUIRE(VALID_NM(mgr));
atomic_store(&mgr->init, init * 100);
atomic_store(&mgr->idle, idle * 100);
atomic_store(&mgr->keepalive, keepalive * 100);
atomic_store(&mgr->advertised, advertised * 100);
atomic_store(&mgr->init, init);
atomic_store(&mgr->idle, idle);
atomic_store(&mgr->keepalive, keepalive);
atomic_store(&mgr->advertised, advertised);
}
void
@@ -521,19 +521,19 @@ isc_nm_gettimeouts(isc_nm_t *mgr, uint32_t *initial, uint32_t *idle,
REQUIRE(VALID_NM(mgr));
if (initial != NULL) {
*initial = atomic_load(&mgr->init) / 100;
*initial = atomic_load(&mgr->init);
}
if (idle != NULL) {
*idle = atomic_load(&mgr->idle) / 100;
*idle = atomic_load(&mgr->idle);
}
if (keepalive != NULL) {
*keepalive = atomic_load(&mgr->keepalive) / 100;
*keepalive = atomic_load(&mgr->keepalive);
}
if (advertised != NULL) {
*advertised = atomic_load(&mgr->advertised) / 100;
*advertised = atomic_load(&mgr->advertised);
}
}

View File

@@ -243,7 +243,6 @@ nm_setup(void **state) {
for (size_t i = 0; i < MAX_NM; i++) {
nm[i] = isc_nm_start(test_mctx, nworkers);
assert_non_null(nm[i]);
isc_nm_settimeouts(nm[i], 1000, 1000, 1000, 1000);
}
*state = nm;

View File

@@ -253,7 +253,6 @@ nm_setup(void **state) {
for (size_t i = 0; i < MAX_NM; i++) {
nm[i] = isc_nm_start(test_mctx, nworkers);
assert_non_null(nm[i]);
isc_nm_settimeouts(nm[i], 1000, 1000, 1000, 1000);
}
*state = nm;