From: phk Date: Tue, 12 Aug 2008 12:28:38 +0000 (+0000) Subject: Make a central TCP_close() function that accepts the two errno's which X-Git-Url: https://err.no/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=67760f9c63fa13e334e52357a028144098238c26;p=varnish Make a central TCP_close() function that accepts the two errno's which indicate that our partner gave up on us. git-svn-id: svn+ssh://projects.linpro.no/svn/varnish/trunk@3083 d4fa192b-c00b-0410-8231-f00ffab90ce4 --- diff --git a/varnish-cache/bin/varnishd/cache_backend.c b/varnish-cache/bin/varnishd/cache_backend.c index 098d9e11..c994607d 100644 --- a/varnish-cache/bin/varnishd/cache_backend.c +++ b/varnish-cache/bin/varnishd/cache_backend.c @@ -242,7 +242,7 @@ bes_conn_try(const struct sess *sp, struct backend *bp) LOCK(&bp->mtx); bp->refcount++; - UNLOCK(&sp->backend->mtx); + UNLOCK(&bp->mtx); s = -1; assert(bp->ipv6 != NULL || bp->ipv4 != NULL); @@ -257,7 +257,7 @@ bes_conn_try(const struct sess *sp, struct backend *bp) s = VBE_TryConnect(sp, PF_INET6, bp->ipv6, bp->ipv6len); if (s < 0) { - LOCK(&sp->backend->mtx); + LOCK(&bp->mtx); bp->refcount--; /* Only keep ref on success */ UNLOCK(&bp->mtx); } @@ -317,16 +317,13 @@ void VBE_ClosedFd(struct worker *w, struct vbe_conn *vc) { struct backend *b; - int i; CHECK_OBJ_NOTNULL(vc, VBE_CONN_MAGIC); CHECK_OBJ_NOTNULL(vc->backend, BACKEND_MAGIC); b = vc->backend; assert(vc->fd >= 0); WSL(w, SLT_BackendClose, vc->fd, "%s", vc->backend->vcl_name); - i = close(vc->fd); - assert(i == 0 || errno == ECONNRESET || errno == ENOTCONN); - vc->fd = -1; + TCP_close(&vc->fd); VBE_DropRef(vc->backend); vc->backend = NULL; VBE_ReleaseConn(vc); diff --git a/varnish-cache/bin/varnishd/common.h b/varnish-cache/bin/varnishd/common.h index 849660e6..280486a4 100644 --- a/varnish-cache/bin/varnishd/common.h +++ b/varnish-cache/bin/varnishd/common.h @@ -54,6 +54,7 @@ void TCP_blocking(int sock); void TCP_nonblocking(int sock); #ifdef SOL_SOCKET int TCP_connect(int s, const struct sockaddr *name, socklen_t namelen, int msec); +void TCP_close(int *s); #endif #define TRUST_ME(ptr) ((void*)(uintptr_t)(ptr)) diff --git a/varnish-cache/bin/varnishd/tcp.c b/varnish-cache/bin/varnishd/tcp.c index 5e8be682..ad95b7bd 100644 --- a/varnish-cache/bin/varnishd/tcp.c +++ b/varnish-cache/bin/varnishd/tcp.c @@ -192,3 +192,17 @@ TCP_connect(int s, const struct sockaddr *name, socklen_t namelen, int msec) TCP_blocking(s); return (0); } + +/*-------------------------------------------------------------------- + * When closing a TCP connection, a couple of errno's are legit, we + * can't be held responsible for the other end wanting to talk to us. + */ + +void +TCP_close(int *s) +{ + assert (close(*s) == 0 || + errno == ECONNRESET || + errno == ENOTCONN); + *s = -1; +}