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. */
*/
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;
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 */
*/
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 */
* - 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;
*/
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);
* 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;
/* 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 */
}
* 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;
/* 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;
*/
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;
* 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 */
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;
}
* 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;
*/
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;
#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 */
* 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;