r4868 - in trunk/varnish-cache: bin/varnishd bin/varnishtest include lib/libvarnish
phk at varnish-cache.org
phk at varnish-cache.org
Mon May 31 13:31:11 CEST 2010
Author: phk
Date: 2010-05-31 13:31:11 +0200 (Mon, 31 May 2010)
New Revision: 4868
Modified:
trunk/varnish-cache/bin/varnishd/cache_vrt.c
trunk/varnish-cache/bin/varnishtest/vtc_server.c
trunk/varnish-cache/include/libvarnish.h
trunk/varnish-cache/lib/libvarnish/tcp.c
Log:
Attempt an even more comprehensive fix for a bug in Solaris:
If the remote end RST's a TCP connection, all socket related syscalls
seems to return EINVAL.
Modified: trunk/varnish-cache/bin/varnishd/cache_vrt.c
===================================================================
--- trunk/varnish-cache/bin/varnishd/cache_vrt.c 2010-05-31 10:08:38 UTC (rev 4867)
+++ trunk/varnish-cache/bin/varnishd/cache_vrt.c 2010-05-31 11:31:11 UTC (rev 4868)
@@ -696,10 +696,12 @@
struct sockaddr *
VRT_r_server_ip(struct sess *sp)
{
+ int i;
- if (sp->mysockaddr->sa_family == AF_UNSPEC)
- assert(!getsockname(sp->fd, sp->mysockaddr, &sp->mysockaddrlen)
- || errno == ECONNRESET);
+ if (sp->mysockaddr->sa_family == AF_UNSPEC) {
+ i = getsockname(sp->fd, sp->mysockaddr, &sp->mysockaddrlen);
+ assert(TCP_Check(i));
+ }
return (sp->mysockaddr);
}
Modified: trunk/varnish-cache/bin/varnishtest/vtc_server.c
===================================================================
--- trunk/varnish-cache/bin/varnishtest/vtc_server.c 2010-05-31 10:08:38 UTC (rev 4867)
+++ trunk/varnish-cache/bin/varnishtest/vtc_server.c 2010-05-31 11:31:11 UTC (rev 4868)
@@ -85,7 +85,7 @@
{
struct server *s;
struct vtclog *vl;
- int i, fd;
+ int i, j, fd;
struct sockaddr_storage addr_s;
struct sockaddr *addr;
socklen_t l;
@@ -107,8 +107,9 @@
vtc_log(vl, 3, "accepted fd %d", fd);
http_process(vl, s->spec, fd, s->sock);
vtc_log(vl, 3, "shutting fd %d", fd);
- assert((shutdown(fd, SHUT_WR) == 0)
- || errno == ENOTCONN || errno == ECONNRESET);
+ j = shutdown(fd, SHUT_WR);
+ if (!TCP_Check(j))
+ vtc_log(vl, 0, "Shutdown failed: %s", strerror(errno));
TCP_close(&fd);
}
macro_def(s->vl, s->name, "addr", NULL);
Modified: trunk/varnish-cache/include/libvarnish.h
===================================================================
--- trunk/varnish-cache/include/libvarnish.h 2010-05-31 10:08:38 UTC (rev 4867)
+++ trunk/varnish-cache/include/libvarnish.h 2010-05-31 11:31:11 UTC (rev 4868)
@@ -60,7 +60,16 @@
#define TCP_ADDRBUFSIZE 64
#define TCP_PORTBUFSIZE 16
+#if defined (__SVR4) && defined (__sun)
+/*
+ * Solaris returns EINVAL if the other end unexepectedly reset the
+ * connection. This is a bug in Solaris.
+ */
+#define TCP_Check(a) ((a) == 0 || errno == ECONNRESET || errno == ENOTCONN \
+ || errno == EINVAL)
+#else
#define TCP_Check(a) ((a) == 0 || errno == ECONNRESET || errno == ENOTCONN)
+#endif
#define TCP_Assert(a) assert(TCP_Check(a))
Modified: trunk/varnish-cache/lib/libvarnish/tcp.c
===================================================================
--- trunk/varnish-cache/lib/libvarnish/tcp.c 2010-05-31 10:08:38 UTC (rev 4867)
+++ trunk/varnish-cache/lib/libvarnish/tcp.c 2010-05-31 11:31:11 UTC (rev 4868)
@@ -236,9 +236,11 @@
void
TCP_close(int *s)
{
- assert (close(*s) == 0 ||
- errno == ECONNRESET ||
- errno == ENOTCONN);
+ int i;
+
+ i = close(*s);
+
+ assert (TCP_Check(i));
*s = -1;
}
More information about the varnish-commit
mailing list