Comm::AcceptLimiter::Instance().kick();
}
-/*
- * Close the socket fd in use by a connection.
- */
-void
-_comm_close(Comm::ConnectionPointer conn, char const *file, int line)
-{
- _comm_close(conn->fd, file, line);
- conn->fd = -1;
-}
-
/*
* Close the socket fd.
*
SQUIDCEXTERN void commSetCloseOnExec(int fd);
SQUIDCEXTERN void commSetTcpKeepalive(int fd, int idle, int interval, int timeout);
extern void _comm_close(int fd, char const *file, int line);
-extern void _comm_close(Comm::ConnectionPointer conn, char const *file, int line);
#define comm_close(x) (_comm_close((x), __FILE__, __LINE__))
SQUIDCEXTERN void comm_reset_close(int fd);
#if LINGERING_CLOSE
SQUIDCEXTERN void comm_lingering_close(int fd);
#endif
-SQUIDCEXTERN void commConnectStart(int fd, const char *, u_short, CNCB *, void *);
-void commConnectStart(int fd, const char *, u_short, AsyncCall::Pointer &cb);
SQUIDCEXTERN int comm_connect_addr(int sock, const Ip::Address &addr);
SQUIDCEXTERN void comm_init(void);
Comm::Connection::~Connection()
{
- if (fd >= 0) {
- comm_close(fd);
- }
+ close();
if (_peer) {
cbdataReferenceDone(_peer);
}
}
+void
+Comm::Connection::close()
+{
+ if (isOpen())
+ comm_close(fd);
+ fd = -1;
+}
+
void
Comm::Connection::setPeer(peer *p)
{
* object for state data. But a semantic equivalent for FD with easily
* accessible cached properties not requiring repeated complex lookups.
*
- * While the properties may be changed, they should be considered read-only
- * outside of the Comm layer code.
+ * While the properties may be changed, this is for teh purpose of creating
+ * potential connection descriptors which may be opened. Properties should
+ * be considered read-only outside of the Comm layer code once the connection
+ * is open.
*
* These objects must not be passed around directly,
* but a Comm::ConnectionPointer must be passed instead.
/** see Comm::Connection::Connection */
const Connection & operator =(const Connection &c);
+ void close();
+
+ /** determine whether this object describes an active connection or not. */
+ bool isOpen() { return (fd >= 0); }
+
/** Address/Port for the Squid end of a TCP link. */
Ip::Address local;
-
/*
* $Id$
*
#include "squid.h"
#include "CacheManager.h"
+#include "comm/Connection.h"
#include "comm/ConnectStateData.h"
#include "comm.h"
#include "event.h"
FwdState* fwd = (FwdState*)d;
Pointer tmp = fwd; // Grab a temporary pointer to keep the object alive during our scope.
- if (fwd->paths[0]->fd >= 0) {
- comm_close(fwd->paths[0]);
- }
-
+ fwd->paths[0]->close();
fwd->self = NULL;
}
if (paths[0]->fd > -1) {
comm_remove_close_handler(paths[0]->fd, fwdServerClosedWrapper, this);
debugs(17, 3, HERE << "closing FD " << paths[0]->fd);
- comm_close(paths[0]);
+ paths[0]->close();
}
paths.clean();
paths[0]->getPeer()->stats.conn_open--;
}
- comm_close(paths[0]);
+ paths[0]->close();
return;
}
}
if (paths[0]->getPeer())
peerConnectFailed(paths[0]->getPeer());
- comm_close(paths[0]);
+ paths[0]->close();
}
return;
peerConnectFailed(paths[0]->getPeer());
}
- comm_close(paths[0]);
+ paths[0]->close();
}
/**
ConnStateData *pinned_connection = request->pinnedConnection();
assert(pinned_connection);
conn->fd = pinned_connection->validatePinnedConnection(request, conn->getPeer());
- if (conn->fd >= 0) {
+ if (conn->isOpen()) {
pinned_connection->unpinConnection();
#if 0
if (!conn->getPeer())
}
conn->remote.SetPort(port);
- if (conn->fd >= 0) {
+ if (conn->isOpen()) {
debugs(17, 3, HERE << "reusing pconn FD " << conn->fd);
n_tries++;
* transient (network) error; its a bug.
*/
flags.dont_retry = 1;
- comm_close(paths[0]);
+ paths[0]->close();
break;
}
}
int n;
u_short port;
Ip::Address ipa_remote;
- int fd = ftpState->data.fd;
char *buf;
LOCAL_ARRAY(char, ipaddr, 1024);
debugs(9, 3, HERE);
fd_table[ctrl.fd].ipaddr);
/* close the bad sources connection down ASAP. */
- comm_close(io.details);
+ Comm::ConnectionPointer nonConst = io.details;
+ nonConst->close();
/* we are ony accepting once, so need to re-open the listener socket. */
typedef CommCbMemFunT<FtpStateData, CommAcceptCbParams> acceptDialer;
gopherToHTML(gopherState, (char *) NULL, 0);
fwd->complete();
- comm_close(fwd->conn());
+ fwd->conn()->close();
return;
}
#if USE_IDENT
#include "comm.h"
+#include "comm/Connection.h"
#include "comm/ConnectStateData.h"
#include "CommCalls.h"
#include "ident/Config.h"
{
IdentStateData *state = (IdentStateData *)data;
identCallback(state, NULL);
- comm_close(&(state->conn));
+ state->conn.close();
hash_remove_link(ident_hash, (hash_link *) state);
xfree(state->hash.key);
cbdataFree(state);
{
IdentStateData *state = (IdentStateData *)data;
debugs(30, 3, HERE << "FD " << fd << ", " << state->conn.remote);
- comm_close(&(state->conn));
+ state->conn.close();
}
void
if (c == NULL) {
/* no clients care */
- comm_close(conn);
+ conn->close();
return;
}
assert(fd == state->conn.fd);
if (flag != COMM_OK || len <= 0) {
- comm_close(&(state->conn));
+ state->conn.close();
return;
}
}
}
- comm_close(&(state->conn));
+ state->conn.close();
}
void
* of scheduling an async call. This reentrant behavior means that the
* user job must be extra careful after calling ipcache_nbgethostbyname,
* especially if the handler destroys the job. Moreover, the job has
- * no way of knowing whether the reentrant call happened. commConnectStart
- * protects the job by scheduling an async call, but some user code calls
- * ipcache_nbgethostbyname directly.
+ * no way of knowing whether the reentrant call happened.
+ * Comm::Connection setup usually protects the job by scheduling an async call,
+ * but some user code calls ipcache_nbgethostbyname directly.
*/
void
ipcache_nbgethostbyname(const char *name, IPH * handler, void *handlerData)
#include "squid.h"
#include "ProtoPort.h"
#include "acl/FilledChecklist.h"
-#include "event.h"
+#include "comm/Connection.h"
+#include "comm/ConnectStateData.h"
#include "CacheManager.h"
+#include "event.h"
#include "htcp.h"
#include "HttpRequest.h"
#include "ICP.h"
#include "Store.h"
#include "icmp/net_db.h"
#include "ip/Address.h"
-#include "comm/ConnectStateData.h"
/* count mcast group peers every 15 minutes */
#define MCAST_COUNT_RATE 900
peerConnectFailedSilent(p);
}
- comm_close(conn);
+ conn->close();
p->testing_now = false;
return;
}