From: Witold Kręcicki Date: Mon, 20 Aug 2018 09:56:37 +0000 (+0200) Subject: Remove fdwatch sockets X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=4b55fd0d8a9ece5e2a122e88c0934fd58bc374d2;p=thirdparty%2Fbind9.git Remove fdwatch sockets --- diff --git a/lib/isc/include/isc/socket.h b/lib/isc/include/isc/socket.h index 76d9be25755..95a722b481e 100644 --- a/lib/isc/include/isc/socket.h +++ b/lib/isc/include/isc/socket.h @@ -244,8 +244,7 @@ typedef enum { isc_sockettype_udp = 1, isc_sockettype_tcp = 2, isc_sockettype_unix = 3, - isc_sockettype_fdwatch = 4, - isc_sockettype_raw = 5 + isc_sockettype_raw = 4 } isc_sockettype_t; /*@{*/ @@ -276,14 +275,6 @@ typedef enum { #define ISC_SOCKFLAG_NORETRY 0x00000002 /*%< drop failed UDP sends */ /*@}*/ -/*@{*/ -/*! - * Flags for fdwatchcreate. - */ -#define ISC_SOCKFDWATCH_READ 0x00000001 /*%< watch for readable */ -#define ISC_SOCKFDWATCH_WRITE 0x00000002 /*%< watch for writable */ -/*@}*/ - /*% * This structure is actually just the common prefix of a socket manager * object implementation's version of an isc_socketmgr_t. @@ -330,76 +321,6 @@ struct isc_socket { *** those functions which return an isc_result. ***/ -isc_result_t -isc_socket_fdwatchcreate(isc_socketmgr_t *manager, - int fd, - int flags, - isc_sockfdwatch_t callback, - void *cbarg, - isc_task_t *task, - isc_socket_t **socketp); -/*%< - * Create a new file descriptor watch socket managed by 'manager'. - * - * Note: - * - *\li 'fd' is the already-opened file descriptor (must be less - * than maxsockets). - *\li This function is not available on Windows. - *\li The callback function is called "in-line" - this means the function - * needs to return as fast as possible, as all other I/O will be suspended - * until the callback completes. - * - * Requires: - * - *\li 'manager' is a valid manager - * - *\li 'socketp' is a valid pointer, and *socketp == NULL - * - *\li 'fd' be opened. - * - * Ensures: - * - * '*socketp' is attached to the newly created fdwatch socket - * - * Returns: - * - *\li #ISC_R_SUCCESS - *\li #ISC_R_NOMEMORY - *\li #ISC_R_NORESOURCES - *\li #ISC_R_UNEXPECTED - *\li #ISC_R_RANGE - */ - -isc_result_t -isc_socket_fdwatchpoke(isc_socket_t *sock, - int flags); -/*%< - * Poke a file descriptor watch socket informing the manager that it - * should restart watching the socket - * - * Note: - * - *\li 'sock' is the socket returned by isc_socket_fdwatchcreate - * - *\li 'flags' indicates what the manager should watch for on the socket - * in addition to what it may already be watching. It can be one or - * both of ISC_SOCKFDWATCH_READ and ISC_SOCKFDWATCH_WRITE. To - * temporarily disable watching on a socket the value indicating - * no more data should be returned from the call back routine. - * - *\li This function is not available on Windows. - * - * Requires: - * - *\li 'sock' is a valid isc socket - * - * - * Returns: - * - *\li #ISC_R_SUCCESS - */ - isc_result_t isc_socket_create(isc_socketmgr_t *manager, int pf, @@ -408,9 +329,6 @@ isc_socket_create(isc_socketmgr_t *manager, /*%< * Create a new 'type' socket managed by 'manager'. * - * For isc_sockettype_fdwatch sockets you should use isc_socket_fdwatchcreate() - * rather than isc_socket_create(). - * * Note: * *\li 'pf' is the desired protocol family, e.g. PF_INET or PF_INET6. @@ -421,8 +339,6 @@ isc_socket_create(isc_socketmgr_t *manager, * *\li 'socketp' is a valid pointer, and *socketp == NULL * - *\li 'type' is not isc_sockettype_fdwatch - * * Ensures: * * '*socketp' is attached to the newly created socket @@ -552,17 +468,12 @@ isc_socket_open(isc_socket_t *sock); * one. This optimization may not be available for some systems, in which * case this function will return ISC_R_NOTIMPLEMENTED and must not be used. * - * isc_socket_open() should not be called on sockets created by - * isc_socket_fdwatchcreate(). - * * Requires: * * \li there must be no other reference to this socket. * * \li 'socket' is a valid and previously closed by isc_socket_close() * - * \li 'sock->type' is not isc_sockettype_fdwatch - * * Returns: * Same as isc_socket_create(). * \li ISC_R_NOTIMPLEMENTED @@ -578,9 +489,6 @@ isc_socket_close(isc_socket_t *sock); * systems, in which case this function will return ISC_R_NOTIMPLEMENTED and * must not be used. * - * isc_socket_close() should not be called on sockets created by - * isc_socket_fdwatchcreate(). - * * Requires: * * \li The socket must have a valid descriptor. @@ -589,8 +497,6 @@ isc_socket_close(isc_socket_t *sock); * * \li There must be no pending I/O requests. * - * \li 'sock->type' is not isc_sockettype_fdwatch - * * Returns: * \li #ISC_R_NOTIMPLEMENTED */ diff --git a/lib/isc/unix/socket.c b/lib/isc/unix/socket.c index 20601d6622e..d3530ec7521 100644 --- a/lib/isc/unix/socket.c +++ b/lib/isc/unix/socket.c @@ -374,10 +374,6 @@ struct isc__socket { unsigned char overflow; /* used for MSG_TRUNC fake */ #endif - void *fdwatcharg; - isc_sockfdwatch_t fdwatchcb; - int fdwatchflags; - isc_task_t *fdwatchtask; unsigned int dscp; }; @@ -468,8 +464,6 @@ static void internal_accept(isc_task_t *, isc_event_t *); static void internal_connect(isc_task_t *, isc_event_t *); static void internal_recv(isc_task_t *, isc_event_t *); static void internal_send(isc_task_t *, isc_event_t *); -static void internal_fdwatch_write(isc_task_t *, isc_event_t *); -static void internal_fdwatch_read(isc_task_t *, isc_event_t *); static void process_cmsg(isc__socket_t *, struct msghdr *, isc_socketevent_t *); static void build_msghdr_send(isc__socket_t *, char *, isc_socketevent_t *, struct msghdr *, struct iovec *, size_t *); @@ -569,19 +563,6 @@ static const isc_statscounter_t unixstatsindex[] = { isc_sockstatscounter_unixrecvfail, isc_sockstatscounter_unixactive }; -static const isc_statscounter_t fdwatchstatsindex[] = { - -1, - -1, - isc_sockstatscounter_fdwatchclose, - isc_sockstatscounter_fdwatchbindfail, - isc_sockstatscounter_fdwatchconnectfail, - isc_sockstatscounter_fdwatchconnect, - -1, - -1, - isc_sockstatscounter_fdwatchsendfail, - isc_sockstatscounter_fdwatchrecvfail, - -1 -}; static const isc_statscounter_t rawstatsindex[] = { isc_sockstatscounter_rawopen, isc_sockstatscounter_rawopenfail, @@ -1669,7 +1650,6 @@ doio_recv(isc__socket_t *sock, isc_socketevent_t *dev) { case isc_sockettype_udp: case isc_sockettype_raw: break; - case isc_sockettype_fdwatch: default: INSIST(0); } @@ -1888,7 +1868,6 @@ doio_send(isc__socket_t *sock, isc_socketevent_t *dev) { */ static void socketclose(isc__socketmgr_t *manager, isc__socket_t *sock, int fd) { - isc_sockettype_t type = sock->type; int lockid = FDLOCK_ID(fd); /* @@ -1897,25 +1876,9 @@ socketclose(isc__socketmgr_t *manager, isc__socket_t *sock, int fd) { */ LOCK(&manager->fdlock[lockid]); manager->fds[fd] = NULL; - if (type == isc_sockettype_fdwatch) - manager->fdstate[fd] = CLOSED; - else - manager->fdstate[fd] = CLOSE_PENDING; + manager->fdstate[fd] = CLOSE_PENDING; UNLOCK(&manager->fdlock[lockid]); - if (type == isc_sockettype_fdwatch) { - /* - * The caller may close the socket once this function returns, - * and `fd' may be reassigned for a new socket. So we do - * unwatch_fd() here, rather than defer it via select_poke(). - * Note: this may complicate data protection among threads and - * may reduce performance due to additional locks. One way to - * solve this would be to dup() the watched descriptor, but we - * take a simpler approach at this moment. - */ - (void)unwatch_fd(manager, fd, SELECT_POKE_READ); - (void)unwatch_fd(manager, fd, SELECT_POKE_WRITE); - } else - select_poke(manager, fd, SELECT_POKE_CLOSE); + select_poke(manager, fd, SELECT_POKE_CLOSE); inc_stats(manager->stats, sock->statsindex[STATID_CLOSE]); if (sock->active == 1) { @@ -2348,13 +2311,6 @@ opensocket(isc__socketmgr_t *manager, isc__socket_t *sock, } #endif break; - case isc_sockettype_fdwatch: - /* - * We should not be called for isc_sockettype_fdwatch - * sockets. - */ - INSIST(0); - break; } } else { sock->fd = dup(dup_socket->fd); @@ -2688,7 +2644,6 @@ socket_create(isc_socketmgr_t *manager0, int pf, isc_sockettype_t type, REQUIRE(VALID_MANAGER(manager)); REQUIRE(socketp != NULL && *socketp == NULL); - REQUIRE(type != isc_sockettype_fdwatch); result = allocate_socket(manager, type, &sock); if (result != ISC_R_SUCCESS) @@ -2796,7 +2751,6 @@ isc_socket_open(isc_socket_t *sock0) { LOCK(&sock->lock); REQUIRE(sock->references == 1); - REQUIRE(sock->type != isc_sockettype_fdwatch); UNLOCK(&sock->lock); /* * We don't need to retain the lock hereafter, since no one else has @@ -2834,112 +2788,6 @@ isc_socket_open(isc_socket_t *sock0) { return (result); } -/* - * Create a new 'type' socket managed by 'manager'. Events - * will be posted to 'task' and when dispatched 'action' will be - * called with 'arg' as the arg value. The new socket is returned - * in 'socketp'. - */ -isc_result_t -isc_socket_fdwatchcreate(isc_socketmgr_t *manager0, int fd, int flags, - isc_sockfdwatch_t callback, void *cbarg, - isc_task_t *task, isc_socket_t **socketp) -{ - isc__socketmgr_t *manager = (isc__socketmgr_t *)manager0; - isc__socket_t *sock = NULL; - isc_result_t result; - int lockid; - - REQUIRE(VALID_MANAGER(manager)); - REQUIRE(socketp != NULL && *socketp == NULL); - - if (fd < 0 || (unsigned int)fd >= manager->maxsocks) - return (ISC_R_RANGE); - - result = allocate_socket(manager, isc_sockettype_fdwatch, &sock); - if (result != ISC_R_SUCCESS) - return (result); - - sock->fd = fd; - sock->fdwatcharg = cbarg; - sock->fdwatchcb = callback; - sock->fdwatchflags = flags; - sock->fdwatchtask = task; - sock->statsindex = fdwatchstatsindex; - - sock->references = 1; - *socketp = (isc_socket_t *)sock; - - /* - * Note we don't have to lock the socket like we normally would because - * there are no external references to it yet. - */ - - lockid = FDLOCK_ID(sock->fd); - LOCK(&manager->fdlock[lockid]); - manager->fds[sock->fd] = sock; - manager->fdstate[sock->fd] = MANAGED; -#if defined(USE_EPOLL) - manager->epoll_events[sock->fd] = 0; -#endif - UNLOCK(&manager->fdlock[lockid]); - - LOCK(&manager->lock); - ISC_LIST_APPEND(manager->socklist, sock, link); -#ifdef USE_SELECT - if (manager->maxfd < sock->fd) - manager->maxfd = sock->fd; -#endif - UNLOCK(&manager->lock); - - if (flags & ISC_SOCKFDWATCH_READ) - select_poke(sock->manager, sock->fd, SELECT_POKE_READ); - if (flags & ISC_SOCKFDWATCH_WRITE) - select_poke(sock->manager, sock->fd, SELECT_POKE_WRITE); - - socket_log(sock, NULL, CREATION, isc_msgcat, ISC_MSGSET_SOCKET, - ISC_MSG_CREATED, "fdwatch-created"); - - return (ISC_R_SUCCESS); -} - -/* - * Indicate to the manager that it should watch the socket again. - * This can be used to restart watching if the previous event handler - * didn't indicate there was more data to be processed. Primarily - * it is for writing but could be used for reading if desired - */ - -isc_result_t -isc_socket_fdwatchpoke(isc_socket_t *sock0, int flags) -{ - isc__socket_t *sock = (isc__socket_t *)sock0; - - REQUIRE(VALID_SOCKET(sock)); - - /* - * We check both flags first to allow us to get the lock - * once but only if we need it. - */ - - if ((flags & (ISC_SOCKFDWATCH_READ | ISC_SOCKFDWATCH_WRITE)) != 0) { - LOCK(&sock->lock); - if (((flags & ISC_SOCKFDWATCH_READ) != 0) && - !sock->pending_recv) - select_poke(sock->manager, sock->fd, - SELECT_POKE_READ); - if (((flags & ISC_SOCKFDWATCH_WRITE) != 0) && - !sock->pending_send) - select_poke(sock->manager, sock->fd, - SELECT_POKE_WRITE); - UNLOCK(&sock->lock); - } - - socket_log(sock, NULL, TRACE, isc_msgcat, ISC_MSGSET_SOCKET, - ISC_MSG_POKED, "fdwatch-poked flags: %d", flags); - - return (ISC_R_SUCCESS); -} /* * Attach to a socket. Caller must explicitly detach when it is done. @@ -2996,7 +2844,6 @@ isc_socket_close(isc_socket_t *sock0) { LOCK(&sock->lock); REQUIRE(sock->references == 1); - REQUIRE(sock->type != isc_sockettype_fdwatch); REQUIRE(sock->fd >= 0 && sock->fd < (int)sock->manager->maxsocks); INSIST(!sock->connecting); @@ -3043,27 +2890,20 @@ dispatch_recv(isc__socket_t *sock) { INSIST(!sock->pending_recv); - if (sock->type != isc_sockettype_fdwatch) { - ev = ISC_LIST_HEAD(sock->recv_list); - if (ev == NULL) - return; - socket_log(sock, NULL, EVENT, NULL, 0, 0, - "dispatch_recv: event %p -> task %p", - ev, ev->ev_sender); - sender = ev->ev_sender; - } else { - sender = sock->fdwatchtask; - } + ev = ISC_LIST_HEAD(sock->recv_list); + if (ev == NULL) + return; + socket_log(sock, NULL, EVENT, NULL, 0, 0, + "dispatch_recv: event %p -> task %p", + ev, ev->ev_sender); + sender = ev->ev_sender; sock->pending_recv = 1; iev = &sock->readable_ev; sock->references++; iev->ev_sender = sock; - if (sock->type == isc_sockettype_fdwatch) - iev->ev_action = internal_fdwatch_read; - else - iev->ev_action = internal_recv; + iev->ev_action = internal_recv; iev->ev_arg = sock; isc_task_send(sender, (isc_event_t **)&iev); @@ -3077,27 +2917,20 @@ dispatch_send(isc__socket_t *sock) { INSIST(!sock->pending_send); - if (sock->type != isc_sockettype_fdwatch) { - ev = ISC_LIST_HEAD(sock->send_list); - if (ev == NULL) - return; - socket_log(sock, NULL, EVENT, NULL, 0, 0, - "dispatch_send: event %p -> task %p", - ev, ev->ev_sender); - sender = ev->ev_sender; - } else { - sender = sock->fdwatchtask; - } + ev = ISC_LIST_HEAD(sock->send_list); + if (ev == NULL) + return; + socket_log(sock, NULL, EVENT, NULL, 0, 0, + "dispatch_send: event %p -> task %p", + ev, ev->ev_sender); + sender = ev->ev_sender; sock->pending_send = 1; iev = &sock->writable_ev; sock->references++; iev->ev_sender = sock; - if (sock->type == isc_sockettype_fdwatch) - iev->ev_action = internal_fdwatch_write; - else - iev->ev_action = internal_send; + iev->ev_action = internal_send; iev->ev_arg = sock; isc_task_send(sender, (isc_event_t **)&iev); @@ -3617,88 +3450,6 @@ internal_send(isc_task_t *me, isc_event_t *ev) { UNLOCK(&sock->lock); } -static void -internal_fdwatch_write(isc_task_t *me, isc_event_t *ev) { - isc__socket_t *sock; - int more_data; - - INSIST(ev->ev_type == ISC_SOCKEVENT_INTW); - - /* - * Find out what socket this is and lock it. - */ - sock = (isc__socket_t *)ev->ev_sender; - INSIST(VALID_SOCKET(sock)); - - LOCK(&sock->lock); - socket_log(sock, NULL, IOEVENT, - isc_msgcat, ISC_MSGSET_SOCKET, ISC_MSG_INTERNALSEND, - "internal_fdwatch_write: task %p got event %p", me, ev); - - INSIST(sock->pending_send == 1); - - UNLOCK(&sock->lock); - more_data = (sock->fdwatchcb)(me, (isc_socket_t *)sock, - sock->fdwatcharg, ISC_SOCKFDWATCH_WRITE); - LOCK(&sock->lock); - - sock->pending_send = 0; - - INSIST(sock->references > 0); - sock->references--; /* the internal event is done with this socket */ - if (sock->references == 0) { - UNLOCK(&sock->lock); - destroy(&sock); - return; - } - - if (more_data) - select_poke(sock->manager, sock->fd, SELECT_POKE_WRITE); - - UNLOCK(&sock->lock); -} - -static void -internal_fdwatch_read(isc_task_t *me, isc_event_t *ev) { - isc__socket_t *sock; - int more_data; - - INSIST(ev->ev_type == ISC_SOCKEVENT_INTR); - - /* - * Find out what socket this is and lock it. - */ - sock = (isc__socket_t *)ev->ev_sender; - INSIST(VALID_SOCKET(sock)); - - LOCK(&sock->lock); - socket_log(sock, NULL, IOEVENT, - isc_msgcat, ISC_MSGSET_SOCKET, ISC_MSG_INTERNALRECV, - "internal_fdwatch_read: task %p got event %p", me, ev); - - INSIST(sock->pending_recv == 1); - - UNLOCK(&sock->lock); - more_data = (sock->fdwatchcb)(me, (isc_socket_t *)sock, - sock->fdwatcharg, ISC_SOCKFDWATCH_READ); - LOCK(&sock->lock); - - sock->pending_recv = 0; - - INSIST(sock->references > 0); - sock->references--; /* the internal event is done with this socket */ - if (sock->references == 0) { - UNLOCK(&sock->lock); - destroy(&sock); - return; - } - - if (more_data) - select_poke(sock->manager, sock->fd, SELECT_POKE_READ); - - UNLOCK(&sock->lock); -} - /* * Process read/writes on each fd here. Avoid locking * and unlocking twice if both reads and writes are possible. @@ -6098,8 +5849,6 @@ _socktype(isc_sockettype_t type) return ("tcp"); else if (type == isc_sockettype_unix) return ("unix"); - else if (type == isc_sockettype_fdwatch) - return ("fdwatch"); else return ("not-initialized"); } diff --git a/lib/isc/win32/socket.c b/lib/isc/win32/socket.c index db9ba9fe7c7..8e568268a85 100644 --- a/lib/isc/win32/socket.c +++ b/lib/isc/win32/socket.c @@ -1649,7 +1649,6 @@ socket_create(isc_socketmgr_t *manager, int pf, isc_sockettype_t type, REQUIRE(VALID_MANAGER(manager)); REQUIRE(socketp != NULL && *socketp == NULL); - REQUIRE(type != isc_sockettype_fdwatch); #ifndef SOCK_RAW if (type == isc_sockettype_raw) @@ -1855,7 +1854,6 @@ isc_socket_dup(isc_socket_t *sock, isc_socket_t **socketp) { isc_result_t isc_socket_open(isc_socket_t *sock) { REQUIRE(VALID_SOCKET(sock)); - REQUIRE(sock->type != isc_sockettype_fdwatch); return (ISC_R_NOTIMPLEMENTED); } @@ -1887,7 +1885,6 @@ isc_socket_detach(isc_socket_t **socketp) { REQUIRE(socketp != NULL); sock = *socketp; REQUIRE(VALID_SOCKET(sock)); - REQUIRE(sock->type != isc_sockettype_fdwatch); LOCK(&sock->lock); CONSISTENT(sock); @@ -1913,7 +1910,6 @@ isc_socket_detach(isc_socket_t **socketp) { isc_result_t isc_socket_close(isc_socket_t *sock) { REQUIRE(VALID_SOCKET(sock)); - REQUIRE(sock->type != isc_sockettype_fdwatch); return (ISC_R_NOTIMPLEMENTED); } @@ -3078,7 +3074,6 @@ isc_socket_sendto(isc_socket_t *sock, isc_region_t *region, isc_result_t ret; REQUIRE(VALID_SOCKET(sock)); - REQUIRE(sock->type != isc_sockettype_fdwatch); LOCK(&sock->lock); CONSISTENT(sock); @@ -3956,8 +3951,6 @@ _socktype(isc_sockettype_t type) { return ("tcp"); else if (type == isc_sockettype_unix) return ("unix"); - else if (type == isc_sockettype_fdwatch) - return ("fdwatch"); else return ("not-initialized"); }