LOCK(&bp->mtx);
bp->refcount++;
- UNLOCK(&sp->backend->mtx);
+ UNLOCK(&bp->mtx);
s = -1;
assert(bp->ipv6 != NULL || bp->ipv4 != NULL);
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);
}
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);
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))
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;
+}