void writeServerDone(char *buf, size_t len, comm_err_t flag, int xerrno);
};
+#define fd_closed(fd) (fd == -1 || fd_table[fd].closing())
+
static const char *const conn_established = "HTTP/1.0 200 Connection established\r\n\r\n";
static CNCB tunnelConnectDone;
cbdataInternalLock(this); /* ??? should be locked by the caller... */
/* Bump the server connection timeout on any activity */
- if (server.fd() != -1)
+ if (!fd_closed(server.fd()))
commSetTimeout(server.fd(), Config.Timeout.read, tunnelTimeout, this);
if (len < 0 || errcode)
from.error (xerrno);
- else if (len == 0 || to.fd() == -1) {
+ else if (len == 0 || fd_closed(to.fd())) {
comm_close(from.fd());
/* Only close the remote end if we've finished queueing data to it */
- if (from.len == 0 && to.fd() != -1) {
+ if (from.len == 0 && !fd_closed(to.fd()) ) {
comm_close(to.fd());
}
} else if (cbdataReferenceValid(this))
client.dataSent(len);
/* If the other end has closed, so should we */
- if (client.fd() == -1) {
+ if (fd_closed(client.fd())) {
comm_close(server.fd());
return;
}
server.dataSent(len);
/* If the other end has closed, so should we */
- if (server.fd() == -1) {
+ if (fd_closed(server.fd())) {
comm_close(client.fd());
return;
}
void
TunnelStateData::Connection::closeIfOpen()
{
- if (fd() != -1)
+ if (!fd_closed(fd()))
comm_close(fd());
}
/* temporary lock to save our own feets (comm_close -> tunnelClientClosed -> Free) */
cbdataInternalLock(tunnelState);
- if (tunnelState->client.fd() > -1)
+ if (!fd_closed(tunnelState->client.fd()))
comm_close(tunnelState->client.fd());
- if (tunnelState->server.fd() > -1)
+ if (fd_closed(tunnelState->server.fd()))
comm_close(tunnelState->server.fd());
cbdataInternalUnlock(tunnelState);
bool
TunnelStateData::noConnections() const
{
- return (server.fd() == -1) && (client.fd() == -1);
+ return fd_closed(server.fd()) && fd_closed(client.fd());
}
#if DELAY_POOLS