]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: protocol: add a default I/O callback and put it into the receiver
authorWilly Tarreau <w@1wt.eu>
Thu, 15 Oct 2020 19:22:29 +0000 (21:22 +0200)
committerWilly Tarreau <w@1wt.eu>
Thu, 15 Oct 2020 19:47:56 +0000 (21:47 +0200)
For now we're still using the protocol's default accept() function as
the I/O callback registered by the receiver into the poller. While
this is usable for most TCP connections where a listener is needed,
this is not suitable for UDP where a different handler is needed.

Let's make this configurable in the receiver just like the upper layer
is configurable for listeners. In order to ease stream protocols
handling, the protocols will now provide a default I/O callback
which will be preset into the receivers upon allocation so that
almost none of them has to deal with it.

include/haproxy/protocol-t.h
include/haproxy/receiver-t.h
src/listener.c

index 499609dc0e4952ec9aed2dc5dac92e4956c77e6e..5c9793b58c49d1b1be9f0385f184d43383d73e6b 100644 (file)
@@ -104,6 +104,9 @@ struct protocol {
        int (*rx_resume)(struct receiver *rx);          /* try to resume a temporarily suspended receiver */
        int (*rx_listening)(const struct receiver *rx); /* is the receiver listening ? 0=no, >0=OK, <0=unrecoverable */
 
+       /* default I/O handler */
+       void (*default_iocb)(int fd);                   /* generic I/O handler (typically accept callback) */
+
        /* functions acting on connections */
        void (*accept)(int fd);                         /* generic accept function */
        int (*connect)(struct connection *, int flags); /* connect function if any, see below for flags values */
index 6f267ba127aaa1a4f06d32141ac7b00f7e9f59f2..5b17211c4bc90e8a600c0fa7dc5b18fecc24f984 100644 (file)
@@ -59,6 +59,7 @@ struct receiver {
        unsigned int flags;              /* receiver options (RX_F_*) */
        struct protocol *proto;          /* protocol this receiver belongs to */
        void *owner;                     /* receiver's owner (usually a listener) */
+       void (*iocb)(int fd);            /* generic I/O handler (typically accept callback) */
        struct rx_settings *settings;    /* points to the settings used by this receiver */
        struct list proto_list;          /* list in the protocol header */
        /* warning: this struct is huge, keep it at the bottom */
index baf1844e4a06301134d1a89d2dbf935f0fbdafb2..1cad1bb101e5d032f668d4642837d00cb100388b 100644 (file)
@@ -588,7 +588,8 @@ void unbind_listener(struct listener *listener)
 /* creates one or multiple listeners for bind_conf <bc> on sockaddr <ss> on port
  * range <portl> to <porth>, and possibly attached to fd <fd> (or -1 for auto
  * allocation). The address family is taken from ss->ss_family, and the protocol
- * passed in <proto> must be usable on this family. The number of jobs and
+ * passed in <proto> must be usable on this family. The protocol's default iocb
+ * is automatically preset as the receivers' iocb. The number of jobs and
  * listeners is automatically increased by the number of listeners created. It
  * returns non-zero on success, zero on error with the error message set in <err>.
  */
@@ -610,6 +611,7 @@ int create_listeners(struct bind_conf *bc, const struct sockaddr_storage *ss,
                l->bind_conf = bc;
                l->rx.settings = &bc->settings;
                l->rx.owner = l;
+               l->rx.iocb = proto->default_iocb;
                l->rx.fd = fd;
                memcpy(&l->rx.addr, ss, sizeof(*ss));
                MT_LIST_INIT(&l->wait_queue);