REORG/MEDIUM: connection: introduce the notion of connection handle
authorWilly Tarreau <w@1wt.eu>
Thu, 24 Aug 2017 12:31:19 +0000 (14:31 +0200)
committerWilly Tarreau <w@1wt.eu>
Thu, 24 Aug 2017 17:30:04 +0000 (19:30 +0200)
Till now connections used to rely exclusively on file descriptors. It
was planned in the past that alternative solutions would be implemented,
leading to member "union t" presenting sock.fd only for now.

With QUIC, the connection will need to continue to exist but will not
rely on a file descriptor but a connection ID.

So this patch introduces a "connection handle" which is either a file
descriptor or a connection ID, to replace the existing "union t". We've
now removed the intermediate "struct sock" which was never used. There
is no functional change at all, though the struct connection was inflated
by 32 bits on 64-bit platforms due to alignment.

14 files changed:
include/proto/connection.h
include/types/connection.h
src/checks.c
src/cli.c
src/connection.c
src/frontend.c
src/hlua.c
src/proto_http.c
src/proto_tcp.c
src/proto_uxst.c
src/raw_sock.c
src/session.c
src/ssl_sock.c
src/stream.c

index 9b02594..66887a5 100644 (file)
@@ -106,7 +106,7 @@ static inline void conn_xprt_close(struct connection *conn)
 static inline void conn_ctrl_init(struct connection *conn)
 {
        if (!conn_ctrl_ready(conn)) {
-               int fd = conn->t.sock.fd;
+               int fd = conn->handle.fd;
 
                fd_insert(fd);
                /* mark the fd as ready so as not to needlessly poll at the beginning */
@@ -124,7 +124,7 @@ static inline void conn_ctrl_init(struct connection *conn)
 static inline void conn_ctrl_close(struct connection *conn)
 {
        if ((conn->flags & (CO_FL_XPRT_READY|CO_FL_CTRL_READY)) == CO_FL_CTRL_READY) {
-               fd_delete(conn->t.sock.fd);
+               fd_delete(conn->handle.fd);
                conn->flags &= ~CO_FL_CTRL_READY;
        }
 }
@@ -151,9 +151,9 @@ static inline void conn_force_close(struct connection *conn)
                conn->xprt->close(conn);
 
        if (conn_ctrl_ready(conn))
-               fd_delete(conn->t.sock.fd);
+               fd_delete(conn->handle.fd);
 
-       conn->t.sock.fd = DEAD_FD_MAGIC;
+       conn->handle.fd = DEAD_FD_MAGIC;
        conn->flags &= ~(CO_FL_XPRT_READY|CO_FL_CTRL_READY);
 }
 
@@ -183,9 +183,9 @@ static inline void conn_refresh_polling_flags(struct connection *conn)
        if (conn_ctrl_ready(conn)) {
                unsigned int flags = conn->flags & ~(CO_FL_CURR_RD_ENA | CO_FL_CURR_WR_ENA);
 
-               if (fd_recv_active(conn->t.sock.fd))
+               if (fd_recv_active(conn->handle.fd))
                        flags |= CO_FL_CURR_RD_ENA;
-               if (fd_send_active(conn->t.sock.fd))
+               if (fd_send_active(conn->handle.fd))
                        flags |= CO_FL_CURR_WR_ENA;
                conn->flags = flags;
        }
@@ -264,7 +264,7 @@ static inline void conn_stop_polling(struct connection *c)
                      CO_FL_SOCK_RD_ENA | CO_FL_SOCK_WR_ENA |
                      CO_FL_DATA_RD_ENA | CO_FL_DATA_WR_ENA);
        if (conn_ctrl_ready(c))
-               fd_stop_both(c->t.sock.fd);
+               fd_stop_both(c->handle.fd);
 }
 
 /* Automatically update polling on connection <c> depending on the DATA and
@@ -304,7 +304,7 @@ static inline void __conn_data_stop_recv(struct connection *c)
  */
 static inline int __conn_data_done_recv(struct connection *c)
 {
-       if (!conn_ctrl_ready(c) || !fd_recv_polled(c->t.sock.fd)) {
+       if (!conn_ctrl_ready(c) || !fd_recv_polled(c->handle.fd)) {
                c->flags &= ~CO_FL_DATA_RD_ENA;
                return 1;
        }
@@ -425,7 +425,7 @@ static inline void conn_sock_read0(struct connection *c)
         * zero from the other side.
         */
        if (conn_ctrl_ready(c))
-               fdtab[c->t.sock.fd].linger_risk = 0;
+               fdtab[c->handle.fd].linger_risk = 0;
 }
 
 static inline void conn_data_read0(struct connection *c)
@@ -439,7 +439,7 @@ static inline void conn_sock_shutw(struct connection *c)
        c->flags |= CO_FL_SOCK_WR_SH;
        __conn_sock_stop_send(c);
        if (conn_ctrl_ready(c))
-               shutdown(c->t.sock.fd, SHUT_WR);
+               shutdown(c->handle.fd, SHUT_WR);
 }
 
 static inline void conn_data_shutw(struct connection *c)
@@ -497,7 +497,7 @@ static inline void conn_init(struct connection *conn)
        conn->data = NULL;
        conn->owner = NULL;
        conn->send_proxy_ofs = 0;
-       conn->t.sock.fd = DEAD_FD_MAGIC;
+       conn->handle.fd = DEAD_FD_MAGIC;
        conn->err_code = CO_ER_NONE;
        conn->target = NULL;
        conn->proxy_netns = NULL;
@@ -534,7 +534,7 @@ static inline void conn_get_from_addr(struct connection *conn)
        if (!conn_ctrl_ready(conn) || !conn->ctrl->get_src)
                return;
 
