MINOR: protocol: add a set of ctrl_init/ctrl_close methods for setup/teardown
Currnetly conn_ctrl_init() does an fd_insert() and conn_ctrl_close() does an fd_delete(). These are the two only short-term obstacles against using a non-fd handle to set up a connection. Let's have pur these into the protocol layer, along with the other connection-level stuff so that the generic connection code uses them instead. This will allow to define new ones for other protocols (e.g. QUIC). Since we only support regular sockets at the moment, the code was placed into sock.c and shared with proto_tcp, proto_uxst and proto_sockpair.
This commit is contained in:
parent
b366c9a59a
commit
de471c4655
@ -96,6 +96,8 @@ struct protocol {
|
||||
int (*resume)(struct listener *l); /* try to resume a suspended listener */
|
||||
struct connection *(*accept_conn)(struct listener *l, int *status); /* accept a new connection */
|
||||
/* functions acting on connections */
|
||||
void (*ctrl_init)(struct connection *); /* completes initialization of the connection */
|
||||
void (*ctrl_close)(struct connection *); /* completes release of the connection */
|
||||
int (*connect)(struct connection *, int flags); /* connect function if any, see below for flags values */
|
||||
|
||||
/* functions acting on the receiver */
|
||||
|
@ -43,6 +43,8 @@ int sock_find_compatible_fd(const struct receiver *rx);
|
||||
int sock_accepting_conn(const struct receiver *rx);
|
||||
struct connection *sock_accept_conn(struct listener *l, int *status);
|
||||
void sock_accept_iocb(int fd);
|
||||
void sock_conn_ctrl_init(struct connection *conn);
|
||||
void sock_conn_ctrl_close(struct connection *conn);
|
||||
|
||||
#endif /* _HAPROXY_SOCK_H */
|
||||
|
||||
|
@ -74,6 +74,8 @@ struct protocol proto_sockpair = {
|
||||
.add = default_add_listener,
|
||||
.unbind = default_unbind_listener,
|
||||
.accept_conn = sockpair_accept_conn,
|
||||
.ctrl_init = sock_conn_ctrl_init,
|
||||
.ctrl_close = sock_conn_ctrl_close,
|
||||
.connect = sockpair_connect_server,
|
||||
|
||||
/* binding layer */
|
||||
|
@ -64,6 +64,8 @@ struct protocol proto_tcpv4 = {
|
||||
.suspend = default_suspend_listener,
|
||||
.resume = default_resume_listener,
|
||||
.accept_conn = sock_accept_conn,
|
||||
.ctrl_init = sock_conn_ctrl_init,
|
||||
.ctrl_close = sock_conn_ctrl_close,
|
||||
.connect = tcp_connect_server,
|
||||
|
||||
/* binding layer */
|
||||
@ -101,6 +103,8 @@ struct protocol proto_tcpv6 = {
|
||||
.suspend = default_suspend_listener,
|
||||
.resume = default_resume_listener,
|
||||
.accept_conn = sock_accept_conn,
|
||||
.ctrl_init = sock_conn_ctrl_init,
|
||||
.ctrl_close = sock_conn_ctrl_close,
|
||||
.connect = tcp_connect_server,
|
||||
|
||||
/* binding layer */
|
||||
|
@ -60,6 +60,8 @@ struct protocol proto_uxst = {
|
||||
.unbind = default_unbind_listener,
|
||||
.suspend = default_suspend_listener,
|
||||
.accept_conn = sock_accept_conn,
|
||||
.ctrl_init = sock_conn_ctrl_init,
|
||||
.ctrl_close = sock_conn_ctrl_close,
|
||||
.connect = uxst_connect_server,
|
||||
|
||||
/* binding layer */
|
||||
|
19
src/sock.c
19
src/sock.c
@ -625,6 +625,25 @@ void sock_accept_iocb(int fd)
|
||||
listener_accept(l);
|
||||
}
|
||||
|
||||
/* This completes the initialization of connection <conn> by inserting its FD
|
||||
* into the fdtab, associating it with the regular connection handler. It will
|
||||
* be bound to the current thread only. This call cannot fail.
|
||||
*/
|
||||
void sock_conn_ctrl_init(struct connection *conn)
|
||||
{
|
||||
fd_insert(conn->handle.fd, conn, conn_fd_handler, tid_bit);
|
||||
}
|
||||
|
||||
/* This completes the release of connection <conn> by removing its FD from the
|
||||
* fdtab and deleting it. The connection must not use the FD anymore past this
|
||||
* point. The FD may be modified in the connection.
|
||||
*/
|
||||
void sock_conn_ctrl_close(struct connection *conn)
|
||||
{
|
||||
fd_delete(conn->handle.fd);
|
||||
conn->handle.fd = DEAD_FD_MAGIC;
|
||||
}
|
||||
|
||||
/*
|
||||
* Local variables:
|
||||
* c-indent-level: 8
|
||||
|
Loading…
x
Reference in New Issue
Block a user