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.
This commit is contained in:
Willy Tarreau 2012-07-06 14:54:49 +02:00 committed by Willy Tarreau
parent d2274c6536
commit 8018471f44
5 changed files with 31 additions and 27 deletions

View File

@ -69,7 +69,7 @@ struct fdtab {
struct { struct {
int (*f)(int fd); /* read/write function */ int (*f)(int fd); /* read/write function */
} cb[DIR_SIZE]; } 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 */ 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 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. */ unsigned int s1; /* Position in spec list+1. 0=not in list. */

View File

@ -22,24 +22,24 @@
*/ */
int conn_fd_handler(int fd) int conn_fd_handler(int fd)
{ {
struct stream_interface *si = fdtab[fd].owner; struct connection *conn = fdtab[fd].owner;
int ret = 0; int ret = 0;
if (!si) if (!conn)
return ret; return ret;
if (si->conn.flags & CO_FL_ERROR) if (conn->flags & CO_FL_ERROR)
return ret; return ret;
if (fdtab[fd].ev & (FD_POLL_IN | FD_POLL_HUP | FD_POLL_ERR)) 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; ret |= FD_WAIT_READ;
if (si->conn.flags & CO_FL_ERROR) if (conn->flags & CO_FL_ERROR)
return ret; return ret;
if (fdtab[fd].ev & (FD_POLL_OUT | FD_POLL_ERR)) 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; ret |= FD_WAIT_WRITE;
return ret; return ret;

View File

@ -466,7 +466,7 @@ int tcp_connect_server(struct stream_interface *si)
if (si->flags & SI_FL_SRC_ADDR) if (si->flags & SI_FL_SRC_ADDR)
si_get_from_addr(si); si_get_from_addr(si);
fdtab[fd].owner = si; fdtab[fd].owner = &si->conn;
fdtab[fd].flags = FD_FL_TCP | FD_FL_TCP_NODELAY; fdtab[fd].flags = FD_FL_TCP | FD_FL_TCP_NODELAY;
si->conn.flags = CO_FL_WAIT_L4_CONN; /* connection in progress */ 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) 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; struct buffer *b = si->ob;
int retval = 0; int retval = 0;
if (si->conn.flags & CO_FL_ERROR) if (conn->flags & CO_FL_ERROR)
goto out_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 */ goto out_ignore; /* strange we were called while ready */
/* we might have been called just after an asynchronous shutw */ /* we might have been called just after an asynchronous shutw */
@ -599,7 +600,7 @@ static int tcp_connect_write(int fd)
* - connecting (EALREADY, EINPROGRESS) * - connecting (EALREADY, EINPROGRESS)
* - connected (EISCONN, 0) * - 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) if (errno == EALREADY || errno == EINPROGRESS)
goto out_ignore; 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_RD].f = NULL;
fdtab[fd].cb[DIR_WR].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; si->exp = TICK_ETERNITY;
return si_data(si)->write(fd); return si_data(si)->write(fd);
@ -639,7 +640,7 @@ static int tcp_connect_write(int fd)
* connection retries. * connection retries.
*/ */
si->conn.flags |= CO_FL_ERROR; conn->flags |= CO_FL_ERROR;
fdtab[fd].ev &= ~FD_POLL_STICKY; fdtab[fd].ev &= ~FD_POLL_STICKY;
EV_FD_REM(fd); EV_FD_REM(fd);
si->flags |= SI_FL_ERR; si->flags |= SI_FL_ERR;
@ -651,15 +652,16 @@ static int tcp_connect_write(int fd)
/* might be used on connect error */ /* might be used on connect error */
static int tcp_connect_read(int fd) 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; int retval;
retval = 1; retval = 1;
if (si->conn.flags & CO_FL_ERROR) if (conn->flags & CO_FL_ERROR)
goto out_error; goto out_error;
if (!(si->conn.flags & CO_FL_WAIT_L4_CONN)) { if (!(conn->flags & CO_FL_WAIT_L4_CONN)) {
retval = 0; retval = 0;
goto out_ignore; /* strange we were called while ready */ goto out_ignore; /* strange we were called while ready */
} }
@ -682,7 +684,7 @@ static int tcp_connect_read(int fd)
* connection retries. * connection retries.
*/ */
si->conn.flags |= CO_FL_ERROR; conn->flags |= CO_FL_ERROR;
fdtab[fd].ev &= ~FD_POLL_STICKY; fdtab[fd].ev &= ~FD_POLL_STICKY;
EV_FD_REM(fd); EV_FD_REM(fd);
si->flags |= SI_FL_ERR; si->flags |= SI_FL_ERR;

