mirror of
http://git.haproxy.org/git/haproxy.git/
synced 2025-03-24 03:47:02 +00:00
MINOR: protocol: add a default I/O callback and put it into the receiver
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.
This commit is contained in:
parent
caa91de718
commit
d2fb99f9d5
@ -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 */
|
||||
|
@ -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 */
|
||||
|
@ -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);
|
||||
|
Loading…
Reference in New Issue
Block a user