MINOR: fd: make fdtab->owner a connection and not a stream_interface anymore
It is more convenient with a connection here and will abstract stream_interface
more easily.
diff --git a/include/types/fd.h b/include/types/fd.h
index c4133a9..54a78d6 100644
--- a/include/types/fd.h
+++ b/include/types/fd.h
@@ -69,7 +69,7 @@
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 a35e322..696525d 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 7b69aad..87ac849 100644
--- a/src/proto_tcp.c
+++ b/src/proto_tcp.c
@@ -466,7 +466,7 @@
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 @@
*/
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 @@
* - 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 @@
*/
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 @@
* 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 @@
/* 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 @@
* 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 0e6c11e..998270b 100644
--- a/src/session.c
+++ b/src/session.c
@@ -281,7 +281,7 @@
/* 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 c561a55..90081aa 100644
--- a/src/sock_raw.c
+++ b/src/sock_raw.c
@@ -228,7 +228,8 @@
*/
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 @@
* 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 @@
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 @@
* 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(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 @@
#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 @@
* 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;