socket.h

Go to the documentation of this file.
00001 /*
00002  * Copyright (C) 2004-2009, 2011-2014  Internet Systems Consortium, Inc. ("ISC")
00003  * Copyright (C) 1998-2002  Internet Software Consortium.
00004  *
00005  * Permission to use, copy, modify, and/or distribute this software for any
00006  * purpose with or without fee is hereby granted, provided that the above
00007  * copyright notice and this permission notice appear in all copies.
00008  *
00009  * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
00010  * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
00011  * AND FITNESS.  IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
00012  * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
00013  * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
00014  * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
00015  * PERFORMANCE OF THIS SOFTWARE.
00016  */
00017 
00018 /* $Id$ */
00019 
00020 #ifndef ISC_SOCKET_H
00021 #define ISC_SOCKET_H 1
00022 
00023 /*****
00024  ***** Module Info
00025  *****/
00026 
00027 /*! \file isc/socket.h
00028  * \brief Provides TCP and UDP sockets for network I/O.  The sockets are event
00029  * sources in the task system.
00030  *
00031  * When I/O completes, a completion event for the socket is posted to the
00032  * event queue of the task which requested the I/O.
00033  *
00034  * \li MP:
00035  *      The module ensures appropriate synchronization of data structures it
00036  *      creates and manipulates.
00037  *      Clients of this module must not be holding a socket's task's lock when
00038  *      making a call that affects that socket.  Failure to follow this rule
00039  *      can result in deadlock.
00040  *      The caller must ensure that isc_socketmgr_destroy() is called only
00041  *      once for a given manager.
00042  *
00043  * \li Reliability:
00044  *      No anticipated impact.
00045  *
00046  * \li Resources:
00047  *      TBS
00048  *
00049  * \li Security:
00050  *      No anticipated impact.
00051  *
00052  * \li Standards:
00053  *      None.
00054  */
00055 
00056 /***
00057  *** Imports
00058  ***/
00059 
00060 #include <isc/event.h>
00061 #include <isc/eventclass.h>
00062 #include <isc/lang.h>
00063 #include <isc/json.h>
00064 #include <isc/region.h>
00065 #include <isc/sockaddr.h>
00066 #include <isc/time.h>
00067 #include <isc/types.h>
00068 #include <isc/xml.h>
00069 
00070 #ifdef WIN32
00071 
00072 /* from the old namespace.h */
00073 
00074 #define isc_socket_create isc__socket_create
00075 #define isc_socket_dup isc__socket_dup
00076 #define isc_socket_attach isc__socket_attach
00077 #define isc_socket_detach isc__socket_detach
00078 #define isc_socketmgr_create isc__socketmgr_create
00079 #define isc_socketmgr_create2 isc__socketmgr_create2
00080 #define isc_socketmgr_destroy isc__socketmgr_destroy
00081 #define isc_socket_open isc__socket_open
00082 #define isc_socket_close isc__socket_close
00083 #define isc_socket_recvv isc__socket_recvv
00084 #define isc_socket_recv isc__socket_recv
00085 #define isc_socket_recv2 isc__socket_recv2
00086 #define isc_socket_send isc__socket_send
00087 #define isc_socket_sendto isc__socket_sendto
00088 #define isc_socket_sendv isc__socket_sendv
00089 #define isc_socket_sendtov isc__socket_sendtov
00090 #define isc_socket_sendtov2 isc__socket_sendtov2
00091 #define isc_socket_sendto2 isc__socket_sendto2
00092 #define isc_socket_cleanunix isc__socket_cleanunix
00093 #define isc_socket_permunix isc__socket_permunix
00094 #define isc_socket_bind isc__socket_bind
00095 #define isc_socket_filter isc__socket_filter
00096 #define isc_socket_listen isc__socket_listen
00097 #define isc_socket_accept isc__socket_accept
00098 #define isc_socket_connect isc__socket_connect
00099 #define isc_socket_getfd isc__socket_getfd
00100 #define isc_socket_getname isc__socket_getname
00101 #define isc_socket_gettag isc__socket_gettag
00102 #define isc_socket_getpeername isc__socket_getpeername
00103 #define isc_socket_getsockname isc__socket_getsockname
00104 #define isc_socket_cancel isc__socket_cancel
00105 #define isc_socket_gettype isc__socket_gettype
00106 #define isc_socket_isbound isc__socket_isbound
00107 #define isc_socket_ipv6only isc__socket_ipv6only
00108 #define isc_socket_setname isc__socket_setname
00109 #define isc_socketmgr_getmaxsockets isc__socketmgr_getmaxsockets
00110 #define isc_socketmgr_setstats isc__socketmgr_setstats
00111 #define isc_socketmgr_setreserved isc__socketmgr_setreserved
00112 #define isc__socketmgr_maxudp isc___socketmgr_maxudp
00113 #define isc_socket_fdwatchcreate isc__socket_fdwatchcreate
00114 #define isc_socket_fdwatchpoke isc__socket_fdwatchpoke
00115 #define isc_socket_dscp isc__socket_dscp
00116 
00117 #endif
00118 
00119 ISC_LANG_BEGINDECLS
00120 
00121 /***
00122  *** Constants
00123  ***/
00124 
00125 /*%
00126  * Maximum number of buffers in a scatter/gather read/write.  The operating
00127  * system in use must support at least this number (plus one on some.)
00128  */
00129 #define ISC_SOCKET_MAXSCATTERGATHER     8
00130 
00131 /*%
00132  * In isc_socket_bind() set socket option SO_REUSEADDR prior to calling
00133  * bind() if a non zero port is specified (AF_INET and AF_INET6).
00134  */
00135 #define ISC_SOCKET_REUSEADDRESS         0x01U
00136 
00137 /*%
00138  * Statistics counters.  Used as isc_statscounter_t values.
00139  */
00140 enum {
00141         isc_sockstatscounter_udp4open = 0,
00142         isc_sockstatscounter_udp6open = 1,
00143         isc_sockstatscounter_tcp4open = 2,
00144         isc_sockstatscounter_tcp6open = 3,
00145         isc_sockstatscounter_unixopen = 4,
00146 
00147         isc_sockstatscounter_udp4openfail = 5,
00148         isc_sockstatscounter_udp6openfail = 6,
00149         isc_sockstatscounter_tcp4openfail = 7,
00150         isc_sockstatscounter_tcp6openfail = 8,
00151         isc_sockstatscounter_unixopenfail = 9,
00152 
00153         isc_sockstatscounter_udp4close = 10,
00154         isc_sockstatscounter_udp6close = 11,
00155         isc_sockstatscounter_tcp4close = 12,
00156         isc_sockstatscounter_tcp6close = 13,
00157         isc_sockstatscounter_unixclose = 14,
00158         isc_sockstatscounter_fdwatchclose = 15,
00159 
00160         isc_sockstatscounter_udp4bindfail = 16,
00161         isc_sockstatscounter_udp6bindfail = 17,
00162         isc_sockstatscounter_tcp4bindfail = 18,
00163         isc_sockstatscounter_tcp6bindfail = 19,
00164         isc_sockstatscounter_unixbindfail = 20,
00165         isc_sockstatscounter_fdwatchbindfail = 21,
00166 
00167         isc_sockstatscounter_udp4connect = 22,
00168         isc_sockstatscounter_udp6connect = 23,
00169         isc_sockstatscounter_tcp4connect = 24,
00170         isc_sockstatscounter_tcp6connect = 25,
00171         isc_sockstatscounter_unixconnect = 26,
00172         isc_sockstatscounter_fdwatchconnect = 27,
00173 
00174         isc_sockstatscounter_udp4connectfail = 28,
00175         isc_sockstatscounter_udp6connectfail = 29,
00176         isc_sockstatscounter_tcp4connectfail = 30,
00177         isc_sockstatscounter_tcp6connectfail = 31,
00178         isc_sockstatscounter_unixconnectfail = 32,
00179         isc_sockstatscounter_fdwatchconnectfail = 33,
00180 
00181         isc_sockstatscounter_tcp4accept = 34,
00182         isc_sockstatscounter_tcp6accept = 35,
00183         isc_sockstatscounter_unixaccept = 36,
00184 
00185         isc_sockstatscounter_tcp4acceptfail = 37,
00186         isc_sockstatscounter_tcp6acceptfail = 38,
00187         isc_sockstatscounter_unixacceptfail = 39,
00188 
00189         isc_sockstatscounter_udp4sendfail = 40,
00190         isc_sockstatscounter_udp6sendfail = 41,
00191         isc_sockstatscounter_tcp4sendfail = 42,
00192         isc_sockstatscounter_tcp6sendfail = 43,
00193         isc_sockstatscounter_unixsendfail = 44,
00194         isc_sockstatscounter_fdwatchsendfail = 45,
00195 
00196         isc_sockstatscounter_udp4recvfail = 46,
00197         isc_sockstatscounter_udp6recvfail = 47,
00198         isc_sockstatscounter_tcp4recvfail = 48,
00199         isc_sockstatscounter_tcp6recvfail = 49,
00200         isc_sockstatscounter_unixrecvfail = 50,
00201         isc_sockstatscounter_fdwatchrecvfail = 51,
00202 
00203         isc_sockstatscounter_udp4active = 52,
00204         isc_sockstatscounter_udp6active = 53,
00205         isc_sockstatscounter_tcp4active = 54,
00206         isc_sockstatscounter_tcp6active = 55,
00207         isc_sockstatscounter_unixactive = 56,
00208 
00209         isc_sockstatscounter_rawopen = 57,
00210         isc_sockstatscounter_rawopenfail = 58,
00211         isc_sockstatscounter_rawclose = 59,
00212         isc_sockstatscounter_rawrecvfail = 60,
00213         isc_sockstatscounter_rawactive = 61,
00214 
00215         isc_sockstatscounter_max = 62
00216 };
00217 
00218 /***
00219  *** Types
00220  ***/
00221 
00222 struct isc_socketevent {
00223         ISC_EVENT_COMMON(isc_socketevent_t);
00224         isc_result_t            result;         /*%< OK, EOF, whatever else */
00225         unsigned int            minimum;        /*%< minimum i/o for event */
00226         unsigned int            n;              /*%< bytes read or written */
00227         unsigned int            offset;         /*%< offset into buffer list */
00228         isc_region_t            region;         /*%< for single-buffer i/o */
00229         isc_bufferlist_t        bufferlist;     /*%< list of buffers */
00230         isc_sockaddr_t          address;        /*%< source address */
00231         isc_time_t              timestamp;      /*%< timestamp of packet recv */
00232         struct in6_pktinfo      pktinfo;        /*%< ipv6 pktinfo */
00233         isc_uint32_t            attributes;     /*%< see below */
00234         isc_eventdestructor_t   destroy;        /*%< original destructor */
00235         unsigned int            dscp;           /*%< UDP dscp value */
00236 };
00237 
00238 typedef struct isc_socket_newconnev isc_socket_newconnev_t;
00239 struct isc_socket_newconnev {
00240         ISC_EVENT_COMMON(isc_socket_newconnev_t);
00241         isc_socket_t *          newsocket;
00242         isc_result_t            result;         /*%< OK, EOF, whatever else */
00243         isc_sockaddr_t          address;        /*%< source address */
00244 };
00245 
00246 typedef struct isc_socket_connev isc_socket_connev_t;
00247 struct isc_socket_connev {
00248         ISC_EVENT_COMMON(isc_socket_connev_t);
00249         isc_result_t            result;         /*%< OK, EOF, whatever else */
00250 };
00251 
00252 /*@{*/
00253 /*!
00254  * _ATTACHED:   Internal use only.
00255  * _TRUNC:      Packet was truncated on receive.
00256  * _CTRUNC:     Packet control information was truncated.  This can
00257  *              indicate that the packet is not complete, even though
00258  *              all the data is valid.
00259  * _TIMESTAMP:  The timestamp member is valid.
00260  * _PKTINFO:    The pktinfo member is valid.
00261  * _MULTICAST:  The UDP packet was received via a multicast transmission.
00262  * _DSCP:       The UDP DSCP value is valid.
00263  */
00264 #define ISC_SOCKEVENTATTR_ATTACHED              0x80000000U /* internal */
00265 #define ISC_SOCKEVENTATTR_TRUNC                 0x00800000U /* public */
00266 #define ISC_SOCKEVENTATTR_CTRUNC                0x00400000U /* public */
00267 #define ISC_SOCKEVENTATTR_TIMESTAMP             0x00200000U /* public */
00268 #define ISC_SOCKEVENTATTR_PKTINFO               0x00100000U /* public */
00269 #define ISC_SOCKEVENTATTR_MULTICAST             0x00080000U /* public */
00270 #define ISC_SOCKEVENTATTR_DSCP                  0x00040000U /* public */
00271 /*@}*/
00272 
00273 #define ISC_SOCKEVENT_ANYEVENT  (0)
00274 #define ISC_SOCKEVENT_RECVDONE  (ISC_EVENTCLASS_SOCKET + 1)
00275 #define ISC_SOCKEVENT_SENDDONE  (ISC_EVENTCLASS_SOCKET + 2)
00276 #define ISC_SOCKEVENT_NEWCONN   (ISC_EVENTCLASS_SOCKET + 3)
00277 #define ISC_SOCKEVENT_CONNECT   (ISC_EVENTCLASS_SOCKET + 4)
00278 
00279 /*
00280  * Internal events.
00281  */
00282 #define ISC_SOCKEVENT_INTR      (ISC_EVENTCLASS_SOCKET + 256)
00283 #define ISC_SOCKEVENT_INTW      (ISC_EVENTCLASS_SOCKET + 257)
00284 
00285 typedef enum {
00286         isc_sockettype_udp = 1,
00287         isc_sockettype_tcp = 2,
00288         isc_sockettype_unix = 3,
00289         isc_sockettype_fdwatch = 4,
00290         isc_sockettype_raw = 5
00291 } isc_sockettype_t;
00292 
00293 /*@{*/
00294 /*!
00295  * How a socket should be shutdown in isc_socket_shutdown() calls.
00296  */
00297 #define ISC_SOCKSHUT_RECV       0x00000001      /*%< close read side */
00298 #define ISC_SOCKSHUT_SEND       0x00000002      /*%< close write side */
00299 #define ISC_SOCKSHUT_ALL        0x00000003      /*%< close them all */
00300 /*@}*/
00301 
00302 /*@{*/
00303 /*!
00304  * What I/O events to cancel in isc_socket_cancel() calls.
00305  */
00306 #define ISC_SOCKCANCEL_RECV     0x00000001      /*%< cancel recv */
00307 #define ISC_SOCKCANCEL_SEND     0x00000002      /*%< cancel send */
00308 #define ISC_SOCKCANCEL_ACCEPT   0x00000004      /*%< cancel accept */
00309 #define ISC_SOCKCANCEL_CONNECT  0x00000008      /*%< cancel connect */
00310 #define ISC_SOCKCANCEL_ALL      0x0000000f      /*%< cancel everything */
00311 /*@}*/
00312 
00313 /*@{*/
00314 /*!
00315  * Flags for isc_socket_send() and isc_socket_recv() calls.
00316  */
00317 #define ISC_SOCKFLAG_IMMEDIATE  0x00000001      /*%< send event only if needed */
00318 #define ISC_SOCKFLAG_NORETRY    0x00000002      /*%< drop failed UDP sends */
00319 /*@}*/
00320 
00321 /*@{*/
00322 /*!
00323  * Flags for fdwatchcreate.
00324  */
00325 #define ISC_SOCKFDWATCH_READ    0x00000001      /*%< watch for readable */
00326 #define ISC_SOCKFDWATCH_WRITE   0x00000002      /*%< watch for writable */
00327 /*@}*/
00328 
00329 /*% Socket and socket manager methods */
00330 typedef struct isc_socketmgrmethods {
00331         void            (*destroy)(isc_socketmgr_t **managerp);
00332         isc_result_t    (*socketcreate)(isc_socketmgr_t *manager, int pf,
00333                                         isc_sockettype_t type,
00334                                         isc_socket_t **socketp);
00335         isc_result_t    (*fdwatchcreate)(isc_socketmgr_t *manager, int fd,
00336                                          int flags,
00337                                          isc_sockfdwatch_t callback,
00338                                          void *cbarg, isc_task_t *task,
00339                                          isc_socket_t **socketp);
00340 } isc_socketmgrmethods_t;
00341 
00342 typedef struct isc_socketmethods {
00343         void            (*attach)(isc_socket_t *socket,
00344                                   isc_socket_t **socketp);
00345         void            (*detach)(isc_socket_t **socketp);
00346         isc_result_t    (*bind)(isc_socket_t *sock, isc_sockaddr_t *sockaddr,
00347                                 unsigned int options);
00348         isc_result_t    (*sendto)(isc_socket_t *sock, isc_region_t *region,
00349                                   isc_task_t *task, isc_taskaction_t action,
00350                                   void *arg, isc_sockaddr_t *address,
00351                                   struct in6_pktinfo *pktinfo);
00352         isc_result_t    (*sendto2)(isc_socket_t *sock, isc_region_t *region,
00353                                    isc_task_t *task, isc_sockaddr_t *address,
00354                                    struct in6_pktinfo *pktinfo,
00355                                    isc_socketevent_t *event,
00356                                    unsigned int flags);
00357         isc_result_t    (*connect)(isc_socket_t *sock, isc_sockaddr_t *addr,
00358                                    isc_task_t *task, isc_taskaction_t action,
00359                                    void *arg);
00360         isc_result_t    (*recv)(isc_socket_t *sock, isc_region_t *region,
00361                                 unsigned int minimum, isc_task_t *task,
00362                                 isc_taskaction_t action, void *arg);
00363         isc_result_t    (*recv2)(isc_socket_t *sock, isc_region_t *region,
00364                                  unsigned int minimum, isc_task_t *task,
00365                                  isc_socketevent_t *event, unsigned int flags);
00366         void            (*cancel)(isc_socket_t *sock, isc_task_t *task,
00367                                   unsigned int how);
00368         isc_result_t    (*getsockname)(isc_socket_t *sock,
00369                                        isc_sockaddr_t *addressp);
00370         isc_sockettype_t (*gettype)(isc_socket_t *sock);
00371         void            (*ipv6only)(isc_socket_t *sock, isc_boolean_t yes);
00372         isc_result_t    (*fdwatchpoke)(isc_socket_t *sock, int flags);
00373         isc_result_t            (*dup)(isc_socket_t *socket,
00374                                   isc_socket_t **socketp);
00375         int             (*getfd)(isc_socket_t *socket);
00376         void            (*dscp)(isc_socket_t *socket, isc_dscp_t dscp);
00377 } isc_socketmethods_t;
00378 
00379 /*%
00380  * This structure is actually just the common prefix of a socket manager
00381  * object implementation's version of an isc_socketmgr_t.
00382  * \brief
00383  * Direct use of this structure by clients is forbidden.  socket implementations
00384  * may change the structure.  'magic' must be ISCAPI_SOCKETMGR_MAGIC for any
00385  * of the isc_socket_ routines to work.  socket implementations must maintain
00386  * all socket invariants.
00387  * In effect, this definition is used only for non-BIND9 version ("export")
00388  * of the library, and the export version does not work for win32.  So, to avoid
00389  * the definition conflict with win32/socket.c, we enable this definition only
00390  * for non-Win32 (i.e. Unix) platforms.
00391  */
00392 #ifndef WIN32
00393 struct isc_socketmgr {
00394         unsigned int            impmagic;
00395         unsigned int            magic;
00396         isc_socketmgrmethods_t  *methods;
00397 };
00398 #endif
00399 
00400 #define ISCAPI_SOCKETMGR_MAGIC          ISC_MAGIC('A','s','m','g')
00401 #define ISCAPI_SOCKETMGR_VALID(m)       ((m) != NULL && \
00402                                          (m)->magic == ISCAPI_SOCKETMGR_MAGIC)
00403 
00404 /*%
00405  * This is the common prefix of a socket object.  The same note as
00406  * that for the socketmgr structure applies.
00407  */
00408 #ifndef WIN32
00409 struct isc_socket {
00410         unsigned int            impmagic;
00411         unsigned int            magic;
00412         isc_socketmethods_t     *methods;
00413 };
00414 #endif
00415 
00416 #define ISCAPI_SOCKET_MAGIC     ISC_MAGIC('A','s','c','t')
00417 #define ISCAPI_SOCKET_VALID(s)  ((s) != NULL && \
00418                                  (s)->magic == ISCAPI_SOCKET_MAGIC)
00419 
00420 /***
00421  *** Socket and Socket Manager Functions
00422  ***
00423  *** Note: all Ensures conditions apply only if the result is success for
00424  *** those functions which return an isc_result.
00425  ***/
00426 
00427 isc_result_t
00428 isc_socket_fdwatchcreate(isc_socketmgr_t *manager,
00429                          int fd,
00430                          int flags,
00431                          isc_sockfdwatch_t callback,
00432                          void *cbarg,
00433                          isc_task_t *task,
00434                          isc_socket_t **socketp);
00435 /*%<
00436  * Create a new file descriptor watch socket managed by 'manager'.
00437  *
00438  * Note:
00439  *
00440  *\li   'fd' is the already-opened file descriptor.
00441  *\li   This function is not available on Windows.
00442  *\li   The callback function is called "in-line" - this means the function
00443  *      needs to return as fast as possible, as all other I/O will be suspended
00444  *      until the callback completes.
00445  *
00446  * Requires:
00447  *
00448  *\li   'manager' is a valid manager
00449  *
00450  *\li   'socketp' is a valid pointer, and *socketp == NULL
00451  *
00452  *\li   'fd' be opened.
00453  *
00454  * Ensures:
00455  *
00456  *      '*socketp' is attached to the newly created fdwatch socket
00457  *
00458  * Returns:
00459  *
00460  *\li   #ISC_R_SUCCESS
00461  *\li   #ISC_R_NOMEMORY
00462  *\li   #ISC_R_NORESOURCES
00463  *\li   #ISC_R_UNEXPECTED
00464  */
00465 
00466 isc_result_t
00467 isc_socket_fdwatchpoke(isc_socket_t *sock,
00468                        int flags);
00469 /*%<
00470  * Poke a file descriptor watch socket informing the manager that it
00471  * should restart watching the socket
00472  *
00473  * Note:
00474  *
00475  *\li   'sock' is the socket returned by isc_socket_fdwatchcreate
00476  *
00477  *\li   'flags' indicates what the manager should watch for on the socket
00478  *      in addition to what it may already be watching.  It can be one or
00479  *      both of ISC_SOCKFDWATCH_READ and ISC_SOCKFDWATCH_WRITE.  To
00480  *      temporarily disable watching on a socket the value indicating
00481  *      no more data should be returned from the call back routine.
00482  *
00483  *\li   This function is not available on Windows.
00484  *
00485  * Requires:
00486  *
00487  *\li   'sock' is a valid isc socket
00488  *
00489  *
00490  * Returns:
00491  *
00492  *\li   #ISC_R_SUCCESS
00493  */
00494 
00495 isc_result_t
00496 isc_socket_create(isc_socketmgr_t *manager,
00497                   int pf,
00498                   isc_sockettype_t type,
00499                   isc_socket_t **socketp);
00500 /*%<
00501  * Create a new 'type' socket managed by 'manager'.
00502  *
00503  * For isc_sockettype_fdwatch sockets you should use isc_socket_fdwatchcreate()
00504  * rather than isc_socket_create().
00505  *
00506  * Note:
00507  *
00508  *\li   'pf' is the desired protocol family, e.g. PF_INET or PF_INET6.
00509  *
00510  * Requires:
00511  *
00512  *\li   'manager' is a valid manager
00513  *
00514  *\li   'socketp' is a valid pointer, and *socketp == NULL
00515  *
00516  *\li   'type' is not isc_sockettype_fdwatch
00517  *
00518  * Ensures:
00519  *
00520  *      '*socketp' is attached to the newly created socket
00521  *
00522  * Returns:
00523  *
00524  *\li   #ISC_R_SUCCESS
00525  *\li   #ISC_R_NOMEMORY
00526  *\li   #ISC_R_NORESOURCES
00527  *\li   #ISC_R_UNEXPECTED
00528  */
00529 
00530 isc_result_t
00531 isc_socket_dup(isc_socket_t *sock0, isc_socket_t **socketp);
00532 /*%<
00533  * Duplicate an existing socket, reusing its file descriptor.
00534  */
00535 
00536 void
00537 isc_socket_cancel(isc_socket_t *sock, isc_task_t *task,
00538                   unsigned int how);
00539 /*%<
00540  * Cancel pending I/O of the type specified by "how".
00541  *
00542  * Note: if "task" is NULL, then the cancel applies to all tasks using the
00543  * socket.
00544  *
00545  * Requires:
00546  *
00547  * \li  "socket" is a valid socket
00548  *
00549  * \li  "task" is NULL or a valid task
00550  *
00551  * "how" is a bitmask describing the type of cancelation to perform.
00552  * The type ISC_SOCKCANCEL_ALL will cancel all pending I/O on this
00553  * socket.
00554  *
00555  * \li ISC_SOCKCANCEL_RECV:
00556  *      Cancel pending isc_socket_recv() calls.
00557  *
00558  * \li ISC_SOCKCANCEL_SEND:
00559  *      Cancel pending isc_socket_send() and isc_socket_sendto() calls.
00560  *
00561  * \li ISC_SOCKCANCEL_ACCEPT:
00562  *      Cancel pending isc_socket_accept() calls.
00563  *
00564  * \li ISC_SOCKCANCEL_CONNECT:
00565  *      Cancel pending isc_socket_connect() call.
00566  */
00567 
00568 void
00569 isc_socket_shutdown(isc_socket_t *sock, unsigned int how);
00570 /*%<
00571  * Shutdown 'socket' according to 'how'.
00572  *
00573  * Requires:
00574  *
00575  * \li  'socket' is a valid socket.
00576  *
00577  * \li  'task' is NULL or is a valid task.
00578  *
00579  * \li  If 'how' is 'ISC_SOCKSHUT_RECV' or 'ISC_SOCKSHUT_ALL' then
00580  *
00581  *              The read queue must be empty.
00582  *
00583  *              No further read requests may be made.
00584  *
00585  * \li  If 'how' is 'ISC_SOCKSHUT_SEND' or 'ISC_SOCKSHUT_ALL' then
00586  *
00587  *              The write queue must be empty.
00588  *
00589  *              No further write requests may be made.
00590  */
00591 
00592 void
00593 isc_socket_attach(isc_socket_t *sock, isc_socket_t **socketp);
00594 /*%<
00595  * Attach *socketp to socket.
00596  *
00597  * Requires:
00598  *
00599  * \li  'socket' is a valid socket.
00600  *
00601  * \li  'socketp' points to a NULL socket.
00602  *
00603  * Ensures:
00604  *
00605  * \li  *socketp is attached to socket.
00606  */
00607 
00608 void
00609 isc_socket_detach(isc_socket_t **socketp);
00610 /*%<
00611  * Detach *socketp from its socket.
00612  *
00613  * Requires:
00614  *
00615  * \li  'socketp' points to a valid socket.
00616  *
00617  * \li  If '*socketp' is the last reference to the socket,
00618  *      then:
00619  *
00620  *              There must be no pending I/O requests.
00621  *
00622  * Ensures:
00623  *
00624  * \li  *socketp is NULL.
00625  *
00626  * \li  If '*socketp' is the last reference to the socket,
00627  *      then:
00628  *
00629  *              The socket will be shutdown (both reading and writing)
00630  *              for all tasks.
00631  *
00632  *              All resources used by the socket have been freed
00633  */
00634 
00635 isc_result_t
00636 isc_socket_open(isc_socket_t *sock);
00637 /*%<
00638  * Open a new socket file descriptor of the given socket structure.  It simply
00639  * opens a new descriptor; all of the other parameters including the socket
00640  * type are inherited from the existing socket.  This function is provided to
00641  * avoid overhead of destroying and creating sockets when many short-lived
00642  * sockets are frequently opened and closed.  When the efficiency is not an
00643  * issue, it should be safer to detach the unused socket and re-create a new
00644  * one.  This optimization may not be available for some systems, in which
00645  * case this function will return ISC_R_NOTIMPLEMENTED and must not be used.
00646  *
00647  * isc_socket_open() should not be called on sockets created by
00648  * isc_socket_fdwatchcreate().
00649  *
00650  * Requires:
00651  *
00652  * \li  there must be no other reference to this socket.
00653  *
00654  * \li  'socket' is a valid and previously closed by isc_socket_close()
00655  *
00656  * \li  'sock->type' is not isc_sockettype_fdwatch
00657  *
00658  * Returns:
00659  *      Same as isc_socket_create().
00660  * \li  ISC_R_NOTIMPLEMENTED
00661  */
00662 
00663 isc_result_t
00664 isc_socket_close(isc_socket_t *sock);
00665 /*%<
00666  * Close a socket file descriptor of the given socket structure.  This function
00667  * is provided as an alternative to destroying an unused socket when overhead
00668  * destroying/re-creating sockets can be significant, and is expected to be
00669  * used with isc_socket_open().  This optimization may not be available for some
00670  * systems, in which case this function will return ISC_R_NOTIMPLEMENTED and
00671  * must not be used.
00672  *
00673  * isc_socket_close() should not be called on sockets created by
00674  * isc_socket_fdwatchcreate().
00675  *
00676  * Requires:
00677  *
00678  * \li  The socket must have a valid descriptor.
00679  *
00680  * \li  There must be no other reference to this socket.
00681  *
00682  * \li  There must be no pending I/O requests.
00683  *
00684  * \li  'sock->type' is not isc_sockettype_fdwatch
00685  *
00686  * Returns:
00687  * \li  #ISC_R_NOTIMPLEMENTED
00688  */
00689 
00690 isc_result_t
00691 isc_socket_bind(isc_socket_t *sock, isc_sockaddr_t *addressp,
00692                 unsigned int options);
00693 /*%<
00694  * Bind 'socket' to '*addressp'.
00695  *
00696  * Requires:
00697  *
00698  * \li  'socket' is a valid socket
00699  *
00700  * \li  'addressp' points to a valid isc_sockaddr.
00701  *
00702  * Returns:
00703  *
00704  * \li  ISC_R_SUCCESS
00705  * \li  ISC_R_NOPERM
00706  * \li  ISC_R_ADDRNOTAVAIL
00707  * \li  ISC_R_ADDRINUSE
00708  * \li  ISC_R_BOUND
00709  * \li  ISC_R_UNEXPECTED
00710  */
00711 
00712 isc_result_t
00713 isc_socket_filter(isc_socket_t *sock, const char *filter);
00714 /*%<
00715  * Inform the kernel that it should perform accept filtering.
00716  * If filter is NULL the current filter will be removed.:w
00717  */
00718 
00719 isc_result_t
00720 isc_socket_listen(isc_socket_t *sock, unsigned int backlog);
00721 /*%<
00722  * Set listen mode on the socket.  After this call, the only function that
00723  * can be used (other than attach and detach) is isc_socket_accept().
00724  *
00725  * Notes:
00726  *
00727  * \li  'backlog' is as in the UNIX system call listen() and may be
00728  *      ignored by non-UNIX implementations.
00729  *
00730  * \li  If 'backlog' is zero, a reasonable system default is used, usually
00731  *      SOMAXCONN.
00732  *
00733  * Requires:
00734  *
00735  * \li  'socket' is a valid, bound TCP socket or a valid, bound UNIX socket.
00736  *
00737  * Returns:
00738  *
00739  * \li  ISC_R_SUCCESS
00740  * \li  ISC_R_UNEXPECTED
00741  */
00742 
00743 isc_result_t
00744 isc_socket_accept(isc_socket_t *sock,
00745                   isc_task_t *task, isc_taskaction_t action, void *arg);
00746 /*%<
00747  * Queue accept event.  When a new connection is received, the task will
00748  * get an ISC_SOCKEVENT_NEWCONN event with the sender set to the listen
00749  * socket.  The new socket structure is sent inside the isc_socket_newconnev_t
00750  * event type, and is attached to the task 'task'.
00751  *
00752  * REQUIRES:
00753  * \li  'socket' is a valid TCP socket that isc_socket_listen() was called
00754  *      on.
00755  *
00756  * \li  'task' is a valid task
00757  *
00758  * \li  'action' is a valid action
00759  *
00760  * RETURNS:
00761  * \li  ISC_R_SUCCESS
00762  * \li  ISC_R_NOMEMORY
00763  * \li  ISC_R_UNEXPECTED
00764  */
00765 
00766 isc_result_t
00767 isc_socket_connect(isc_socket_t *sock, isc_sockaddr_t *addressp,
00768                    isc_task_t *task, isc_taskaction_t action,
00769                    void *arg);
00770 /*%<
00771  * Connect 'socket' to peer with address *saddr.  When the connection
00772  * succeeds, or when an error occurs, a CONNECT event with action 'action'
00773  * and arg 'arg' will be posted to the event queue for 'task'.
00774  *
00775  * Requires:
00776  *
00777  * \li  'socket' is a valid TCP socket
00778  *
00779  * \li  'addressp' points to a valid isc_sockaddr
00780  *
00781  * \li  'task' is a valid task
00782  *
00783  * \li  'action' is a valid action
00784  *
00785  * Returns:
00786  *
00787  * \li  ISC_R_SUCCESS
00788  * \li  ISC_R_NOMEMORY
00789  * \li  ISC_R_UNEXPECTED
00790  *
00791  * Posted event's result code:
00792  *
00793  * \li  ISC_R_SUCCESS
00794  * \li  ISC_R_TIMEDOUT
00795  * \li  ISC_R_CONNREFUSED
00796  * \li  ISC_R_NETUNREACH
00797  * \li  ISC_R_UNEXPECTED
00798  */
00799 
00800 isc_result_t
00801 isc_socket_getpeername(isc_socket_t *sock, isc_sockaddr_t *addressp);
00802 /*%<
00803  * Get the name of the peer connected to 'socket'.
00804  *
00805  * Requires:
00806  *
00807  * \li  'socket' is a valid TCP socket.
00808  *
00809  * Returns:
00810  *
00811  * \li  ISC_R_SUCCESS
00812  * \li  ISC_R_TOOSMALL
00813  * \li  ISC_R_UNEXPECTED
00814  */
00815 
00816 isc_result_t
00817 isc_socket_getsockname(isc_socket_t *sock, isc_sockaddr_t *addressp);
00818 /*%<
00819  * Get the name of 'socket'.
00820  *
00821  * Requires:
00822  *
00823  * \li  'socket' is a valid socket.
00824  *
00825  * Returns:
00826  *
00827  * \li  ISC_R_SUCCESS
00828  * \li  ISC_R_TOOSMALL
00829  * \li  ISC_R_UNEXPECTED
00830  */
00831 
00832 /*@{*/
00833 isc_result_t
00834 isc_socket_recv(isc_socket_t *sock, isc_region_t *region,
00835                 unsigned int minimum,
00836                 isc_task_t *task, isc_taskaction_t action, void *arg);
00837 isc_result_t
00838 isc_socket_recvv(isc_socket_t *sock, isc_bufferlist_t *buflist,
00839                  unsigned int minimum,
00840                  isc_task_t *task, isc_taskaction_t action, void *arg);
00841 
00842 isc_result_t
00843 isc_socket_recv2(isc_socket_t *sock, isc_region_t *region,
00844                  unsigned int minimum, isc_task_t *task,
00845                  isc_socketevent_t *event, unsigned int flags);
00846 
00847 /*!
00848  * Receive from 'socket', storing the results in region.
00849  *
00850  * Notes:
00851  *
00852  *\li   Let 'length' refer to the length of 'region' or to the sum of all
00853  *      available regions in the list of buffers '*buflist'.
00854  *
00855  *\li   If 'minimum' is non-zero and at least that many bytes are read,
00856  *      the completion event will be posted to the task 'task.'  If minimum
00857  *      is zero, the exact number of bytes requested in the region must
00858  *      be read for an event to be posted.  This only makes sense for TCP
00859  *      connections, and is always set to 1 byte for UDP.
00860  *
00861  *\li   The read will complete when the desired number of bytes have been
00862  *      read, if end-of-input occurs, or if an error occurs.  A read done
00863  *      event with the given 'action' and 'arg' will be posted to the
00864  *      event queue of 'task'.
00865  *
00866  *\li   The caller may not modify 'region', the buffers which are passed
00867  *      into this function, or any data they refer to until the completion
00868  *      event is received.
00869  *
00870  *\li   For isc_socket_recvv():
00871  *      On successful completion, '*buflist' will be empty, and the list of
00872  *      all buffers will be returned in the done event's 'bufferlist'
00873  *      member.  On error return, '*buflist' will be unchanged.
00874  *
00875  *\li   For isc_socket_recv2():
00876  *      'event' is not NULL, and the non-socket specific fields are
00877  *      expected to be initialized.
00878  *
00879  *\li   For isc_socket_recv2():
00880  *      The only defined value for 'flags' is ISC_SOCKFLAG_IMMEDIATE.  If
00881  *      set and the operation completes, the return value will be
00882  *      ISC_R_SUCCESS and the event will be filled in and not sent.  If the
00883  *      operation does not complete, the return value will be
00884  *      ISC_R_INPROGRESS and the event will be sent when the operation
00885  *      completes.
00886  *
00887  * Requires:
00888  *
00889  *\li   'socket' is a valid, bound socket.
00890  *
00891  *\li   For isc_socket_recv():
00892  *      'region' is a valid region
00893  *
00894  *\li   For isc_socket_recvv():
00895  *      'buflist' is non-NULL, and '*buflist' contain at least one buffer.
00896  *
00897  *\li   'task' is a valid task
00898  *
00899  *\li   For isc_socket_recv() and isc_socket_recvv():
00900  *      action != NULL and is a valid action
00901  *
00902  *\li   For isc_socket_recv2():
00903  *      event != NULL
00904  *
00905  * Returns:
00906  *
00907  *\li   #ISC_R_SUCCESS
00908  *\li   #ISC_R_INPROGRESS
00909  *\li   #ISC_R_NOMEMORY
00910  *\li   #ISC_R_UNEXPECTED
00911  *
00912  * Event results:
00913  *
00914  *\li   #ISC_R_SUCCESS
00915  *\li   #ISC_R_UNEXPECTED
00916  *\li   XXX needs other net-type errors
00917  */
00918 /*@}*/
00919 
00920 /*@{*/
00921 isc_result_t
00922 isc_socket_send(isc_socket_t *sock, isc_region_t *region,
00923                 isc_task_t *task, isc_taskaction_t action, void *arg);
00924 isc_result_t
00925 isc_socket_sendto(isc_socket_t *sock, isc_region_t *region,
00926                   isc_task_t *task, isc_taskaction_t action, void *arg,
00927                   isc_sockaddr_t *address, struct in6_pktinfo *pktinfo);
00928 isc_result_t
00929 isc_socket_sendv(isc_socket_t *sock, isc_bufferlist_t *buflist,
00930                  isc_task_t *task, isc_taskaction_t action, void *arg);
00931 isc_result_t
00932 isc_socket_sendtov(isc_socket_t *sock, isc_bufferlist_t *buflist,
00933                    isc_task_t *task, isc_taskaction_t action, void *arg,
00934                    isc_sockaddr_t *address, struct in6_pktinfo *pktinfo);
00935 isc_result_t
00936 isc_socket_sendtov2(isc_socket_t *sock, isc_bufferlist_t *buflist,
00937                     isc_task_t *task, isc_taskaction_t action, void *arg,
00938                     isc_sockaddr_t *address, struct in6_pktinfo *pktinfo,
00939                     unsigned int flags);
00940 isc_result_t
00941 isc_socket_sendto2(isc_socket_t *sock, isc_region_t *region,
00942                    isc_task_t *task,
00943                    isc_sockaddr_t *address, struct in6_pktinfo *pktinfo,
00944                    isc_socketevent_t *event, unsigned int flags);
00945 
00946 /*!
00947  * Send the contents of 'region' to the socket's peer.
00948  *
00949  * Notes:
00950  *
00951  *\li   Shutting down the requestor's task *may* result in any
00952  *      still pending writes being dropped or completed, depending on the
00953  *      underlying OS implementation.
00954  *
00955  *\li   If 'action' is NULL, then no completion event will be posted.
00956  *
00957  *\li   The caller may not modify 'region', the buffers which are passed
00958  *      into this function, or any data they refer to until the completion
00959  *      event is received.
00960  *
00961  *\li   For isc_socket_sendv() and isc_socket_sendtov():
00962  *      On successful completion, '*buflist' will be empty, and the list of
00963  *      all buffers will be returned in the done event's 'bufferlist'
00964  *      member.  On error return, '*buflist' will be unchanged.
00965  *
00966  *\li   For isc_socket_sendto2():
00967  *      'event' is not NULL, and the non-socket specific fields are
00968  *      expected to be initialized.
00969  *
00970  *\li   For isc_socket_sendto2():
00971  *      The only defined values for 'flags' are ISC_SOCKFLAG_IMMEDIATE
00972  *      and ISC_SOCKFLAG_NORETRY.
00973  *
00974  *\li   If ISC_SOCKFLAG_IMMEDIATE is set and the operation completes, the
00975  *      return value will be ISC_R_SUCCESS and the event will be filled
00976  *      in and not sent.  If the operation does not complete, the return
00977  *      value will be ISC_R_INPROGRESS and the event will be sent when
00978  *      the operation completes.
00979  *
00980  *\li   ISC_SOCKFLAG_NORETRY can only be set for UDP sockets.  If set
00981  *      and the send operation fails due to a transient error, the send
00982  *      will not be retried and the error will be indicated in the event.
00983  *      Using this option along with ISC_SOCKFLAG_IMMEDIATE allows the caller
00984  *      to specify a region that is allocated on the stack.
00985  *
00986  * Requires:
00987  *
00988  *\li   'socket' is a valid, bound socket.
00989  *
00990  *\li   For isc_socket_send():
00991  *      'region' is a valid region
00992  *
00993  *\li   For isc_socket_sendv() and isc_socket_sendtov():
00994  *      'buflist' is non-NULL, and '*buflist' contain at least one buffer.
00995  *
00996  *\li   'task' is a valid task
00997  *
00998  *\li   For isc_socket_sendv(), isc_socket_sendtov(), isc_socket_send(), and
00999  *      isc_socket_sendto():
01000  *      action == NULL or is a valid action
01001  *
01002  *\li   For isc_socket_sendto2():
01003  *      event != NULL
01004  *
01005  * Returns:
01006  *
01007  *\li   #ISC_R_SUCCESS
01008  *\li   #ISC_R_INPROGRESS
01009  *\li   #ISC_R_NOMEMORY
01010  *\li   #ISC_R_UNEXPECTED
01011  *
01012  * Event results:
01013  *
01014  *\li   #ISC_R_SUCCESS
01015  *\li   #ISC_R_UNEXPECTED
01016  *\li   XXX needs other net-type errors
01017  */
01018 /*@}*/
01019 
01020 isc_result_t
01021 isc_socketmgr_createinctx(isc_mem_t *mctx, isc_appctx_t *actx,
01022                           isc_socketmgr_t **managerp);
01023 
01024 isc_result_t
01025 isc_socketmgr_create(isc_mem_t *mctx, isc_socketmgr_t **managerp);
01026 
01027 isc_result_t
01028 isc_socketmgr_create2(isc_mem_t *mctx, isc_socketmgr_t **managerp,
01029                       unsigned int maxsocks);
01030 /*%<
01031  * Create a socket manager.  If "maxsocks" is non-zero, it specifies the
01032  * maximum number of sockets that the created manager should handle.
01033  * isc_socketmgr_create() is equivalent of isc_socketmgr_create2() with
01034  * "maxsocks" being zero.
01035  * isc_socketmgr_createinctx() also associates the new manager with the
01036  * specified application context.
01037  *
01038  * Notes:
01039  *
01040  *\li   All memory will be allocated in memory context 'mctx'.
01041  *
01042  * Requires:
01043  *
01044  *\li   'mctx' is a valid memory context.
01045  *
01046  *\li   'managerp' points to a NULL isc_socketmgr_t.
01047  *
01048  *\li   'actx' is a valid application context (for createinctx()).
01049  *
01050  * Ensures:
01051  *
01052  *\li   '*managerp' is a valid isc_socketmgr_t.
01053  *
01054  * Returns:
01055  *
01056  *\li   #ISC_R_SUCCESS
01057  *\li   #ISC_R_NOMEMORY
01058  *\li   #ISC_R_UNEXPECTED
01059  *\li   #ISC_R_NOTIMPLEMENTED
01060  */
01061 
01062 isc_result_t
01063 isc_socketmgr_getmaxsockets(isc_socketmgr_t *manager, unsigned int *nsockp);
01064 /*%<
01065  * Returns in "*nsockp" the maximum number of sockets this manager may open.
01066  *
01067  * Requires:
01068  *
01069  *\li   '*manager' is a valid isc_socketmgr_t.
01070  *\li   'nsockp' is not NULL.
01071  *
01072  * Returns:
01073  *
01074  *\li   #ISC_R_SUCCESS
01075  *\li   #ISC_R_NOTIMPLEMENTED
01076  */
01077 
01078 void
01079 isc_socketmgr_setstats(isc_socketmgr_t *manager, isc_stats_t *stats);
01080 /*%<
01081  * Set a general socket statistics counter set 'stats' for 'manager'.
01082  *
01083  * Requires:
01084  * \li  'manager' is valid, hasn't opened any socket, and doesn't have
01085  *      stats already set.
01086  *
01087  *\li   stats is a valid statistics supporting socket statistics counters
01088  *      (see above).
01089  */
01090 
01091 void
01092 isc_socketmgr_destroy(isc_socketmgr_t **managerp);
01093 /*%<
01094  * Destroy a socket manager.
01095  *
01096  * Notes:
01097  *
01098  *\li   This routine blocks until there are no sockets left in the manager,
01099  *      so if the caller holds any socket references using the manager, it
01100  *      must detach them before calling isc_socketmgr_destroy() or it will
01101  *      block forever.
01102  *
01103  * Requires:
01104  *
01105  *\li   '*managerp' is a valid isc_socketmgr_t.
01106  *
01107  *\li   All sockets managed by this manager are fully detached.
01108  *
01109  * Ensures:
01110  *
01111  *\li   *managerp == NULL
01112  *
01113  *\li   All resources used by the manager have been freed.
01114  */
01115 
01116 isc_sockettype_t
01117 isc_socket_gettype(isc_socket_t *sock);
01118 /*%<
01119  * Returns the socket type for "sock."
01120  *
01121  * Requires:
01122  *
01123  *\li   "sock" is a valid socket.
01124  */
01125 
01126 /*@{*/
01127 isc_boolean_t
01128 isc__socket_isbound(isc_socket_t *sock);
01129 /*%
01130  * Intended for internal use in BIND9 only
01131  */
01132 
01133 void
01134 isc_socket_ipv6only(isc_socket_t *sock, isc_boolean_t yes);
01135 /*%<
01136  * If the socket is an IPv6 socket set/clear the IPV6_IPV6ONLY socket
01137  * option if the host OS supports this option.
01138  *
01139  * Requires:
01140  *\li   'sock' is a valid socket.
01141  */
01142 /*@}*/
01143 
01144 void
01145 isc_socket_dscp(isc_socket_t *sock, isc_dscp_t dscp);
01146 /*%<
01147  * Sets the Differentiated Services Code Point (DSCP) field for packets
01148  * transmitted on this socket.  If 'dscp' is -1, return immediately.
01149  *
01150  * Requires:
01151  *\li   'sock' is a valid socket.
01152  */
01153 
01154 isc_socketevent_t *
01155 isc_socket_socketevent(isc_mem_t *mctx, void *sender,
01156                        isc_eventtype_t eventtype, isc_taskaction_t action,
01157                        void *arg);
01158 /*%<
01159  * Get a isc_socketevent_t to be used with isc_socket_sendto2(), etc.
01160  */
01161 
01162 void
01163 isc_socket_cleanunix(isc_sockaddr_t *addr, isc_boolean_t active);
01164 
01165 /*%<
01166  * Cleanup UNIX domain sockets in the file-system.  If 'active' is true
01167  * then just unlink the socket.  If 'active' is false try to determine
01168  * if there is a listener of the socket or not.  If no listener is found
01169  * then unlink socket.
01170  *
01171  * Prior to unlinking the path is tested to see if it a socket.
01172  *
01173  * Note: there are a number of race conditions which cannot be avoided
01174  *       both in the filesystem and any application using UNIX domain
01175  *       sockets (e.g. socket is tested between bind() and listen(),
01176  *       the socket is deleted and replaced in the file-system between
01177  *       stat() and unlink()).
01178  */
01179 
01180 isc_result_t
01181 isc_socket_permunix(isc_sockaddr_t *sockaddr, isc_uint32_t perm,
01182                     isc_uint32_t owner, isc_uint32_t group);
01183 /*%<
01184  * Set ownership and file permissions on the UNIX domain socket.
01185  *
01186  * Note: On Solaris and SunOS this secures the directory containing
01187  *       the socket as Solaris and SunOS do not honour the filesystem
01188  *       permissions on the socket.
01189  *
01190  * Requires:
01191  * \li  'sockaddr' to be a valid UNIX domain sockaddr.
01192  *
01193  * Returns:
01194  * \li  #ISC_R_SUCCESS
01195  * \li  #ISC_R_FAILURE
01196  */
01197 
01198 void isc_socket_setname(isc_socket_t *socket, const char *name, void *tag);
01199 /*%<
01200  * Set the name and optional tag for a socket.  This allows tracking of the
01201  * owner or purpose for this socket, and is useful for tracing and statistics
01202  * reporting.
01203  */
01204 
01205 const char *isc_socket_getname(isc_socket_t *socket);
01206 /*%<
01207  * Get the name associated with a socket, if any.
01208  */
01209 
01210 void *isc_socket_gettag(isc_socket_t *socket);
01211 /*%<
01212  * Get the tag associated with a socket, if any.
01213  */
01214 
01215 int isc_socket_getfd(isc_socket_t *socket);
01216 /*%<
01217  * Get the file descriptor associated with a socket
01218  */
01219 
01220 void
01221 isc__socketmgr_setreserved(isc_socketmgr_t *mgr, isc_uint32_t);
01222 /*%<
01223  * Temporary.  For use by named only.
01224  */
01225 
01226 void
01227 isc__socketmgr_maxudp(isc_socketmgr_t *mgr, int maxudp);
01228 /*%<
01229  * Test interface. Drop UDP packet > 'maxudp'.
01230  */
01231 
01232 #ifdef HAVE_LIBXML2
01233 int
01234 isc_socketmgr_renderxml(isc_socketmgr_t *mgr, xmlTextWriterPtr writer);
01235 /*%<
01236  * Render internal statistics and other state into the XML document.
01237  */
01238 #endif /* HAVE_LIBXML2 */
01239 
01240 #ifdef HAVE_JSON
01241 isc_result_t
01242 isc_socketmgr_renderjson(isc_socketmgr_t *mgr, json_object *stats);
01243 /*%<
01244  * Render internal statistics and other state into JSON format.
01245  */
01246 #endif /* HAVE_JSON */
01247 
01248 /*%<
01249  * See isc_socketmgr_create() above.
01250  */
01251 typedef isc_result_t
01252 (*isc_socketmgrcreatefunc_t)(isc_mem_t *mctx, isc_socketmgr_t **managerp);
01253 
01254 isc_result_t
01255 isc_socket_register(isc_socketmgrcreatefunc_t createfunc);
01256 /*%<
01257  * Register a new socket I/O implementation and add it to the list of
01258  * supported implementations.  This function must be called when a different
01259  * event library is used than the one contained in the ISC library.
01260  */
01261 
01262 isc_result_t
01263 isc__socket_register(void);
01264 /*%<
01265  * A short cut function that specifies the socket I/O module in the ISC
01266  * library for isc_socket_register().  An application that uses the ISC library
01267  * usually do not have to care about this function: it would call
01268  * isc_lib_register(), which internally calls this function.
01269  */
01270 
01271 ISC_LANG_ENDDECLS
01272 
01273 #endif /* ISC_SOCKET_H */

Generated on Tue Apr 28 17:41:04 2015 by Doxygen 1.5.4 for BIND9 Internals 9.11.0pre-alpha