-       if (conn->ctrl->get_src(conn->t.sock.fd, (struct sockaddr *)&conn->addr.from,
+       if (conn->ctrl->get_src(conn->handle.fd, (struct sockaddr *)&conn->addr.from,
                                sizeof(conn->addr.from),
                                obj_type(conn->target) != OBJ_TYPE_LISTENER) == -1)
                return;
@@ -550,7 +550,7 @@ static inline void conn_get_to_addr(struct connection *conn)
        if (!conn_ctrl_ready(conn) || !conn->ctrl->get_dst)
                return;
 
-       if (conn->ctrl->get_dst(conn->t.sock.fd, (struct sockaddr *)&conn->addr.to,
+       if (conn->ctrl->get_dst(conn->handle.fd, (struct sockaddr *)&conn->addr.to,
                                sizeof(conn->addr.to),
                                obj_type(conn->target) != OBJ_TYPE_LISTENER) == -1)
                return;
index 7da0a7a..59b8cff 100644 (file)
@@ -42,6 +42,15 @@ struct buffer;
 struct server;
 struct pipe;
 
+
+/* A connection handle is how we differenciate two connections on the lower
+ * layers. It usually is a file descriptor but can be a connection id.
+ */
+union conn_handle {
+       int fd;                 /* file descriptor, for regular sockets */
+};
+
+
 /* For each direction, we have a CO_FL_{SOCK,DATA}_<DIR>_ENA flag, which
  * indicates if read or write is desired in that direction for the respective
  * layers. The current status corresponding to the current layer being used is
@@ -293,12 +302,7 @@ struct connection {
        void *xprt_ctx;               /* general purpose pointer, initialized to NULL */
        void *owner;                  /* pointer to upper layer's entity (eg: stream interface) */
        int xprt_st;                  /* transport layer state, initialized to zero */
-
-       union {                       /* definitions which depend on connection type */
-               struct {              /*** information used by socket-based connections ***/
-                       int fd;       /* file descriptor for a stream driver when known */
-               } sock;
-       } t;
+       union conn_handle handle;     /* connection handle at the socket layer */
        enum obj_type *target;        /* the target to connect to (server, proxy, applet, ...) */
        struct list list;             /* attach point to various connection lists (idle, ...) */
        const struct netns_entry *proxy_netns;
index fc92a24..ca18220 100644 (file)
@@ -573,7 +573,7 @@ static int retrieve_errno_from_socket(struct connection *conn)
        if (!conn_ctrl_ready(conn))
                return 0;
 
-       if (getsockopt(conn->t.sock.fd, SOL_SOCKET, SO_ERROR, &skerr, &lskerr) == 0)
+       if (getsockopt(conn->handle.fd, SOL_SOCKET, SO_ERROR, &skerr, &lskerr) == 0)
                errno = skerr;
 
        if (errno == EAGAIN)
@@ -2986,7 +2986,7 @@ const char *init_check(struct check *check, int type)
                return "out of memory while allocating check connection";
        }
 
-       check->conn->t.sock.fd = -1; /* no agent in progress yet */
+       check->conn->handle.fd = -1; /* no agent in progress yet */
 
        return NULL;
 }
index 6172b48..77db681 100644 (file)
--- a/src/cli.c
+++ b/src/cli.c
@@ -1173,7 +1173,7 @@ static int _getsocks(char **args, struct appctx *appctx, void *private)
        int tot_fd_nb = 0;
        struct proxy *px;
        int i = 0;
-       int fd = remote->t.sock.fd;
+       int fd = remote->handle.fd;
        int curoff = 0;
        int old_fcntl;
        int ret;
index 0c90c3b..564c976 100644 (file)
@@ -181,21 +181,21 @@ void conn_update_data_polling(struct connection *c)
 
        /* update read status if needed */
        if (unlikely((f & (CO_FL_CURR_RD_ENA|CO_FL_DATA_RD_ENA)) == CO_FL_DATA_RD_ENA)) {
-               fd_want_recv(c->t.sock.fd);
+               fd_want_recv(c->handle.fd);
                f |= CO_FL_CURR_RD_ENA;
        }
        else if (unlikely((f & (CO_FL_CURR_RD_ENA|CO_FL_DATA_RD_ENA)) == CO_FL_CURR_RD_ENA)) {
-               fd_stop_recv(c->t.sock.fd);
+               fd_stop_recv(c->handle.fd);
                f &= ~CO_FL_CURR_RD_ENA;
        }
 
        /* update write status if needed */
        if (unlikely((f & (CO_FL_CURR_WR_ENA|CO_FL_DATA_WR_ENA)) == CO_FL_DATA_WR_ENA)) {
-               fd_want_send(c->t.sock.fd);
+               fd_want_send(c->handle.fd);
                f |= CO_FL_CURR_WR_ENA;
        }
        else if (unlikely((f & (CO_FL_CURR_WR_ENA|CO_FL_DATA_WR_ENA)) == CO_FL_CURR_WR_ENA)) {
-               fd_stop_send(c->t.sock.fd);
+               fd_stop_send(c->handle.fd);
                f &= ~CO_FL_CURR_WR_ENA;
        }
        c->flags = f;
@@ -216,21 +216,21 @@ void conn_update_sock_polling(struct connection *c)
 
        /* update read status if needed */
        if (unlikely((f & (CO_FL_CURR_RD_ENA|CO_FL_SOCK_RD_ENA)) == CO_FL_SOCK_RD_ENA)) {
-               fd_want_recv(c->t.sock.fd);
+               fd_want_recv(c->handle.fd);
                f |= CO_FL_CURR_RD_ENA;
        }
        else if (unlikely((f & (CO_FL_CURR_RD_ENA|CO_FL_SOCK_RD_ENA)) == CO_FL_CURR_RD_ENA)) {
-               fd_stop_recv(c->t.sock.fd);
+               fd_stop_recv(c->handle.fd);
                f &= ~CO_FL_CURR_RD_ENA;
        }
 
        /* update write status if needed */
        if (unlikely((f & (CO_FL_CURR_WR_ENA|CO_FL_SOCK_WR_ENA)) == CO_FL_SOCK_WR_ENA)) {
-               fd_want_send(c->t.sock.fd);
+               fd_want_send(c->handle.fd);
                f |= CO_FL_CURR_WR_ENA;
        }
        else if (unlikely((f & (CO_FL_CURR_WR_ENA|CO_FL_SOCK_WR_ENA)) == CO_FL_CURR_WR_ENA)) {
-               fd_stop_send(c->t.sock.fd);
+               fd_stop_send(c->handle.fd);
                f &= ~CO_FL_CURR_WR_ENA;
        }
        c->flags = f;
@@ -265,11 +265,11 @@ int conn_sock_send(struct connection *conn, const void *buf, int len, int flags)
        if (!len)
                goto fail;
 
-       if (!fd_send_ready(conn->t.sock.fd))
+       if (!fd_send_ready(conn->handle.fd))
                goto wait;
 
        do {
-               ret = send(conn->t.sock.fd, buf, len, flags | MSG_DONTWAIT | MSG_NOSIGNAL);
+               ret = send(conn->handle.fd, buf, len, flags | MSG_DONTWAIT | MSG_NOSIGNAL);
        } while (ret < 0 && errno == EINTR);
 
 
@@ -278,7 +278,7 @@ int conn_sock_send(struct connection *conn, const void *buf, int len, int flags)
 
        if (ret == 0 || errno == EAGAIN || errno == ENOTCONN) {
        wait:
-               fd_cant_send(conn->t.sock.fd);
+               fd_cant_send(conn->handle.fd);
                return 0;
        }
  fail:
@@ -301,11 +301,11 @@ int conn_sock_drain(struct connection *conn)
        if (conn->flags & (CO_FL_ERROR | CO_FL_SOCK_RD_SH))
                return 1;
 
-       if (fdtab[conn->t.sock.fd].ev & (FD_POLL_ERR|FD_POLL_HUP)) {
-               fdtab[conn->t.sock.fd].linger_risk = 0;
+       if (fdtab[conn->handle.fd].ev & (FD_POLL_ERR|FD_POLL_HUP)) {
+               fdtab[conn->handle.fd].linger_risk = 0;
        }
        else {
-               if (!fd_recv_ready(conn->t.sock.fd))
+               if (!fd_recv_ready(conn->handle.fd))
                        return 0;
 
                /* disable draining if we were called and have no drain function */
@@ -314,7 +314,7 @@ int conn_sock_drain(struct connection *conn)
                        return 0;
                }
 
-               if (conn->ctrl->drain(conn->t.sock.fd) <= 0)
+               if (conn->ctrl->drain(conn->handle.fd) <= 0)
                        return 0;
        }
 
@@ -368,16 +368,16 @@ int conn_recv_proxy(struct connection *conn, int flag)
        if (!conn_ctrl_ready(conn))
                goto fail;
 
-       if (!fd_recv_ready(conn->t.sock.fd))
+       if (!fd_recv_ready(conn->handle.fd))
                return 0;
 
        do {
-               trash.len = recv(conn->t.sock.fd, trash.str, trash.size, MSG_PEEK);
+               trash.len = recv(conn->handle.fd, trash.str, trash.size, MSG_PEEK);
                if (trash.len < 0) {
                        if (errno == EINTR)
                                continue;
                        if (errno == EAGAIN) {
-                               fd_cant_recv(conn->t.sock.fd);
+                               fd_cant_recv(conn->handle.fd);
                                return 0;
                        }
                        goto recv_abort;
@@ -609,7 +609,7 @@ int conn_recv_proxy(struct connection *conn, int flag)
         * fail.
         */
        do {
-               int len2 = recv(conn->t.sock.fd, trash.str, trash.len, 0);
+               int len2 = recv(conn->handle.fd, trash.str, trash.len, 0);
                if (len2 < 0 && errno == EINTR)
                        continue;
                if (len2 != trash.len)
@@ -680,16 +680,16 @@ int conn_recv_netscaler_cip(struct connection *conn, int flag)
        if (!conn_ctrl_ready(conn))
                goto fail;
 
-       if (!fd_recv_ready(conn->t.sock.fd))
+       if (!fd_recv_ready(conn->handle.fd))
                return 0;
 
        do {
-               trash.len = recv(conn->t.sock.fd, trash.str, trash.size, MSG_PEEK);
+               trash.len = recv(conn->handle.fd, trash.str, trash.size, MSG_PEEK);
                if (trash.len < 0) {
                        if (errno == EINTR)
                                continue;
                        if (errno == EAGAIN) {
-                               fd_cant_recv(conn->t.sock.fd);
+                               fd_cant_recv(conn->handle.fd);
                                return 0;
                        }
                        goto recv_abort;
@@ -807,7 +807,7 @@ int conn_recv_netscaler_cip(struct connection *conn, int flag)
         * result, we fail.
         */
        do {
-               int len2 = recv(conn->t.sock.fd, trash.str, trash.len, 0);
+               int len2 = recv(conn->handle.fd, trash.str, trash.len, 0);
                if (len2 < 0 && errno == EINTR)
                        continue;
                if (len2 != trash.len)
index 8e2bf2f..be40e5f 100644 (file)
@@ -115,13 +115,13 @@ int frontend_accept(struct stream *s)
                case AF_INET:
                case AF_INET6:
                        chunk_printf(&trash, "%08x:%s.accept(%04x)=%04x from [%s:%d] ALPN=%s\n",
-                                    s->uniq_id, fe->id, (unsigned short)l->fd, (unsigned short)conn->t.sock.fd,
+                                    s->uniq_id, fe->id, (unsigned short)l->fd, (unsigned short)conn->handle.fd,
                                     pn, get_host_port(&conn->addr.from), alpn);
                        break;
                case AF_UNIX:
                        /* UNIX socket, only the destination is known */
                        chunk_printf(&trash, "%08x:%s.accept(%04x)=%04x from [unix:%d] ALPN=%s\n",
-                                    s->uniq_id, fe->id, (unsigned short)l->fd, (unsigned short)conn->t.sock.fd,
+                                    s->uniq_id, fe->id, (unsigned short)l->fd, (unsigned short)conn->handle.fd,
                                     l->luid, alpn);
                        break;
                }
index 6f941f4..0f82425 100644 (file)
@@ -5091,7 +5091,7 @@ __LJMP static int hlua_txn_set_tos(lua_State *L)
        tos = MAY_LJMP(luaL_checkinteger(L, 2));
 
        if ((cli_conn = objt_conn(htxn->s->sess->origin)) && conn_ctrl_ready(cli_conn))
-               inet_set_tos(cli_conn->t.sock.fd, &cli_conn->addr.from, tos);
+               inet_set_tos(cli_conn->handle.fd, &cli_conn->addr.from, tos);
 
        return 0;
 }
@@ -5108,7 +5108,7 @@ __LJMP static int hlua_txn_set_mark(lua_State *L)
        mark = MAY_LJMP(luaL_checkinteger(L, 2));
 
        if ((cli_conn = objt_conn(htxn->s->sess->origin)) && conn_ctrl_ready(cli_conn))
-               setsockopt(cli_conn->t.sock.fd, SOL_SOCKET, SO_MARK, &mark, sizeof(mark));
+               setsockopt(cli_conn->handle.fd, SOL_SOCKET, SO_MARK, &mark, sizeof(mark));
 #endif
        return 0;
 }
index 2b9b0d0..439e57f 100644 (file)
@@ -2809,7 +2809,7 @@ int http_wait_for_request(struct stream *s, struct channel *req, int an_bit)
                         * previously disabled it, otherwise we might cause the client
                         * to delay next data.
                         */
-                       setsockopt(__objt_conn(sess->origin)->t.sock.fd, IPPROTO_TCP, TCP_QUICKACK, &one, sizeof(one));
+                       setsockopt(__objt_conn(sess->origin)->handle.fd, IPPROTO_TCP, TCP_QUICKACK, &one, sizeof(one));
                }
 #endif
 
@@ -3517,13 +3517,13 @@ resume_execution:
 
                case ACT_HTTP_SET_TOS:
                        if ((cli_conn = objt_conn(sess->origin)) && conn_ctrl_ready(cli_conn))
-                               inet_set_tos(cli_conn->t.sock.fd, &cli_conn->addr.from, rule->arg.tos);
+                               inet_set_tos(cli_conn->handle.fd, &cli_conn->addr.from, rule->arg.tos);
                        break;
 
                case ACT_HTTP_SET_MARK:
 #ifdef SO_MARK
                        if ((cli_conn = objt_conn(sess->origin)) && conn_ctrl_ready(cli_conn))
-                               setsockopt(cli_conn->t.sock.fd, SOL_SOCKET, SO_MARK, &rule->arg.mark, sizeof(rule->arg.mark));
+                               setsockopt(cli_conn->handle.fd, SOL_SOCKET, SO_MARK, &rule->arg.mark, sizeof(rule->arg.mark));
 #endif
                        break;
 
@@ -3786,13 +3786,13 @@ resume_execution:
 
                case ACT_HTTP_SET_TOS:
                        if ((cli_conn = objt_conn(sess->origin)) && conn_ctrl_ready(cli_conn))
-                               inet_set_tos(cli_conn->t.sock.fd, &cli_conn->addr.from, rule->arg.tos);
+                               inet_set_tos(cli_conn->handle.fd, &cli_conn->addr.from, rule->arg.tos);
                        break;
 
                case ACT_HTTP_SET_MARK:
 #ifdef SO_MARK
                        if ((cli_conn = objt_conn(sess->origin)) && conn_ctrl_ready(cli_conn))
-                               setsockopt(cli_conn->t.sock.fd, SOL_SOCKET, SO_MARK, &rule->arg.mark, sizeof(rule->arg.mark));
+                               setsockopt(cli_conn->handle.fd, SOL_SOCKET, SO_MARK, &rule->arg.mark, sizeof(rule->arg.mark));
 #endif
                        break;
 
@@ -4817,7 +4817,7 @@ int http_process_request(struct stream *s, struct channel *req, int an_bit)
            cli_conn && conn_ctrl_ready(cli_conn) &&
            ((msg->flags & HTTP_MSGF_TE_CHNK) ||
             (msg->body_len > req->buf->i - txn->req.eoh - 2)))
-               setsockopt(cli_conn->t.sock.fd, IPPROTO_TCP, TCP_QUICKACK, &one, sizeof(one));
+               setsockopt(cli_conn->handle.fd, IPPROTO_TCP, TCP_QUICKACK, &one, sizeof(one));
 #endif
 
        /*************************************************************
@@ -8818,8 +8818,8 @@ void debug_hdr(const char *dir, struct stream *s, const char *start, const char
 
        chunk_printf(&trash, "%08x:%s.%s[%04x:%04x]: ", s->uniq_id, s->be->id,
                      dir,
-                    objt_conn(sess->origin) ? (unsigned short)objt_conn(sess->origin)->t.sock.fd : -1,
-                    objt_conn(s->si[1].end) ? (unsigned short)objt_conn(s->si[1].end)->t.sock.fd : -1);
+                    objt_conn(sess->origin) ? (unsigned short)objt_conn(sess->origin)->handle.fd : -1,
+                    objt_conn(s->si[1].end) ? (unsigned short)objt_conn(s->si[1].end)->handle.fd : -1);
 
        for (max = 0; start + max < end; max++)
                if (start[max] == '\r' || start[max] == '\n')
index 57d6fc1..2bbde7a 100644 (file)
@@ -302,7 +302,7 @@ int tcp_connect_server(struct connection *conn, int data, int delack)
                return SF_ERR_INTERNAL;
        }
 
-       fd = conn->t.sock.fd = create_server_socket(conn);
+       fd = conn->handle.fd = create_server_socket(conn);
 
        if (fd == -1) {
                qfprintf(stderr, "Cannot get a server socket.\n");
@@ -669,7 +669,7 @@ int tcp_drain(int fd)
  */
 int tcp_connect_probe(struct connection *conn)
 {
-       int fd = conn->t.sock.fd;
+       int fd = conn->handle.fd;
        socklen_t lskerr;
        int skerr;
 
@@ -1326,7 +1326,7 @@ static enum act_return tcp_exec_action_silent_drop(struct act_rule *rule, struct
        /* re-enable quickack if it was disabled to ack all data and avoid
         * retransmits from the client that might trigger a real reset.
         */
-       setsockopt(conn->t.sock.fd, SOL_TCP, TCP_QUICKACK, &one, sizeof(one));
+       setsockopt(conn->handle.fd, SOL_TCP, TCP_QUICKACK, &one, sizeof(one));
 #endif
        /* lingering must absolutely be disabled so that we don't send a
         * shutdown(), this is critical to the TCP_REPAIR trick. When no stream
@@ -1338,10 +1338,10 @@ static enum act_return tcp_exec_action_silent_drop(struct act_rule *rule, struct
        /* We're on the client-facing side, we must force to disable lingering to
         * ensure we will use an RST exclusively and kill any pending data.
         */
-       fdtab[conn->t.sock.fd].linger_risk = 1;
+       fdtab[conn->handle.fd].linger_risk = 1;
 
 #ifdef TCP_REPAIR
-       if (setsockopt(conn->t.sock.fd, SOL_TCP, TCP_REPAIR, &one, sizeof(one)) == 0) {
+       if (setsockopt(conn->handle.fd, SOL_TCP, TCP_REPAIR, &one, sizeof(one)) == 0) {
                /* socket will be quiet now */
                goto out;
        }
@@ -1351,7 +1351,7 @@ static enum act_return tcp_exec_action_silent_drop(struct act_rule *rule, struct
         * network and has no effect on local net.
         */
 #ifdef IP_TTL
-       setsockopt(conn->t.sock.fd, SOL_IP, IP_TTL, &one, sizeof(one));
+       setsockopt(conn->handle.fd, SOL_IP, IP_TTL, &one, sizeof(one));
 #endif
  out:
        /* kill the stream if any */
@@ -1597,7 +1597,7 @@ static inline int get_tcp_info(const struct arg *args, struct sample *smp,
        /* The fd may not be avalaible for the tcp_info struct, and the
          syscal can fail. */
        optlen = sizeof(info);
-       if (getsockopt(conn->t.sock.fd, SOL_TCP, TCP_INFO, &info, &optlen) == -1)
+       if (getsockopt(conn->handle.fd, SOL_TCP, TCP_INFO, &info, &optlen) == -1)
                return 0;
 
        /* extract the value. */
index 5aa45a7..ac14d3b 100644 (file)
@@ -439,7 +439,7 @@ int uxst_connect_server(struct connection *conn, int data, int delack)
                return SF_ERR_INTERNAL;
        }
 
-       if ((fd = conn->t.sock.fd = socket(PF_UNIX, SOCK_STREAM, 0)) == -1) {
+       if ((fd = conn->handle.fd = socket(PF_UNIX, SOCK_STREAM, 0)) == -1) {
                qfprintf(stderr, "Cannot get a server socket.\n");
 
                if (errno == ENFILE) {
index 707ba55..406fef3 100644 (file)
@@ -78,7 +78,7 @@ int raw_sock_to_pipe(struct connection *conn, struct pipe *pipe, unsigned int co
        if (!conn_ctrl_ready(conn))
                return 0;
 
-       if (!fd_recv_ready(conn->t.sock.fd))
+       if (!fd_recv_ready(conn->handle.fd))
                return 0;
 
        errno = 0;
@@ -87,13 +87,13 @@ int raw_sock_to_pipe(struct connection *conn, struct pipe *pipe, unsigned int co
         * Since older splice() implementations were buggy and returned
         * EAGAIN on end of read, let's bypass the call to splice() now.
         */
-       if (unlikely(!(fdtab[conn->t.sock.fd].ev & FD_POLL_IN))) {
+       if (unlikely(!(fdtab[conn->handle.fd].ev & FD_POLL_IN))) {
                /* stop here if we reached the end of data */
-               if ((fdtab[conn->t.sock.fd].ev & (FD_POLL_ERR|FD_POLL_HUP)) == FD_POLL_HUP)
+               if ((fdtab[conn->handle.fd].ev & (FD_POLL_ERR|FD_POLL_HUP)) == FD_POLL_HUP)
                        goto out_read0;
 
                /* report error on POLL_ERR before connection establishment */
-               if ((fdtab[conn->t.sock.fd].ev & FD_POLL_ERR) && (conn->flags & CO_FL_WAIT_L4_CONN)) {
+               if ((fdtab[conn->handle.fd].ev & FD_POLL_ERR) && (conn->flags & CO_FL_WAIT_L4_CONN)) {
                        conn->flags |= CO_FL_ERROR | CO_FL_SOCK_RD_SH | CO_FL_SOCK_WR_SH;
                        errno = 0; /* let the caller do a getsockopt() if it wants it */
                        return retval;
@@ -104,7 +104,7 @@ int raw_sock_to_pipe(struct connection *conn, struct pipe *pipe, unsigned int co
                if (count > MAX_SPLICE_AT_ONCE)
                        count = MAX_SPLICE_AT_ONCE;
 
-               ret = splice(conn->t.sock.fd, NULL, pipe->prod, NULL, count,
+               ret = splice(conn->handle.fd, NULL, pipe->prod, NULL, count,
                             SPLICE_F_MOVE|SPLICE_F_NONBLOCK);
 
                if (ret <= 0) {
@@ -148,7 +148,7 @@ int raw_sock_to_pipe(struct connection *conn, struct pipe *pipe, unsigned int co
 #ifndef ASSUME_SPLICE_WORKS
                                if (splice_detects_close)
 #endif
-                                       fd_cant_recv(conn->t.sock.fd); /* we know for sure that it's EAGAIN */
+                                       fd_cant_recv(conn->handle.fd); /* we know for sure that it's EAGAIN */
                                break;
                        }
                        else if (errno == ENOSYS || errno == EINVAL || errno == EBADF) {
@@ -176,7 +176,7 @@ int raw_sock_to_pipe(struct connection *conn, struct pipe *pipe, unsigned int co
                         * being asked to poll.
                         */
                        conn->flags |= CO_FL_WAIT_ROOM;
-                       fd_done_recv(conn->t.sock.fd);
+                       fd_done_recv(conn->handle.fd);
                        break;
                }
        } /* while */
@@ -200,17 +200,17 @@ int raw_sock_from_pipe(struct connection *conn, struct pipe *pipe)
        if (!conn_ctrl_ready(conn))
                return 0;
 
-       if (!fd_send_ready(conn->t.sock.fd))
+       if (!fd_send_ready(conn->handle.fd))
                return 0;
 
        done = 0;
        while (pipe->data) {
-               ret = splice(pipe->cons, NULL, conn->t.sock.fd, NULL, pipe->data,
+               ret = splice(pipe->cons, NULL, conn->handle.fd, NULL, pipe->data,
                             SPLICE_F_MOVE|SPLICE_F_NONBLOCK);
 
                if (ret <= 0) {
                        if (ret == 0 || errno == EAGAIN) {
-                               fd_cant_send(conn->t.sock.fd);
+                               fd_cant_send(conn->handle.fd);
                                break;
                        }
                        else if (errno == EINTR)
@@ -250,18 +250,18 @@ static int raw_sock_to_buf(struct connection *conn, struct buffer *buf, int coun
        if (!conn_ctrl_ready(conn))
                return 0;
 
-       if (!fd_recv_ready(conn->t.sock.fd))
+       if (!fd_recv_ready(conn->handle.fd))
                return 0;
 
        errno = 0;
 
-       if (unlikely(!(fdtab[conn->t.sock.fd].ev & FD_POLL_IN))) {
+       if (unlikely(!(fdtab[conn->handle.fd].ev & FD_POLL_IN))) {
                /* stop here if we reached the end of data */
-               if ((fdtab[conn->t.sock.fd].ev & (FD_POLL_ERR|FD_POLL_HUP)) == FD_POLL_HUP)
+               if ((fdtab[conn->handle.fd].ev & (FD_POLL_ERR|FD_POLL_HUP)) == FD_POLL_HUP)
                        goto read0;
 
                /* report error on POLL_ERR before connection establishment */
-               if ((fdtab[conn->t.sock.fd].ev & FD_POLL_ERR) && (conn->flags & CO_FL_WAIT_L4_CONN)) {
+               if ((fdtab[conn->handle.fd].ev & FD_POLL_ERR) && (conn->flags & CO_FL_WAIT_L4_CONN)) {
                        conn->flags |= CO_FL_ERROR | CO_FL_SOCK_RD_SH | CO_FL_SOCK_WR_SH;
                        return done;
                }
@@ -288,7 +288,7 @@ static int raw_sock_to_buf(struct connection *conn, struct buffer *buf, int coun
                if (try > count)
                        try = count;
 
-               ret = recv(conn->t.sock.fd, bi_end(buf), try, 0);
+               ret = recv(conn->handle.fd, bi_end(buf), try, 0);
 
                if (ret > 0) {
                        buf->i += ret;
@@ -303,12 +303,12 @@ static int raw_sock_to_buf(struct connection *conn, struct buffer *buf, int coun
                                 * to read an unlikely close from the client since we'll
                                 * close first anyway.
                                 */
-                               if (fdtab[conn->t.sock.fd].ev & FD_POLL_HUP)
+                               if (fdtab[conn->handle.fd].ev & FD_POLL_HUP)
                                        goto read0;
 
-                               if ((!fdtab[conn->t.sock.fd].linger_risk) ||
+                               if ((!fdtab[conn->handle.fd].linger_risk) ||
                                    (cur_poller.flags & HAP_POLL_F_RDHUP)) {
-                                       fd_done_recv(conn->t.sock.fd);
+                                       fd_done_recv(conn->handle.fd);
                                        break;
                                }
                        }
@@ -318,7 +318,7 @@ static int raw_sock_to_buf(struct connection *conn, struct buffer *buf, int coun
                        goto read0;
                }
                else if (errno == EAGAIN || errno == ENOTCONN) {
-                       fd_cant_recv(conn->t.sock.fd);
+                       fd_cant_recv(conn->handle.fd);
                        break;
                }
                else if (errno != EINTR) {
@@ -342,7 +342,7 @@ static int raw_sock_to_buf(struct connection *conn, struct buffer *buf, int coun
         * of recv()'s return value 0, so we have no way to tell there was
         * an error without checking.
         */
-       if (unlikely(fdtab[conn->t.sock.fd].ev & FD_POLL_ERR))
+       if (unlikely(fdtab[conn->handle.fd].ev & FD_POLL_ERR))
                conn->flags |= CO_FL_ERROR | CO_FL_SOCK_RD_SH | CO_FL_SOCK_WR_SH;
        return done;
 }
@@ -365,7 +365,7 @@ static int raw_sock_from_buf(struct connection *conn, struct buffer *buf, int fl
        if (!conn_ctrl_ready(conn))
                return 0;
 
-       if (!fd_send_ready(conn->t.sock.fd))
+       if (!fd_send_ready(conn->handle.fd))
                return 0;
 
        done = 0;
@@ -383,7 +383,7 @@ static int raw_sock_from_buf(struct connection *conn, struct buffer *buf, int fl
                if (try < buf->o || flags & CO_SFL_MSG_MORE)
                        send_flag |= MSG_MORE;
 
-               ret = send(conn->t.sock.fd, bo_ptr(buf), try, send_flag);
+               ret = send(conn->handle.fd, bo_ptr(buf), try, send_flag);
 
                if (ret > 0) {
                        buf->o -= ret;
@@ -399,7 +399,7 @@ static int raw_sock_from_buf(struct connection *conn, struct buffer *buf, int fl
                }
                else if (ret == 0 || errno == EAGAIN || errno == ENOTCONN) {
                        /* nothing written, we need to poll for write first */
-                       fd_cant_send(conn->t.sock.fd);
+                       fd_cant_send(conn->handle.fd);
                        break;
                }
                else if (errno != EINTR) {
index 06d3000..62713ab 100644 (file)
@@ -130,7 +130,7 @@ int session_accept_fd(struct listener *l, int cfd, struct sockaddr_storage *addr
 
        conn_prepare(cli_conn, l->proto, l->bind_conf->xprt);
 
-       cli_conn->t.sock.fd = cfd;
+       cli_conn->handle.fd = cfd;
        cli_conn->addr.from = *addr;
        cli_conn->flags |= CO_FL_ADDR_FROM_SET;
        cli_conn->target = &l->obj_type;
index 7b1a0c9..36f8cc2 100644 (file)
@@ -286,7 +286,7 @@ static forceinline void ssl_sock_dump_errors(struct connection *conn)
                        if (ret == 0)
                                return;
                        fprintf(stderr, "fd[%04x] OpenSSL error[0x%lx] %s: %s\n",
-                               (unsigned short)conn->t.sock.fd, ret,
+                               (unsigned short)conn->handle.fd, ret,
                                ERR_func_error_string(ret), ERR_reason_error_string(ret));
                }
        }
@@ -4506,7 +4506,7 @@ static int ssl_sock_init(struct connection *conn)
                }
 
                /* set fd on SSL session context */
-               if (!SSL_set_fd(conn->xprt_ctx, conn->t.sock.fd)) {
+               if (!SSL_set_fd(conn->xprt_ctx, conn->handle.fd)) {
                        SSL_free(conn->xprt_ctx);
                        conn->xprt_ctx = NULL;
                        if (may_retry--) {
@@ -4560,7 +4560,7 @@ static int ssl_sock_init(struct connection *conn)
                }
 
                /* set fd on SSL session context */
-               if (!SSL_set_fd(conn->xprt_ctx, conn->t.sock.fd)) {
+               if (!SSL_set_fd(conn->xprt_ctx, conn->handle.fd)) {
                        SSL_free(conn->xprt_ctx);
                        conn->xprt_ctx = NULL;
                        if (may_retry--) {
@@ -4632,7 +4632,7 @@ int ssl_sock_handshake(struct connection *conn, unsigned int flag)
                                /* SSL handshake needs to write, L4 connection may not be ready */
                                __conn_sock_stop_recv(conn);
                                __conn_sock_want_send(conn);
-                               fd_cant_send(conn->t.sock.fd);
+                               fd_cant_send(conn->handle.fd);
                                return 0;
                        }
                        else if (ret == SSL_ERROR_WANT_READ) {
@@ -4648,7 +4648,7 @@ int ssl_sock_handshake(struct connection *conn, unsigned int flag)
                                        conn->flags &= ~CO_FL_WAIT_L4_CONN;
                                __conn_sock_stop_send(conn);
                                __conn_sock_want_recv(conn);
-                               fd_cant_recv(conn->t.sock.fd);
+                               fd_cant_recv(conn->handle.fd);
                                return 0;
                        }
 #if OPENSSL_VERSION_NUMBER >= 0x1010000fL
@@ -4723,7 +4723,7 @@ int ssl_sock_handshake(struct connection *conn, unsigned int flag)
                        /* SSL handshake needs to write, L4 connection may not be ready */
                        __conn_sock_stop_recv(conn);
                        __conn_sock_want_send(conn);
-                       fd_cant_send(conn->t.sock.fd);
+                       fd_cant_send(conn->handle.fd);
                        return 0;
                }
                else if (ret == SSL_ERROR_WANT_READ) {
@@ -4732,7 +4732,7 @@ int ssl_sock_handshake(struct connection *conn, unsigned int flag)
                                conn->flags &= ~CO_FL_WAIT_L4_CONN;
                        __conn_sock_stop_send(conn);
                        __conn_sock_want_recv(conn);
-                       fd_cant_recv(conn->t.sock.fd);
+                       fd_cant_recv(conn->handle.fd);
                        return 0;
                }
 #if OPENSSL_VERSION_NUMBER >= 0x1010000fL
@@ -4941,7 +4941,7 @@ static int ssl_sock_to_buf(struct connection *conn, struct buffer *buf, int coun
                                        break;
                                }
                                /* we need to poll for retry a read later */
-                               fd_cant_recv(conn->t.sock.fd);
+                               fd_cant_recv(conn->handle.fd);
                                break;
                        }
                        /* otherwise it's a real error */
@@ -5042,7 +5042,7 @@ static int ssl_sock_from_buf(struct connection *conn, struct buffer *buf, int fl
                                        break;
                                }
                                /* we need to poll to retry a write later */
-                               fd_cant_send(conn->t.sock.fd);
+                               fd_cant_send(conn->handle.fd);
                                break;
                        }
                        else if (ret == SSL_ERROR_WANT_READ) {
index d9bbe53..6f7a1be 100644 (file)
@@ -2302,8 +2302,8 @@ struct task *process_stream(struct task *t)
                    si_b->prev_state == SI_ST_EST) {
                        chunk_printf(&trash, "%08x:%s.srvcls[%04x:%04x]\n",
                                      s->uniq_id, s->be->id,
-                                     objt_conn(si_f->end) ? (unsigned short)objt_conn(si_f->end)->t.sock.fd : -1,
-                                     objt_conn(si_b->end) ? (unsigned short)objt_conn(si_b->end)->t.sock.fd : -1);
+                                     objt_conn(si_f->end) ? (unsigned short)objt_conn(si_f->end)->handle.fd : -1,
+                                     objt_conn(si_b->end) ? (unsigned short)objt_conn(si_b->end)->handle.fd : -1);
                        shut_your_big_mouth_gcc(write(1, trash.str, trash.len));
                }
 
@@ -2311,8 +2311,8 @@ struct task *process_stream(struct task *t)
                    si_f->prev_state == SI_ST_EST) {
                        chunk_printf(&trash, "%08x:%s.clicls[%04x:%04x]\n",
                                      s->uniq_id, s->be->id,
-                                     objt_conn(si_f->end) ? (unsigned short)objt_conn(si_f->end)->t.sock.fd : -1,
-                                     objt_conn(si_b->end) ? (unsigned short)objt_conn(si_b->end)->t.sock.fd : -1);
+                                     objt_conn(si_f->end) ? (unsigned short)objt_conn(si_f->end)->handle.fd : -1,
+                                     objt_conn(si_b->end) ? (unsigned short)objt_conn(si_b->end)->handle.fd : -1);
                        shut_your_big_mouth_gcc(write(1, trash.str, trash.len));
                }
        }
@@ -2415,8 +2415,8 @@ struct task *process_stream(struct task *t)
                     (!(global.mode & MODE_QUIET) || (global.mode & MODE_VERBOSE)))) {
                chunk_printf(&trash, "%08x:%s.closed[%04x:%04x]\n",
                              s->uniq_id, s->be->id,
-                             objt_conn(si_f->end) ? (unsigned short)objt_conn(si_f->end)->t.sock.fd : -1,
-                             objt_conn(si_b->end) ? (unsigned short)objt_conn(si_b->end)->t.sock.fd : -1);
+                             objt_conn(si_f->end) ? (unsigned short)objt_conn(si_f->end)->handle.fd : -1,
+                             objt_conn(si_b->end) ? (unsigned short)objt_conn(si_b->end)->handle.fd : -1);
                shut_your_big_mouth_gcc(write(1, trash.str, trash.len));
        }
 
@@ -2835,10 +2835,10 @@ static int stats_dump_full_strm_to_buffer(struct stream_interface *si, struct st
                        chunk_appendf(&trash,
                                      "      flags=0x%08x fd=%d fd.state=%02x fd.cache=%d updt=%d\n",
                                      conn->flags,
-                                     conn->t.sock.fd,
-                                     conn->t.sock.fd >= 0 ? fdtab[conn->t.sock.fd].state : 0,
-                                     conn->t.sock.fd >= 0 ? fdtab[conn->t.sock.fd].cache : 0,
-                                     conn->t.sock.fd >= 0 ? fdtab[conn->t.sock.fd].updated : 0);
+                                     conn->handle.fd,
+                                     conn->handle.fd >= 0 ? fdtab[conn->handle.fd].state : 0,
+                                     conn->handle.fd >= 0 ? fdtab[conn->handle.fd].cache : 0,
+                                     conn->handle.fd >= 0 ? fdtab[conn->handle.fd].updated : 0);
                }
                else if ((tmpctx = objt_appctx(strm->si[0].end)) != NULL) {
                        chunk_appendf(&trash,
@@ -2863,10 +2863,10 @@ static int stats_dump_full_strm_to_buffer(struct stream_interface *si, struct st
                        chunk_appendf(&trash,
                                      "      flags=0x%08x fd=%d fd.state=%02x fd.cache=%d updt=%d\n",
                                      conn->flags,
-                                     conn->t.sock.fd,
-                                     conn->t.sock.fd >= 0 ? fdtab[conn->t.sock.fd].state : 0,
-                                     conn->t.sock.fd >= 0 ? fdtab[conn->t.sock.fd].cache : 0,
-                                     conn->t.sock.fd >= 0 ? fdtab[conn->t.sock.fd].updated : 0);
+                                     conn->handle.fd,
+                                     conn->handle.fd >= 0 ? fdtab[conn->handle.fd].state : 0,
+                                     conn->handle.fd >= 0 ? fdtab[conn->handle.fd].cache : 0,
+                                     conn->handle.fd >= 0 ? fdtab[conn->handle.fd].updated : 0);
                }
                else if ((tmpctx = objt_appctx(strm->si[1].end)) != NULL) {
                        chunk_appendf(&trash,
@@ -3122,7 +3122,7 @@ static int cli_io_handler_dump_sess(struct appctx *appctx)
                                     " s0=[%d,%1xh,fd=%d,ex=%s]",
                                     curr_strm->si[0].state,
                                     curr_strm->si[0].flags,
-                                    conn ? conn->t.sock.fd : -1,
+                                    conn ? conn->handle.fd : -1,
                                     curr_strm->si[0].exp ?
                                     human_time(TICKS_TO_MS(curr_strm->si[0].exp - now_ms),
                                                TICKS_TO_MS(1000)) : "");
@@ -3132,7 +3132,7 @@ static int cli_io_handler_dump_sess(struct appctx *appctx)
                                     " s1=[%d,%1xh,fd=%d,ex=%s]",
                                     curr_strm->si[1].state,
                                     curr_strm->si[1].flags,
-                                    conn ? conn->t.sock.fd : -1,
+                                    conn ? conn->handle.fd : -1,
                                     curr_strm->si[1].exp ?
                                     human_time(TICKS_TO_MS(curr_strm->si[1].exp - now_ms),
                                                TICKS_TO_MS(1000)) : "");