diff --git a/include/types/fd.h b/include/types/fd.h index c4133a92d..54a78d6b1 100644 --- a/include/types/fd.h +++ b/include/types/fd.h @@ -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. */ diff --git a/src/connection.c b/src/connection.c index a35e3220d..696525d3e 100644 --- a/src/connection.c +++ b/src/connection.c @@ -22,24 +22,24 @@ */ 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; diff --git a/src/proto_tcp.c b/src/proto_tcp.c index 7b69aadc4..87ac849ce 100644 --- a/src/proto_tcp.c +++ b/src/proto_tcp.c @@ -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; diff --git a/src/session.c b/src/session.c index 0e6c11e0d..998270b33 100644 --- a/src/session.c +++ b/src/session.c @@ -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; diff --git a/src/sock_raw.c b/src/sock_raw.c index c561a5510..90081aa33 100644 --- a/src/sock_raw.c +++ b/src/sock_raw.c @@ -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;