REQUIRE(size <= ISC_NETMGR_RECVBUF_SIZE);
size = ISC_NETMGR_RECVBUF_SIZE;
break;
+ case isc_nm_tcpsocket:
case isc_nm_tcpdnssocket:
break;
case isc_nm_tlsdnssocket:
r = uv_udp_recv_start(&sock->uv_handle.udp, isc__nm_alloc_cb,
isc__nm_udp_read_cb);
break;
+ case isc_nm_tcpsocket:
+ r = uv_read_start(&sock->uv_handle.stream, isc__nm_alloc_cb,
+ isc__nm_tcp_read_cb);
+ break;
case isc_nm_tcpdnssocket:
r = uv_read_start(&sock->uv_handle.stream, isc__nm_alloc_cb,
isc__nm_tcpdns_read_cb);
case isc_nm_udpsocket:
r = uv_udp_recv_stop(&sock->uv_handle.udp);
break;
+ case isc_nm_tcpsocket:
case isc_nm_tcpdnssocket:
case isc_nm_tlsdnssocket:
r = uv_read_stop(&sock->uv_handle.stream);
static void
tcp_connection_cb(uv_stream_t *server, int status);
-static void
-read_cb(uv_stream_t *stream, ssize_t nread, const uv_buf_t *buf);
-
static void
tcp_close_cb(uv_handle_t *uvhandle);
static void
stop_tcp_child(isc_nmsocket_t *sock);
-static void
-start_reading(isc_nmsocket_t *sock);
-
-static void
-stop_reading(isc_nmsocket_t *sock);
-
-static void
-tcp_alloc_cb(uv_handle_t *handle, size_t size, uv_buf_t *buf);
-
static void
failed_accept_cb(isc_nmsocket_t *sock, isc_result_t eresult) {
REQUIRE(sock->accepting);
REQUIRE(VALID_NMSOCK(sock));
REQUIRE(sock->statichandle != NULL);
- stop_reading(sock);
+ isc__nmsocket_timer_stop(sock);
+ isc__nm_stop_reading(sock);
if (!sock->recv_read) {
goto destroy;
}
}
-static void
-start_reading(isc_nmsocket_t *sock) {
- if (sock->reading) {
- return;
- }
-
- int r = uv_read_start(&sock->uv_handle.stream, tcp_alloc_cb, read_cb);
- REQUIRE(r == 0);
- sock->reading = true;
-}
-
-static void
-stop_reading(isc_nmsocket_t *sock) {
- if (!sock->reading) {
- return;
- }
-
- int r = uv_read_stop(&sock->uv_handle.stream);
- REQUIRE(r == 0);
- sock->reading = false;
-
- isc__nmsocket_timer_stop(sock);
-}
-
void
isc__nm_tcp_read(isc_nmhandle_t *handle, isc_nm_recv_cb_t cb, void *cbarg) {
REQUIRE(VALID_NMHANDLE(handle));
return;
}
-/*%<
- * Allocator for TCP read operations. Limited to size 2^16.
- *
- * Note this doesn't actually allocate anything, it just assigns the
- * worker's receive buffer to a socket, and marks it as "in use".
- */
-static void
-tcp_alloc_cb(uv_handle_t *handle, size_t size, uv_buf_t *buf) {
- isc_nmsocket_t *sock = uv_handle_get_data(handle);
- isc__networker_t *worker = NULL;
-
- REQUIRE(VALID_NMSOCK(sock));
- REQUIRE(sock->type == isc_nm_tcpsocket);
- REQUIRE(isc__nm_in_netthread());
- if (size > 65536) {
- size = 65536;
- }
-
- worker = &sock->mgr->workers[sock->tid];
- INSIST(!worker->recvbuf_inuse);
-
- buf->base = worker->recvbuf;
- buf->len = size;
- worker->recvbuf_inuse = true;
-}
-
void
isc__nm_async_tcpstartread(isc__networker_t *worker, isc__netievent_t *ev0) {
isc__netievent_tcpstartread_t *ievent =
return;
}
- start_reading(sock);
+ isc__nm_start_reading(sock);
isc__nmsocket_timer_start(sock);
}
REQUIRE(sock->tid == isc_nm_tid());
UNUSED(worker);
- stop_reading(sock);
+ isc__nmsocket_timer_stop(sock);
+ isc__nm_stop_reading(sock);
}
void
(isc__netievent_t *)ievent);
}
-static void
-read_cb(uv_stream_t *stream, ssize_t nread, const uv_buf_t *buf) {
+void
+isc__nm_tcp_read_cb(uv_stream_t *stream, ssize_t nread, const uv_buf_t *buf) {
isc_nmsocket_t *sock = uv_handle_get_data((uv_handle_t *)stream);
isc__nm_uvreq_t *req = NULL;
static void
tcp_send_cb(uv_write_t *req, int status) {
isc__nm_uvreq_t *uvreq = (isc__nm_uvreq_t *)req->data;
- isc_nmsocket_t *sock = uvreq->sock;
-
REQUIRE(VALID_UVREQ(uvreq));
REQUIRE(VALID_NMHANDLE(uvreq->handle));
+ isc_nmsocket_t *sock = uvreq->sock;
+
if (status < 0) {
isc__nm_incstats(sock->mgr, sock->statsindex[STATID_SENDFAIL]);
failed_send_cb(sock, uvreq, isc__nm_uverr2result(status));
isc_quota_detach(&sock->quota);
}
- stop_reading(sock);
+ isc__nmsocket_timer_stop(sock);
+ isc__nm_stop_reading(sock);
+
+ uv_handle_set_data((uv_handle_t *)&sock->timer, sock);
uv_close((uv_handle_t *)&sock->timer, timer_close_cb);
}