]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: fd: make fdtab->owner a connection and not a stream_interface anymore
authorWilly Tarreau <wtarreau@exceliance.fr>
Fri, 6 Jul 2012 12:54:49 +0000 (14:54 +0200)
committerWilly Tarreau <w@1wt.eu>
Sun, 2 Sep 2012 19:51:28 +0000 (21:51 +0200)
It is more convenient with a connection here and will abstract stream_interface
more easily.

include/types/fd.h
src/connection.c
src/proto_tcp.c
src/session.c
src/sock_raw.c

index c4133a92dd0d11856b565ca7bb10fe738d86f20f..54a78d6b197eba55cb83365f36e431bd1fc6e791 100644 (file)
@@ -69,7 +69,7 @@ struct fdtab {
        struct {
                int (*f)(int fd);            /* read/write function */
        } cb[DIR_SIZE];
-       void *owner;                         /* the session (or proxy) associated with this fd, NULL if closed */
+       void *owner;                         /* the connection or listener associated with this fd, NULL if closed */
        struct {                             /* used by pollers which support speculative polling */
                unsigned char e;             /* read and write events status. 4 bits, may be merged into flags' lower bits */
                unsigned int s1;             /* Position in spec list+1. 0=not in list. */
index a35e3220de9f1febf067063e41e67b0ed5942aa0..696525d3e9c947b41b1852f96cd66924c940e631 100644 (file)
  */
 int conn_fd_handler(int fd)
 {
-       struct stream_interface *si = fdtab[fd].owner;
+       struct connection *conn = fdtab[fd].owner;
        int ret = 0;
 
-       if (!si)
+       if (!conn)
                return ret;
 
-       if (si->conn.flags & CO_FL_ERROR)
+       if (conn->flags & CO_FL_ERROR)
                return ret;
 
        if (fdtab[fd].ev & (FD_POLL_IN | FD_POLL_HUP | FD_POLL_ERR))
-               if (!si->conn.data->read(fd))
+               if (!conn->data->read(fd))
                        ret |= FD_WAIT_READ;
 
-       if (si->conn.flags & CO_FL_ERROR)
+       if (conn->flags & CO_FL_ERROR)
                return ret;
 
        if (fdtab[fd].ev & (FD_POLL_OUT | FD_POLL_ERR))
-               if (!si->conn.data->write(fd))
+               if (!conn->data->write(fd))
                        ret |= FD_WAIT_WRITE;
 
        return ret;
index 7b69aadc4093b21c4f41fc6c9a888eb5aab72c0c..87ac849ce631acdab1a3da364eeeb78f8054142b 100644 (file)
@@ -466,7 +466,7 @@ int tcp_connect_server(struct stream_interface *si)
        if (si->flags & SI_FL_SRC_ADDR)
                si_get_from_addr(si);
 
-       fdtab[fd].owner = si;
+       fdtab[fd].owner = &si->conn;
        fdtab[fd].flags = FD_FL_TCP | FD_FL_TCP_NODELAY;
        si->conn.flags  = CO_FL_WAIT_L4_CONN; /* connection in progress */
 
@@ -536,14 +536,15 @@ int tcp_get_dst(int fd, struct sockaddr *sa, socklen_t salen, int dir)
  */
 static int tcp_connect_write(int fd)
 {
-       struct stream_interface *si = fdtab[fd].owner;
+       struct connection *conn = fdtab[fd].owner;
+       struct stream_interface *si = container_of(conn, struct stream_interface, conn);
        struct buffer *b = si->ob;
        int retval = 0;
 
-       if (si->conn.flags & CO_FL_ERROR)
+       if (conn->flags & CO_FL_ERROR)
                goto out_error;
 
-       if (!(si->conn.flags & CO_FL_WAIT_L4_CONN))
+       if (!(conn->flags & CO_FL_WAIT_L4_CONN))
                goto out_ignore; /* strange we were called while ready */
 
        /* we might have been called just after an asynchronous shutw */
@@ -599,7 +600,7 @@ static int tcp_connect_write(int fd)
                 *  - connecting (EALREADY, EINPROGRESS)
                 *  - connected (EISCONN, 0)
                 */
-               if ((connect(fd, si->conn.peeraddr, si->conn.peerlen) < 0)) {
+               if ((connect(fd, conn->peeraddr, conn->peerlen) < 0)) {
                        if (errno == EALREADY || errno == EINPROGRESS)
                                goto out_ignore;
 
@@ -620,7 +621,7 @@ static int tcp_connect_write(int fd)
         */
        fdtab[fd].cb[DIR_RD].f = NULL;
        fdtab[fd].cb[DIR_WR].f = NULL;
-       si->conn.flags &= ~CO_FL_WAIT_L4_CONN;
+       conn->flags &= ~CO_FL_WAIT_L4_CONN;
        si->exp = TICK_ETERNITY;
        return si_data(si)->write(fd);
 
@@ -639,7 +640,7 @@ static int tcp_connect_write(int fd)
         * connection retries.
         */
 
-       si->conn.flags |= CO_FL_ERROR;
+       conn->flags |= CO_FL_ERROR;
        fdtab[fd].ev &= ~FD_POLL_STICKY;
        EV_FD_REM(fd);
        si->flags |= SI_FL_ERR;
@@ -651,15 +652,16 @@ static int tcp_connect_write(int fd)
 /* might be used on connect error */
 static int tcp_connect_read(int fd)
 {
-       struct stream_interface *si = fdtab[fd].owner;
+       struct connection *conn = fdtab[fd].owner;
+       struct stream_interface *si = container_of(conn, struct stream_interface, conn);
        int retval;
 
        retval = 1;
 
-       if (si->conn.flags & CO_FL_ERROR)
+       if (conn->flags & CO_FL_ERROR)
                goto out_error;
 
-       if (!(si->conn.flags & CO_FL_WAIT_L4_CONN)) {
+       if (!(conn->flags & CO_FL_WAIT_L4_CONN)) {
                retval = 0;
                goto out_ignore; /* strange we were called while ready */
        }
@@ -682,7 +684,7 @@ static int tcp_connect_read(int fd)
         * connection retries.
         */
 
-       si->conn.flags |= CO_FL_ERROR;
+       conn->flags |= CO_FL_ERROR;
        fdtab[fd].ev &= ~FD_POLL_STICKY;
        EV_FD_REM(fd);
        si->flags |= SI_FL_ERR;
index 0e6c11e0df157e0c98b57db34e1b7768c471cd2f..998270b33882db5aa21421c8927d657ebb2be66e 100644 (file)
@@ -281,7 +281,7 @@ int session_accept(struct listener *l, int cfd, struct sockaddr_storage *addr)
 
        /* finish initialization of the accepted file descriptor */
        fd_insert(cfd);
-       fdtab[cfd].owner = &s->si[0];
+       fdtab[cfd].owner = &s->si[0].conn;
        fdtab[cfd].flags = 0;
        fdtab[cfd].cb[DIR_RD].f = NULL;
        fdtab[cfd].cb[DIR_WR].f = NULL;
index c561a55107dce26412f9b340464330ccbfcaecc4..90081aa3387779ad008119e61dcf1db9f3e31157 100644 (file)
@@ -228,7 +228,8 @@ static int sock_raw_splice_in(struct buffer *b, struct stream_interface *si)
  */
 static int sock_raw_read(int fd)
 {
-       struct stream_interface *si = fdtab[fd].owner;
+       struct connection *conn = fdtab[fd].owner;
+       struct stream_interface *si = container_of(conn, struct stream_interface, conn);
        struct buffer *b = si->ib;
        int ret, max, retval, cur_read;
        int read_poll = MAX_READ_POLL_LOOPS;
@@ -245,7 +246,7 @@ static int sock_raw_read(int fd)
         * happens when we send too large a request to a backend server
         * which rejects it before reading it all.
         */
-       if (si->conn.flags & CO_FL_ERROR)
+       if (conn->flags & CO_FL_ERROR)
                goto out_error;
 
        /* stop here if we reached the end of data */
@@ -323,8 +324,8 @@ static int sock_raw_read(int fd)
                                b_adv(b, fwd);
                        }
 
-                       if (si->conn.flags & CO_FL_WAIT_L4_CONN) {
-                               si->conn.flags &= ~CO_FL_WAIT_L4_CONN;
+                       if (conn->flags & CO_FL_WAIT_L4_CONN) {
+                               conn->flags &= ~CO_FL_WAIT_L4_CONN;
                                si->exp = TICK_ETERNITY;
                        }
 
@@ -503,7 +504,7 @@ static int sock_raw_read(int fd)
         * connection retries.
         */
 
-       si->conn.flags |= CO_FL_ERROR;
+       conn->flags |= CO_FL_ERROR;
        fdtab[fd].ev &= ~FD_POLL_STICKY;
        EV_FD_REM(fd);
        si->flags |= SI_FL_ERR;
@@ -667,7 +668,8 @@ static int sock_raw_write_loop(struct stream_interface *si, struct buffer *b)
  */
 static int sock_raw_write(int fd)
 {
-       struct stream_interface *si = fdtab[fd].owner;
+       struct connection *conn = fdtab[fd].owner;
+       struct stream_interface *si = container_of(conn, struct stream_interface, conn);
        struct buffer *b = si->ob;
        int retval = 1;
 
@@ -676,7 +678,7 @@ static int sock_raw_write(int fd)
 #endif
 
        retval = 1;
-       if (si->conn.flags & CO_FL_ERROR)
+       if (conn->flags & CO_FL_ERROR)
                goto out_error;
 
        /* we might have been called just after an asynchronous shutw */
@@ -750,7 +752,7 @@ static int sock_raw_write(int fd)
         * connection retries.
         */
 
-       si->conn.flags |= CO_FL_ERROR;
+       conn->flags |= CO_FL_ERROR;
        fdtab[fd].ev &= ~FD_POLL_STICKY;
        EV_FD_REM(fd);
        si->flags |= SI_FL_ERR;