]> git.ipfire.org Git - thirdparty/bind9.git/commitdiff
Remove fdwatch sockets, those are not used anywhere.
authorWitold Kręcicki <wpk@isc.org>
Mon, 20 Aug 2018 09:56:37 +0000 (11:56 +0200)
committerWitold Kręcicki <wpk@isc.org>
Tue, 6 Nov 2018 11:25:09 +0000 (11:25 +0000)
lib/isc/include/isc/socket.h
lib/isc/unix/socket.c
lib/isc/win32/socket.c

index 95d70b13f15a9d4a8604ffabe846cfeddedb2238..7eea7298557c799d1340035e314f66d16ff9a5ee 100644 (file)
@@ -243,8 +243,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;
 
 /*@{*/
@@ -275,14 +274,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.
@@ -329,76 +320,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,
@@ -407,9 +328,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.
@@ -420,8 +338,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
@@ -551,17 +467,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
@@ -577,9 +488,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.
@@ -588,8 +496,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
  */
index 4ec0504496e6025f6ae5fa159fd3707a3c1ac351..5bad9ce486363004faa3ad85013f1ce8d6bae63b 100644 (file)
@@ -373,10 +373,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;
 };
 
@@ -467,8 +463,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 *);
@@ -568,19 +562,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,
@@ -1582,7 +1563,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);
        }
@@ -1782,7 +1762,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);
 
        /*
@@ -1791,25 +1770,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) {
@@ -2242,13 +2205,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);
@@ -2582,7 +2538,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)
@@ -2690,7 +2645,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
@@ -2728,112 +2682,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.
@@ -2890,7 +2738,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);
@@ -2937,27 +2784,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);
@@ -2971,27 +2811,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);
@@ -3511,88 +3344,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.
@@ -5876,8 +5627,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");
 }
index d1d465afe5bd5d2785dfbd2972b050088faa280f..8be28bfc0da6eff759112e2829fe909f5009d341 100644 (file)
@@ -1551,7 +1551,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)
@@ -1757,7 +1756,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);
 }
@@ -1789,7 +1787,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);
@@ -1815,7 +1812,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);
 }
@@ -2903,7 +2899,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);
@@ -3706,8 +3701,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");
 }