sock->pquota = NULL;
- if (sock->timer_initialized) {
- sock->timer_initialized = false;
- /* We might be in timer callback */
- if (!uv_is_closing((uv_handle_t *)&sock->timer)) {
- uv_timer_stop(&sock->timer);
- uv_close((uv_handle_t *)&sock->timer, NULL);
- }
- }
-
isc_astack_destroy(sock->inactivehandles);
while ((uvreq = isc_astack_pop(sock->inactivereqs)) != NULL) {
#endif
UNLOCK(&sock->lock);
- if (sock->type == isc_nm_tcpsocket || sock->type == isc_nm_tlssocket ||
- (sock->type == isc_nm_udpsocket && atomic_load(&sock->client)) ||
- (sock->type == isc_nm_tcpdnssocket && atomic_load(&sock->client)) ||
- (sock->type == isc_nm_tlsdnssocket && atomic_load(&sock->client)))
- {
+ switch (sock->type) {
+ case isc_nm_udpsocket:
+ case isc_nm_tcpdnssocket:
+ case isc_nm_tlsdnssocket:
+ if (!atomic_load(&sock->client)) {
+ break;
+ }
+ /* fallthrough */
+ case isc_nm_tcpsocket:
+ case isc_nm_tlssocket:
INSIST(sock->statichandle == NULL);
/*
* handle and socket would never be freed.
*/
sock->statichandle = handle;
+ break;
+ default:
+ break;
}
if (sock->type == isc_nm_httpsocket && sock->h2.session) {
REQUIRE(sock->tid == isc_nm_tid());
REQUIRE(sock->reading);
- isc__nm_failed_read_cb(sock, ISC_R_TIMEDOUT);
+ if (atomic_load(&sock->client)) {
+ if (sock->recv_cb != NULL) {
+ isc__nm_uvreq_t *req = isc__nm_get_read_req(sock, NULL);
+ isc__nm_readcb(sock, req, ISC_R_TIMEDOUT);
+ }
+
+ if (!isc__nmsocket_timer_running(sock)) {
+ isc__nmsocket_clearcb(sock);
+ isc__nm_failed_read_cb(sock, ISC_R_CANCELED);
+ }
+ } else {
+ isc__nm_failed_read_cb(sock, ISC_R_TIMEDOUT);
+ }
}
void
RUNTIME_CHECK(r == 0);
}
+bool
+isc__nmsocket_timer_running(isc_nmsocket_t *sock) {
+ REQUIRE(VALID_NMSOCK(sock));
+
+ return (uv_is_active((uv_handle_t *)&sock->timer));
+}
+
void
isc__nmsocket_timer_start(isc_nmsocket_t *sock) {
REQUIRE(VALID_NMSOCK(sock));
- if (uv_is_active((uv_handle_t *)&sock->timer)) {
+ if (isc__nmsocket_timer_running(sock)) {
return;
}
isc__nmsocket_timer_stop(isc_nmsocket_t *sock) {
REQUIRE(VALID_NMSOCK(sock));
- if (!uv_is_active((uv_handle_t *)&sock->timer)) {
- return;
- }
+ /* uv_timer_stop() is idempotent, no need to check if running */
int r = uv_timer_stop(&sock->timer);
RUNTIME_CHECK(r == 0);
req->cb.recv = sock->recv_cb;
req->cbarg = sock->recv_cbarg;
- if (atomic_load(&sock->client)) {
+ switch (sock->type) {
+ case isc_nm_tcpsocket:
+ case isc_nm_tlssocket:
isc_nmhandle_attach(sock->statichandle, &req->handle);
- } else {
- req->handle = isc__nmhandle_get(sock, sockaddr, NULL);
+ break;
+ default:
+ if (atomic_load(&sock->client)) {
+ isc_nmhandle_attach(sock->statichandle, &req->handle);
+ } else {
+ req->handle = isc__nmhandle_get(sock, sockaddr, NULL);
+ }
+ break;
}
- return req;
+ return (req);
}
/*%<
return;
default:
handle->sock->read_timeout = timeout;
- if (uv_is_active((uv_handle_t *)&handle->sock->timer)) {
- isc__nmsocket_timer_restart(handle->sock);
- }
+ isc__nmsocket_timer_restart(handle->sock);
}
}
static void
stop_reading(isc_nmsocket_t *sock);
-static isc__nm_uvreq_t *
-get_read_req(isc_nmsocket_t *sock);
-
static void
tcp_alloc_cb(uv_handle_t *handle, size_t size, uv_buf_t *buf);
sock->recv_read = false;
if (sock->recv_cb != NULL) {
- isc__nm_uvreq_t *req = get_read_req(sock);
+ isc__nm_uvreq_t *req = isc__nm_get_read_req(sock, NULL);
isc__nmsocket_clearcb(sock);
isc__nm_readcb(sock, req, result);
}
}
}
-static isc__nm_uvreq_t *
-get_read_req(isc_nmsocket_t *sock) {
- isc__nm_uvreq_t *req = NULL;
-
- req = isc__nm_uvreq_get(sock->mgr, sock);
- req->cb.recv = sock->recv_cb;
- req->cbarg = sock->recv_cbarg;
- isc_nmhandle_attach(sock->statichandle, &req->handle);
-
- return req;
-}
-
static void
start_reading(isc_nmsocket_t *sock) {
if (sock->reading) {
goto free;
}
- req = get_read_req(sock);
+ req = isc__nm_get_read_req(sock, NULL);
/*
* The callback will be called synchronously because the
nactive = atomic_load(&listener->active_child_connections);
INSIST(nactive >= 0);
- return nactive;
+ return (nactive);
}