Mailing List Archive

r2658 - trunk/varnish-cache/bin/varnishd
Author: phk
Date: 2008-06-09 15:11:45 +0200 (Mon, 09 Jun 2008)
New Revision: 2658

Modified:
trunk/varnish-cache/bin/varnishd/cache_acceptor.c
trunk/varnish-cache/bin/varnishd/heritage.h
trunk/varnish-cache/bin/varnishd/mgt_child.c
Log:
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).



Modified: trunk/varnish-cache/bin/varnishd/cache_acceptor.c
===================================================================
--- trunk/varnish-cache/bin/varnishd/cache_acceptor.c 2008-06-09 13:01:27 UTC (rev 2657)
+++ trunk/varnish-cache/bin/varnishd/cache_acceptor.c 2008-06-09 13:11:45 UTC (rev 2658)
@@ -161,6 +161,9 @@
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;

Modified: trunk/varnish-cache/bin/varnishd/heritage.h
===================================================================
--- trunk/varnish-cache/bin/varnishd/heritage.h 2008-06-09 13:01:27 UTC (rev 2657)
+++ trunk/varnish-cache/bin/varnishd/heritage.h 2008-06-09 13:11:45 UTC (rev 2658)
@@ -38,6 +38,8 @@
struct listen_sock {
VTAILQ_ENTRY(listen_sock) list;
int sock;
+ char *hname;
+ char *pname;
struct vss_addr *addr;
};


Modified: trunk/varnish-cache/bin/varnishd/mgt_child.c
===================================================================
--- trunk/varnish-cache/bin/varnishd/mgt_child.c 2008-06-09 13:01:27 UTC (rev 2657)
+++ trunk/varnish-cache/bin/varnishd/mgt_child.c 2008-06-09 13:11:45 UTC (rev 2658)
@@ -138,18 +138,21 @@
{
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 @@
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);
}
}