]> git.ipfire.org Git - thirdparty/bind9.git/commitdiff
Updates to fdwatch code to support DHCP/DDNS code, ticket rt20253.
authorShawn Routhier <sar@isc.org>
Thu, 1 Oct 2009 01:30:01 +0000 (01:30 +0000)
committerShawn Routhier <sar@isc.org>
Thu, 1 Oct 2009 01:30:01 +0000 (01:30 +0000)
CHANGES
lib/isc/include/isc/msgs.h
lib/isc/include/isc/namespace.h
lib/isc/include/isc/socket.h
lib/isc/include/isc/types.h
lib/isc/socket_api.c
lib/isc/unix/socket.c

diff --git a/CHANGES b/CHANGES
index c23002338e4e5fdcae4fab0e71a3d4130bbef217..0e32dd900e19ec4af0d35faf63eccb2230d2d762 100644 (file)
--- a/CHANGES
+++ b/CHANGES
@@ -1,3 +1,10 @@
+2695.  [func]          DHCP/DDNS - update fdwatch code for use by
+                       DHCP.  Modify the api to isc_sockfdwatch_t (the
+                       callback funciton for isc_socket_fdwatchcreate)
+                       to include information about the direction (read
+                       or write) and add isc_socket_fdwatchpoke.
+                       [RT #20253]
+
 2694.  [bug]           Reduce default NSEC3 iterations from 100 to 10.
                        [RT #19970]
 
index d8f2787a28a4ebdfd15d05546604bb58340456a2..14d0967a1dbfaf67d2f4e9be5f3752d57b26fdad 100644 (file)
@@ -15,7 +15,7 @@
  * PERFORMANCE OF THIS SOFTWARE.
  */
 
-/* $Id: msgs.h,v 1.17 2008/08/08 06:28:59 tbox Exp $ */
+/* $Id: msgs.h,v 1.18 2009/10/01 01:30:01 sar Exp $ */
 
 #ifndef ISC_MSGS_H
 #define ISC_MSGS_H 1
 #define ISC_MSG_FILTER        1421 /*%< setsockopt(SO_ACCEPTFILTER): %s */
 
 #define ISC_MSG_TOOMANYHANDLES 1422 /*%< %s: too many open WSA event handles: %s */
-
+#define ISC_MSG_POKED          1423 /*%< "poked flags: %d" */
 
 #define ISC_MSG_AWAKE         1502 /*%< "awake" */
 #define ISC_MSG_WORKING               1503 /*%< "working" */
index 33ec63a38fdaaa99f1e28d28cf038a6a9081f6a5..4fa05ac4ef1bbf4e3652ddb0a5035efab13ae339 100644 (file)
@@ -14,7 +14,7 @@
  * PERFORMANCE OF THIS SOFTWARE.
  */
 
-/* $Id: namespace.h,v 1.4 2009/09/02 23:48:03 tbox Exp $ */
+/* $Id: namespace.h,v 1.5 2009/10/01 01:30:01 sar Exp $ */
 
 #ifndef ISCAPI_NAMESPACE_H
 #define ISCAPI_NAMESPACE_H 1
 #define isc_socket_listen isc__socket_listen
 #define isc_socket_accept isc__socket_accept
 #define isc_socket_connect isc__socket_connect
-#define isc_socket_fdwatchcreate isc__socket_fdwatchcreate
 #define isc_socket_getname isc__socket_getname
 #define isc_socket_gettag isc__socket_gettag
 #define isc_socket_getpeername isc__socket_getpeername
 #define isc_socketmgr_setstats isc__socketmgr_setstats
 #define isc_socketmgr_setreserved isc__socketmgr_setreserved
 #define isc__socketmgr_maxudp isc___socketmgr_maxudp
+#define isc_socket_fdwatchcreate isc__socket_fdwatchcreate
+#define isc_socket_fdwatchpoke isc__socket_fdwatchpoke
 
 #define isc_task_create isc__task_create
 #define isc_task_attach isc__task_attach
index 376dcc09ad231faaf907349bebbd803e8d2b6c08..c4ab0e29591d0677955e509489268ed9bf36b89d 100644 (file)
@@ -15,7 +15,7 @@
  * PERFORMANCE OF THIS SOFTWARE.
  */
 
-/* $Id: socket.h,v 1.93 2009/09/02 23:43:54 each Exp $ */
+/* $Id: socket.h,v 1.94 2009/10/01 01:30:01 sar Exp $ */
 
 #ifndef ISC_SOCKET_H
 #define ISC_SOCKET_H 1
@@ -266,6 +266,11 @@ typedef struct isc_socketmgrmethods {
        isc_result_t    (*socketcreate)(isc_socketmgr_t *manager, int pf,
                                        isc_sockettype_t type,
                                        isc_socket_t **socketp);
+       isc_result_t    (*fdwatchcreate)(isc_socketmgr_t *manager, int fd,
+                                        int flags,
+                                        isc_sockfdwatch_t callback,
+                                        void *cbarg, isc_task_t *task,
+                                        isc_socket_t **socketp);
 } isc_socketmgrmethods_t;
 
 typedef struct isc_socketmethods {
@@ -290,6 +295,7 @@ typedef struct isc_socketmethods {
                                       isc_sockaddr_t *addressp);
        isc_sockettype_t (*gettype)(isc_socket_t *sock);
        void            (*ipv6only)(isc_socket_t *sock, isc_boolean_t yes);
+       isc_result_t    (*fdwatchpoke)(isc_socket_t *sock, int flags);
 } isc_socketmethods_t;
 
 /*%
@@ -379,6 +385,35 @@ isc_socket_fdwatchcreate(isc_socketmgr_t *manager,
  *\li  #ISC_R_UNEXPECTED
  */
 
+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,
index 03ada89a1c0c57c7d9da9c6e7ce7acf1905855fe..906bad176fc9adc6970608181828444b4d275778 100644 (file)
@@ -15,7 +15,7 @@
  * PERFORMANCE OF THIS SOFTWARE.
  */
 
-/* $Id: types.h,v 1.50 2009/09/01 18:40:25 jinmei Exp $ */
+/* $Id: types.h,v 1.51 2009/10/01 01:30:01 sar Exp $ */
 
 #ifndef ISC_TYPES_H
 #define ISC_TYPES_H 1
@@ -98,7 +98,7 @@ typedef struct isc_timer              isc_timer_t;            /*%< Timer */
 typedef struct isc_timermgr            isc_timermgr_t;         /*%< Timer Manager */
 
 typedef void (*isc_taskaction_t)(isc_task_t *, isc_event_t *);
-typedef int (*isc_sockfdwatch_t)(isc_task_t *, isc_socket_t *, void *);
+typedef int (*isc_sockfdwatch_t)(isc_task_t *, isc_socket_t *, void *, int);
 
 /* The following cannot be listed alphabetically due to forward reference */
 typedef isc_result_t (isc_httpdaction_t)(const char *url,
index 8ba206070c5fcabdcf1c030c76d37c2a39ce1bb8..95075f5a65932cc115696b1e9943bbfbe4c05c95 100644 (file)
@@ -14,7 +14,7 @@
  * PERFORMANCE OF THIS SOFTWARE.
  */
 
-/* $Id: socket_api.c,v 1.4 2009/09/02 23:48:02 tbox Exp $ */
+/* $Id: socket_api.c,v 1.5 2009/10/01 01:30:01 sar Exp $ */
 
 #include <config.h>
 
@@ -194,3 +194,23 @@ isc_socket_setname(isc_socket_t *socket, const char *name, void *tag) {
        UNUSED(name);
        UNUSED(tag);
 }
+
+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)
+{
+       REQUIRE(ISCAPI_SOCKETMGR_VALID(manager));
+
+       return (manager->methods->fdwatchcreate(manager, fd, flags,
+                                               callback, cbarg, task,
+                                               socketp));
+}
+
+isc_result_t
+isc_socket_fdwatchpoke(isc_socket_t *sock, int flags)
+{
+       REQUIRE(ISCAPI_SOCKET_VALID(sock));
+
+       return(sock->methods->fdwatchpoke(sock, flags));
+}
index e2e06934ee0830b777d1c6ff9e1d3a29231b7426..663a03ab101d3a4b64d37ed4f7c87f05d76f008b 100644 (file)
@@ -15,7 +15,7 @@
  * PERFORMANCE OF THIS SOFTWARE.
  */
 
-/* $Id: socket.c,v 1.324 2009/09/07 02:08:51 marka Exp $ */
+/* $Id: socket.c,v 1.325 2009/10/01 01:30:01 sar Exp $ */
 
 /*! \file */
 
@@ -535,6 +535,13 @@ ISC_SOCKETFUNC_SCOPE void
 isc__socketmgr_renderxml(isc_socketmgr_t *mgr0, xmlTextWriterPtr writer);
 #endif
 
+ISC_SOCKETFUNC_SCOPE 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);
+ISC_SOCKETFUNC_SCOPE isc_result_t
+isc__socket_fdwatchpoke(isc_socket_t *sock, int flags);
+
 static struct {
        isc_socketmethods_t methods;
 
@@ -556,7 +563,8 @@ static struct {
                isc__socket_cancel,
                isc__socket_getsockname,
                isc__socket_gettype,
-               isc__socket_ipv6only
+               isc__socket_ipv6only,
+               isc__socket_fdwatchpoke
        }
 #ifndef BIND9
        ,
@@ -571,7 +579,8 @@ static struct {
 
 static isc_socketmgrmethods_t socketmgrmethods = {
        isc__socketmgr_destroy,
-       isc__socket_create
+       isc__socket_create,
+       isc__socket_fdwatchcreate
 };
 
 #define SELECT_POKE_SHUTDOWN           (-1)
@@ -2553,6 +2562,7 @@ isc__socket_open(isc_socket_t *sock0) {
 
        return (result);
 }
+#endif /* BIND9 */
 
 /*
  * Create a new 'type' socket managed by 'manager'.  Events
@@ -2617,7 +2627,29 @@ isc__socket_fdwatchcreate(isc_socketmgr_t *manager0, int fd, int flags,
 
        return (ISC_R_SUCCESS);
 }
-#endif /* BIND9 */
+
+/* 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_SOCKETFUNC_SCOPE isc_result_t
+isc__socket_fdwatchpoke(isc_socket_t *sock0, int flags)
+{
+       isc__socket_t *sock = (isc__socket_t *)sock0;
+
+       REQUIRE(VALID_SOCKET(sock));
+
+       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, 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.
@@ -3276,7 +3308,7 @@ internal_fdwatch_write(isc_task_t *me, isc_event_t *ev) {
 
        UNLOCK(&sock->lock);
        more_data = (sock->fdwatchcb)(me, (isc_socket_t *)sock,
-                                     sock->fdwatcharg);
+                                     sock->fdwatcharg, ISC_SOCKFDWATCH_WRITE);
        LOCK(&sock->lock);
 
        sock->pending_send = 0;
@@ -3317,7 +3349,7 @@ internal_fdwatch_read(isc_task_t *me, isc_event_t *ev) {
 
        UNLOCK(&sock->lock);
        more_data = (sock->fdwatchcb)(me, (isc_socket_t *)sock,
-                                     sock->fdwatcharg);
+                                     sock->fdwatcharg, ISC_SOCKFDWATCH_READ);
        LOCK(&sock->lock);
 
        sock->pending_recv = 0;