Commit 1476982d authored by Poul-Henning Kamp's avatar Poul-Henning Kamp

Don't leak listen address structures if we fail to bind to them.

Associate ascii representation addr/port strings with each listen
socket, already in the manager process.

Postpone listen(2) call until client is ready, to limit initial 
connection spike.

XXX: I still miss an unlisten(2).



git-svn-id: http://www.varnish-cache.org/svn/trunk/varnish-cache@2658 d4fa192b-c00b-0410-8231-f00ffab90ce4
parent e6e3a796
......@@ -161,6 +161,9 @@ vca_acct(void *arg)
AN(pfd);
i = 0;
VTAILQ_FOREACH(ls, &heritage.socks, list) {
if (ls->sock < 0)
continue;
AZ(listen(ls->sock, params->listen_depth));
AZ(setsockopt(ls->sock, SOL_SOCKET, SO_LINGER,
&linger, sizeof linger));
pfd[i].events = POLLIN;
......
......@@ -38,6 +38,8 @@
struct listen_sock {
VTAILQ_ENTRY(listen_sock) list;
int sock;
char *hname;
char *pname;
struct vss_addr *addr;
};
......
......@@ -138,18 +138,21 @@ open_sockets(void)
{
struct listen_sock *ls, *ls2;
int good = 0;
char hbuf[TCP_ADDRBUFSIZE];
char pbuf[TCP_PORTBUFSIZE];
VTAILQ_FOREACH_SAFE(ls, &heritage.socks, list, ls2) {
if (ls->sock >= 0) {
good++;
continue;
}
ls->sock = VSS_listen(ls->addr, params->listen_depth);
if (ls->sock < 0) {
VTAILQ_REMOVE(&heritage.socks, ls, list);
free(ls);
ls->sock = VSS_bind(ls->addr);
if (ls->sock < 0)
continue;
}
TCP_myname(ls->sock, hbuf, sizeof hbuf, pbuf, sizeof pbuf);
REPLACE(ls->hname, hbuf);
REPLACE(ls->pname, pbuf);
/*
* Set nonblocking mode to avoid a race where a client
* closes before we call accept(2) and nobody else are in
......@@ -174,8 +177,10 @@ close_sockets(void)
VTAILQ_FOREACH(ls, &heritage.socks, list) {
if (ls->sock < 0)
continue;
(void)close(ls->sock);
AZ(close(ls->sock));
ls->sock = -1;
REPLACE(ls->hname, NULL);
REPLACE(ls->pname, NULL);
}
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment