/* This describes a receiver with all its characteristics (address, status, etc) */
struct receiver {
+ int fd; /* handle we receive from (fd only for now) */
unsigned int flags; /* receiver options (RX_F_*) */
-
/* warning: this struct is huge, keep it at the bottom */
struct sockaddr_storage addr; /* the address the socket is bound to */
};
enum obj_type obj_type; /* object type = OBJ_TYPE_LISTENER */
enum li_state state; /* state: NEW, INIT, ASSIGNED, LISTEN, READY, FULL */
short int nice; /* nice value to assign to the instantiated tasks */
- int fd; /* the listen socket */
int luid; /* listener universally unique ID, used for SNMP */
int options; /* socket options : LI_O_* */
struct fe_counters *counters; /* statistics counters */
if (!conn_get_src(conn)) {
chunk_printf(&trash, "%08x:%s.accept(%04x)=%04x from [listener:%d] ALPN=%s\n",
- s->uniq_id, fe->id, (unsigned short)l->fd, (unsigned short)conn->handle.fd,
+ s->uniq_id, fe->id, (unsigned short)l->rx.fd, (unsigned short)conn->handle.fd,
l->luid, alpn);
}
else switch (addr_to_str(conn->src, pn, sizeof(pn))) {
case AF_INET:
case AF_INET6:
chunk_printf(&trash, "%08x:%s.accept(%04x)=%04x from [%s:%d] ALPN=%s\n",
- s->uniq_id, fe->id, (unsigned short)l->fd, (unsigned short)conn->handle.fd,
+ s->uniq_id, fe->id, (unsigned short)l->rx.fd, (unsigned short)conn->handle.fd,
pn, get_host_port(conn->src), alpn);
break;
case AF_UNIX:
/* UNIX socket, only the destination is known */
chunk_printf(&trash, "%08x:%s.accept(%04x)=%04x from [unix:%d] ALPN=%s\n",
- s->uniq_id, fe->id, (unsigned short)l->fd, (unsigned short)conn->handle.fd,
+ s->uniq_id, fe->id, (unsigned short)l->rx.fd, (unsigned short)conn->handle.fd,
l->luid, alpn);
break;
}
* Close it and give the listener its real state.
*/
if (p->state == PR_STSTOPPED && l->state >= LI_ZOMBIE) {
- close(l->fd);
+ close(l->rx.fd);
l->state = LI_INIT;
}
unbind_listener(l);
}
}
else if (!listener->maxconn || listener->nbconn < listener->maxconn) {
- fd_want_recv(listener->fd);
+ fd_want_recv(listener->rx.fd);
listener->state = LI_READY;
}
else {
if (listener->state < LI_READY)
goto end;
if (listener->state == LI_READY)
- fd_stop_recv(listener->fd);
+ fd_stop_recv(listener->rx.fd);
MT_LIST_DEL(&listener->wait_queue);
listener->state = LI_LISTEN;
end:
MT_LIST_DEL(&l->wait_queue);
- fd_stop_recv(l->fd);
+ fd_stop_recv(l->rx.fd);
l->state = LI_PAUSED;
end:
HA_SPIN_UNLOCK(LISTENER_LOCK, &l->lock);
if (l->proto->sock_prot == IPPROTO_TCP &&
l->state == LI_PAUSED &&
- listen(l->fd, listener_backlog(l)) != 0) {
+ listen(l->rx.fd, listener_backlog(l)) != 0) {
ret = 0;
goto end;
}
goto end;
}
- fd_want_recv(l->fd);
+ fd_want_recv(l->rx.fd);
l->state = LI_READY;
end:
HA_SPIN_UNLOCK(LISTENER_LOCK, &l->lock);
if (l->state >= LI_READY) {
MT_LIST_DEL(&l->wait_queue);
if (l->state != LI_FULL) {
- fd_stop_recv(l->fd);
+ fd_stop_recv(l->rx.fd);
l->state = LI_FULL;
}
}
HA_SPIN_LOCK(LISTENER_LOCK, &l->lock);
if (l->state == LI_READY) {
MT_LIST_TRY_ADDQ(list, &l->wait_queue);
- fd_stop_recv(l->fd);
+ fd_stop_recv(l->rx.fd);
l->state = LI_LIMITED;
}
HA_SPIN_UNLOCK(LISTENER_LOCK, &l->lock);
void do_unbind_listener(struct listener *listener, int do_close)
{
if (listener->state == LI_READY && fd_updt)
- fd_stop_recv(listener->fd);
+ fd_stop_recv(listener->rx.fd);
MT_LIST_DEL(&listener->wait_queue);
if (listener->state >= LI_PAUSED) {
listener->state = LI_ASSIGNED;
- fd_stop_both(listener->fd);
+ fd_stop_both(listener->rx.fd);
if (do_close) {
- fd_delete(listener->fd);
- listener->fd = -1;
+ fd_delete(listener->rx.fd);
+ listener->rx.fd = -1;
}
}
}
LIST_ADDQ(&bc->listeners, &l->by_bind);
l->bind_conf = bc;
- l->fd = fd;
+ l->rx.fd = fd;
memcpy(&l->rx.addr, ss, sizeof(*ss));
MT_LIST_INIT(&l->wait_queue);
l->state = LI_INIT;
else
fd_done_recv(fd);
} else if (l->state > LI_ASSIGNED) {
- fd_stop_recv(l->fd);
+ fd_stop_recv(l->rx.fd);
}
HA_SPIN_UNLOCK(LISTENER_LOCK, &l->lock);
return;
*/
static int sockpair_bind_listener(struct listener *listener, char *errmsg, int errlen)
{
- int fd = listener->fd;
+ int fd = listener->rx.fd;
int err;
const char *msg = NULL;
if (listener->state != LI_ASSIGNED)
return ERR_NONE; /* already bound */
- if (listener->fd == -1) {
+ if (listener->rx.fd == -1) {
err |= ERR_FATAL | ERR_ALERT;
msg = "sockpair can be only used with inherited FDs";
goto err_return;
err = ERR_NONE;
- if (listener->fd == -1)
- listener->fd = sock_find_compatible_fd(listener);
+ if (listener->rx.fd == -1)
+ listener->rx.fd = sock_find_compatible_fd(listener);
/* if the listener already has an fd assigned, then we were offered the
* fd by an external process (most likely the parent), and we don't want
* to create a new socket. However we still want to set a few flags on
* the socket.
*/
- fd = listener->fd;
+ fd = listener->rx.fd;
ext = (fd >= 0);
if (!ext) {
#endif
/* the socket is ready */
- listener->fd = fd;
+ listener->rx.fd = fd;
listener->state = LI_LISTEN;
fd_insert(fd, listener, listener->proto->accept,
*/
int tcp_pause_listener(struct listener *l)
{
- if (shutdown(l->fd, SHUT_WR) != 0)
+ if (shutdown(l->rx.fd, SHUT_WR) != 0)
return -1; /* Solaris dies here */
- if (listen(l->fd, listener_backlog(l)) != 0)
+ if (listen(l->rx.fd, listener_backlog(l)) != 0)
return -1; /* OpenBSD dies here */
- if (shutdown(l->fd, SHUT_RD) != 0)
+ if (shutdown(l->rx.fd, SHUT_RD) != 0)
return -1; /* should always be OK */
return 1;
}
}
/* the socket is ready */
- listener->fd = fd;
+ listener->rx.fd = fd;
listener->state = LI_LISTEN;
if (listener->bind_conf->frontend->mode == PR_MODE_SYSLOG)
if (listener->state != LI_ASSIGNED)
return ERR_NONE; /* already bound */
- if (listener->fd == -1)
- listener->fd = sock_find_compatible_fd(listener);
-
+ if (listener->rx.fd == -1)
+ listener->rx.fd = sock_find_compatible_fd(listener);
path = ((struct sockaddr_un *)&listener->rx.addr)->sun_path;
maxpathlen = MIN(MAXPATHLEN, sizeof(addr.sun_path));
* to create a new socket. However we still want to set a few flags on
* the socket.
*/
- fd = listener->fd;
+ fd = listener->rx.fd;
ext = (fd >= 0);
if (ext)
goto fd_ready;
unlink(backname);
/* the socket is now listening */
- listener->fd = fd;
+ listener->rx.fd = fd;
listener->state = LI_LISTEN;
fd_insert(fd, listener, listener->proto->accept,
struct listener *l;
list_for_each_entry(l, &p->conf.listeners, by_fe) {
if (l->state > LI_ASSIGNED)
- close(l->fd);
+ close(l->rx.fd);
l->state = LI_INIT;
}
}