]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: protocol: add a set of ctrl_init/ctrl_close methods for setup/teardown
authorWilly Tarreau <w@1wt.eu>
Tue, 8 Dec 2020 14:50:56 +0000 (15:50 +0100)
committerWilly Tarreau <w@1wt.eu>
Tue, 8 Dec 2020 14:50:56 +0000 (15:50 +0100)
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.

include/haproxy/protocol-t.h
include/haproxy/sock.h
src/proto_sockpair.c
src/proto_tcp.c
src/proto_uxst.c
src/sock.c

index 137a09af5401eed642a5a6109585f927283d80b5..5205de690159ff36f7feb265c59ea69b3efecee9 100644 (file)
@@ -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 */
index 6e81b1b22bfb13e1be585aee47dbd3ac258306f8..6c9b7b7d6d7b51946474a189786fc6fd03b8a058 100644 (file)
@@ -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 */
 
index d3a6b98849e9bf436d6f31c74efdabe247185026..7124f565f57a434b62317f673c8ce4b8ff2a03f6 100644 (file)
@@ -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 */
index 19651c0fdf4aa8a091d97a92c9b5df83e2c9876c..4a5e9c21640b57aa58eddc5bbd960811de8f1a8b 100644 (file)
@@ -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 */
index 1714e101db34bd8063f0baf30d8e370660632e93..1c6ea77dcd3fd41863a056438ab8e9abdfa72e4f 100644 (file)
@@ -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 */
index 9eff7f1049010942a1d7f1b5ad34277523685a2a..c7a5f80f709d8aa1a45b4e91a0ab91fbb1df8128 100644 (file)
@@ -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