return commSetConnTimeout(conn, -1, nil);
}
+
+/**
+ * Connect socket FD to given remote address.
+ * If return value is an error flag (COMM_ERROR, ERR_CONNECT, ERR_PROTOCOL, etc.),
+ * then error code will also be returned in errno.
+ */
int
comm_connect_addr(int sock, const Ip::Address &address)
{
address.getAddrInfo(AI, F->sock_family);
/* Establish connection. */
- errno = 0;
+ int xerrno = 0;
if (!F->flags.called_connect) {
F->flags.called_connect = true;
// Async calls development will fix this.
if (x == 0) {
x = -1;
- errno = EINPROGRESS;
- }
-
- if (x < 0) {
+ xerrno = EINPROGRESS;
+ } else if (x < 0) {
debugs(5,5, "comm_connect_addr: sock=" << sock << ", addrinfo( " <<
" flags=" << AI->ai_flags <<
", family=" << AI->ai_family <<
", &addr=" << AI->ai_addr <<
", addrlen=" << AI->ai_addrlen <<
" )" );
- debugs(5, 9, "connect FD " << sock << ": (" << x << ") " << xstrerror());
+ debugs(5, 9, "connect FD " << sock << ": (" << x << ") " << xstrerr(xerrno));
debugs(14,9, "connecting to: " << address );
}
+
} else {
+ errno = 0;
#if _SQUID_NEWSOS6_
/* Makoto MATSUSHITA <matusita@ics.es.osaka-u.ac.jp> */
+ if (connect(sock, AI->ai_addr, AI->ai_addrlen) < 0)
+ xerrno = errno;
- connect(sock, AI->ai_addr, AI->ai_addrlen);
-
- if (errno == EINVAL) {
+ if (xerrno == EINVAL) {
errlen = sizeof(err);
x = getsockopt(sock, SOL_SOCKET, SO_ERROR, &err, &errlen);
-
if (x >= 0)
- errno = x;
+ xerrno = x;
}
-
#else
errlen = sizeof(err);
-
x = getsockopt(sock, SOL_SOCKET, SO_ERROR, &err, &errlen);
-
if (x == 0)
- errno = err;
+ xerrno = err;
#if _SQUID_SOLARIS_
/*
* connect and just returns EPIPE. Create a fake
* error message for connect. -- fenner@parc.xerox.com
*/
- if (x < 0 && errno == EPIPE)
- errno = ENOTCONN;
-
+ if (x < 0 && xerrno == EPIPE)
+ xerrno = ENOTCONN;
+ else
+ xerrno = errno;
#endif
#endif
-
}
Ip::Address::FreeAddr(AI);
PROF_stop(comm_connect_addr);
- if (errno == 0 || errno == EISCONN)
+ errno = xerrno;
+ if (xerrno == 0 || xerrno == EISCONN)
status = Comm::OK;
- else if (ignoreErrno(errno))
+ else if (ignoreErrno(xerrno))
status = Comm::INPROGRESS;
- else if (errno == EAFNOSUPPORT || errno == EINVAL)
+ else if (xerrno == EAFNOSUPPORT || xerrno == EINVAL)
return Comm::ERR_PROTOCOL;
else
return Comm::COMM_ERROR;
debugs(5, DBG_DATA, "comm_connect_addr: FD " << sock << " connection pending");
}
+ errno = xerrno;
return status;
}