Commit 63253f48 authored by Poul-Henning Kamp's avatar Poul-Henning Kamp

Make a central TCP_close() function that accepts the two errno's which

indicate that our partner gave up on us.



git-svn-id: http://www.varnish-cache.org/svn/trunk/varnish-cache@3083 d4fa192b-c00b-0410-8231-f00ffab90ce4
parent 1b68a1f7
......@@ -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);
......
......@@ -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))
......
......@@ -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;
}
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