View File

@ -281,7 +281,7 @@ int session_accept(struct listener *l, int cfd, struct sockaddr_storage *addr)
/* finish initialization of the accepted file descriptor */ /* finish initialization of the accepted file descriptor */
fd_insert(cfd); fd_insert(cfd);
fdtab[cfd].owner = &s->si[0]; fdtab[cfd].owner = &s->si[0].conn;
fdtab[cfd].flags = 0; fdtab[cfd].flags = 0;
fdtab[cfd].cb[DIR_RD].f = NULL; fdtab[cfd].cb[DIR_RD].f = NULL;
fdtab[cfd].cb[DIR_WR].f = NULL; fdtab[cfd].cb[DIR_WR].f = NULL;

View 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) 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; struct buffer *b = si->ib;
int ret, max, retval, cur_read; int ret, max, retval, cur_read;
int read_poll = MAX_READ_POLL_LOOPS; 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 * happens when we send too large a request to a backend server
* which rejects it before reading it all. * which rejects it before reading it all.
*/ */
if (si->conn.flags & CO_FL_ERROR) if (conn->flags & CO_FL_ERROR)
goto out_error; goto out_error;
/* stop here if we reached the end of data */ /* stop here if we reached the end of data */
@ -323,8 +324,8 @@ static int sock_raw_read(int fd)
b_adv(b, fwd); b_adv(b, fwd);
} }
if (si->conn.flags & CO_FL_WAIT_L4_CONN) { if (conn->flags & CO_FL_WAIT_L4_CONN) {
si->conn.flags &= ~CO_FL_WAIT_L4_CONN; conn->flags &= ~CO_FL_WAIT_L4_CONN;
si->exp = TICK_ETERNITY; si->exp = TICK_ETERNITY;
} }
@ -503,7 +504,7 @@ static int sock_raw_read(int fd)
* connection retries. * connection retries.
*/ */
si->conn.flags |= CO_FL_ERROR; conn->flags |= CO_FL_ERROR;
fdtab[fd].ev &= ~FD_POLL_STICKY; fdtab[fd].ev &= ~FD_POLL_STICKY;
EV_FD_REM(fd); EV_FD_REM(fd);
si->flags |= SI_FL_ERR; 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) 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; struct buffer *b = si->ob;
int retval = 1; int retval = 1;
@ -676,7 +678,7 @@ static int sock_raw_write(int fd)
#endif #endif
retval = 1; retval = 1;
if (si->conn.flags & CO_FL_ERROR) if (conn->flags & CO_FL_ERROR)
goto out_error; goto out_error;
/* we might have been called just after an asynchronous shutw */ /* we might have been called just after an asynchronous shutw */
@ -750,7 +752,7 @@ static int sock_raw_write(int fd)
* connection retries. * connection retries.
*/ */
si->conn.flags |= CO_FL_ERROR; conn->flags |= CO_FL_ERROR;
fdtab[fd].ev &= ~FD_POLL_STICKY; fdtab[fd].ev &= ~FD_POLL_STICKY;
EV_FD_REM(fd); EV_FD_REM(fd);
si->flags |= SI_FL_ERR; si->flags |= SI_FL_ERR;