/* CommCloseCbPtrFun */
-CommCloseCbPtrFun::CommCloseCbPtrFun(PF *aHandler,
+CommCloseCbPtrFun::CommCloseCbPtrFun(CLCB *aHandler,
const CommCloseCbParams &aParams):
CommDialerParamsT<CommCloseCbParams>(aParams),
handler(aHandler)
void
CommCloseCbPtrFun::dial()
{
- handler(params.fd, params.data);
+ handler(params);
}
void
* - connect (CNCB)
* - I/O (IOCB)
* - timeout (CTCB)
+ * - close (CLCB)
*/
class CommAcceptCbParams;
class CommTimeoutCbParams;
typedef void CTCB(const CommTimeoutCbParams ¶ms);
+class CommCloseCbParams;
+typedef void CLCB(const CommCloseCbParams ¶ms);
+
/*
* TODO: When there are no function-pointer-based callbacks left, all
* this complexity can be removed. Jobs that need comm services will just
};
-// close (PF) dialer
+// close (CLCB) dialer
class CommCloseCbPtrFun: public CallDialer,
public CommDialerParamsT<CommCloseCbParams>
{
public:
typedef CommCloseCbParams Params;
- CommCloseCbPtrFun(PF *aHandler, const Params &aParams);
+ CommCloseCbPtrFun(CLCB *aHandler, const Params &aParams);
void dial();
virtual void print(std::ostream &os) const;
public:
- PF *handler;
+ CLCB *handler;
};
class CommTimeoutCbPtrFun:public CallDialer,
void kickReads(int const count);
private:
- static PF CloseHandler;
+ static CLCB CloseHandler;
static DeferredRead popHead(CbDataListContainer<DeferredRead> &deferredReads);
void kickARead(DeferredRead const &);
void flushReads();
// If call is not canceled schedule it for execution else ignore it
if (!call->canceled()) {
debugs(5, 5, "commCallCloseHandlers: ch->handler=" << call);
+ // XXX: this should not be needed. Params can be set by the call creator
typedef CommCloseCbParams Params;
Params ¶ms = GetCommParams<Params>(call);
params.fd = fd;
comm_lingering_close(int fd)
{
#if USE_SSL
-
if (fd_table[fd].ssl)
- ssl_shutdown_method(fd);
-
+ ssl_shutdown_method(fd_table[fd].ssl);
#endif
if (shutdown(fd, 1) < 0) {
comm_close(fd);
}
+#if USE_SSL
void
-comm_close_start(int fd, void *data)
+commStartSslClose(const CommCloseCbParams ¶ms)
{
-#if USE_SSL
- fde *F = &fd_table[fd];
- if (F->ssl)
- ssl_shutdown_method(fd);
-
-#endif
-
+ assert(&fd_table[params.fd].ssl);
+ ssl_shutdown_method(fd_table[params.fd].ssl);
}
+#endif
void
-comm_close_complete(int fd, void *data)
+comm_close_complete(const CommCloseCbParams ¶ms)
{
#if USE_SSL
- fde *F = &fd_table[fd];
+ fde *F = &fd_table[params.fd];
if (F->ssl) {
SSL_free(F->ssl);
F->dynamicSslContext = NULL;
}
#endif
- fd_close(fd); /* update fdstat */
-
- close(fd);
+ fd_close(params.fd); /* update fdstat */
+ close(params.fd);
statCounter.syscalls.sock.closes++;
- /* When an fd closes, give accept() a chance, if need be */
+ /* When one connection closes, give accept() a chance, if need be */
Comm::AcceptLimiter::Instance().kick();
}
F->flags.close_request = 1;
- AsyncCall::Pointer startCall=commCbCall(5,4, "comm_close_start",
- CommCloseCbPtrFun(comm_close_start, NULL));
- typedef CommCloseCbParams Params;
- Params &startParams = GetCommParams<Params>(startCall);
- startParams.fd = fd;
- ScheduleCallHere(startCall);
+#if USE_SSL
+ if (F->ssl) {
+ // XXX: make this a generic async call passing one FD parameter. No need to use CommCloseCbParams
+ AsyncCall::Pointer startCall=commCbCall(5,4, "commStartSslClose",
+ CommCloseCbPtrFun(commStartSslClose, NULL));
+ CommCloseCbParams &startParams = GetCommParams<CommCloseCbParams>(startCall);
+ startParams.fd = fd;
+ ScheduleCallHere(startCall);
+ }
+#endif
// a half-closed fd may lack a reader, so we stop monitoring explicitly
if (commHasHalfClosedMonitor(fd))
AsyncCall::Pointer completeCall=commCbCall(5,4, "comm_close_complete",
CommCloseCbPtrFun(comm_close_complete, NULL));
- Params &completeParams = GetCommParams<Params>(completeCall);
+ CommCloseCbParams &completeParams = GetCommParams<CommCloseCbParams>(completeCall);
completeParams.fd = fd;
// must use async call to wait for all callbacks
// scheduled before comm_close() to finish
}
void
-comm_add_close_handler(int fd, PF * handler, void *data)
+comm_add_close_handler(int fd, CLCB * handler, void *data)
{
debugs(5, 5, "comm_add_close_handler: FD " << fd << ", handler=" <<
handler << ", data=" << data);
// remove function-based close handler
void
-comm_remove_close_handler(int fd, PF * handler, void *data)
+comm_remove_close_handler(int fd, CLCB * handler, void *data)
{
assert (isOpen(fd));
/* Find handler in list */
// We have to use a global function as a closer and point to temp
// instead of "this" because DeferredReadManager is not a job and
// is not even cbdata protected
+ // XXX: and yet we use cbdata protection functions on it??
AsyncCall::Pointer closer = commCbCall(5,4,
"DeferredReadManager::CloseHandler",
CommCloseCbPtrFun(&CloseHandler, temp));
}
void
-DeferredReadManager::CloseHandler(int fd, void *thecbdata)
+DeferredReadManager::CloseHandler(const CommCloseCbParams ¶ms)
{
- if (!cbdataReferenceValid (thecbdata))
+ if (!cbdataReferenceValid(params.data))
return;
- CbDataList<DeferredRead> *temp = (CbDataList<DeferredRead> *)thecbdata;
+ CbDataList<DeferredRead> *temp = (CbDataList<DeferredRead> *)params.data;
temp->element.closer = NULL;
temp->element.markCancelled();
//typedef void IOACB(int fd, int nfd, Comm::ConnectionPointer details, comm_err_t flag, int xerrno, void *data);
-extern void comm_add_close_handler(int fd, PF *, void *);
+extern void comm_add_close_handler(int fd, CLCB *, void *);
extern void comm_add_close_handler(int fd, AsyncCall::Pointer &);
-extern void comm_remove_close_handler(int fd, PF *, void *);
+extern void comm_remove_close_handler(int fd, CLCB *, void *);
extern void comm_remove_close_handler(int fd, AsyncCall::Pointer &);
static EVH idnsCheckQueue;
static void idnsTickleQueue(void);
static void idnsRcodeCount(int, int);
-static void idnsVCClosed(int fd, void *data);
+static CLCB idnsVCClosed;
static unsigned short idnsQueryID(void);
static void
}
static void
-idnsVCClosed(int fd, void *data)
+idnsVCClosed(const CommCloseCbParams ¶ms)
{
- nsvc * vc = (nsvc *)data;
+ nsvc * vc = (nsvc *)params.data;
delete vc->queue;
delete vc->msg;
vc->conn = NULL;
#endif
static PSC fwdPeerSelectionCompleteWrapper;
-static PF fwdServerClosedWrapper;
+static CLCB fwdServerClosedWrapper;
#if USE_SSL
static PF fwdNegotiateSSLWrapper;
#endif
}
static void
-fwdServerClosedWrapper(int fd, void *data)
+fwdServerClosedWrapper(const CommCloseCbParams ¶ms)
{
- FwdState *fwd = (FwdState *) data;
- fwd->serverClosed(fd);
+ FwdState *fwd = (FwdState *)params.data;
+ fwd->serverClosed(params.fd);
}
#if USE_SSL
char replybuf[BUFSIZ];
} GopherStateData;
-static PF gopherStateFree;
+static CLCB gopherStateFree;
static void gopherMimeCreate(GopherStateData *);
static void gopher_request_parse(const HttpRequest * req,
char *type_id,
/// \ingroup ServerProtocolGopherInternal
static void
-gopherStateFree(int, void *data)
+gopherStateFree(const CommCloseCbParams ¶ms)
{
- GopherStateData *gopherState = (GopherStateData *)data;
+ GopherStateData *gopherState = (GopherStateData *)params.data;
if (gopherState == NULL)
return;
static IOCB helperHandleRead;
static IOCB helperStatefulHandleRead;
-static PF helperServerFree;
-static PF helperStatefulServerFree;
+static CLCB helperServerFree;
+static CLCB helperStatefulServerFree;
static void Enqueue(helper * hlp, helper_request *);
static helper_request *Dequeue(helper * hlp);
static helper_stateful_request *StatefulDequeue(statefulhelper * hlp);
/* ====================================================================== */
static void
-helperServerFree(int fd, void *data)
+helperServerFree(const CommCloseCbParams ¶ms)
{
- helper_server *srv = (helper_server *)data;
+ helper_server *srv = (helper_server *)params.data;
helper *hlp = srv->parent;
helper_request *r;
int i, concurrency = hlp->childs.concurrency;
if (!srv->flags.shutdown) {
assert(hlp->childs.n_active > 0);
hlp->childs.n_active--;
- debugs(84, DBG_CRITICAL, "WARNING: " << hlp->id_name << " #" << srv->index + 1 << " (FD " << fd << ") exited");
+ debugs(84, DBG_CRITICAL, "WARNING: " << hlp->id_name << " #" << srv->index + 1 << " (FD " << params.fd << ") exited");
if (hlp->childs.needNew() > 0) {
debugs(80, 1, "Too few " << hlp->id_name << " processes are running (need " << hlp->childs.needNew() << "/" << hlp->childs.n_max << ")");
}
static void
-helperStatefulServerFree(int fd, void *data)
+helperStatefulServerFree(const CommCloseCbParams ¶ms)
{
- helper_stateful_server *srv = (helper_stateful_server *)data;
+ helper_stateful_server *srv = (helper_stateful_server *)params.data;
statefulhelper *hlp = srv->parent;
helper_stateful_request *r;
if (!srv->flags.shutdown) {
assert( hlp->childs.n_active > 0);
hlp->childs.n_active--;
- debugs(84, 0, "WARNING: " << hlp->id_name << " #" << srv->index + 1 << " (FD " << fd << ") exited");
+ debugs(84, 0, "WARNING: " << hlp->id_name << " #" << srv->index + 1 << " (FD " << params.fd << ") exited");
if (hlp->childs.needNew() > 0) {
debugs(80, 1, "Too few " << hlp->id_name << " processes are running (need " << hlp->childs.needNew() << "/" << hlp->childs.n_max << ")");
// TODO: make these all a series of Async job calls. They are self-contained callbacks now.
static IOCB ReadReply;
-static PF Close;
+static CLCB Close;
static CTCB Timeout;
static CNCB ConnectDone;
static hash_table *ident_hash = NULL;
}
void
-Ident::Close(int fdnotused, void *data)
+Ident::Close(const CommCloseCbParams ¶ms)
{
- IdentStateData *state = (IdentStateData *)data;
+ IdentStateData *state = (IdentStateData *)params.data;
identCallback(state, NULL);
state->conn->close();
hash_remove_link(ident_hash, (hash_link *) state);
}
void
-ssl_shutdown_method(int fd)
+ssl_shutdown_method(SSL *ssl)
{
- SSL *ssl = fd_table[fd].ssl;
-
SSL_shutdown(ssl);
}
int ssl_write_method(int, const char *, int);
/// \ingroup ServerProtocolSSLAPI
-void ssl_shutdown_method(int);
+void ssl_shutdown_method(SSL *ssl);
/// \ingroup ServerProtocolSSLAPI
static CNCB tunnelConnectDone;
static ERCB tunnelErrorComplete;
-static PF tunnelServerClosed;
-static PF tunnelClientClosed;
+static CLCB tunnelServerClosed;
+static CLCB tunnelClientClosed;
static CTCB tunnelTimeout;
static PSC tunnelPeerSelectComplete;
static void tunnelStateFree(TunnelStateData * tunnelState);
static void tunnelRelayConnectRequest(const Comm::ConnectionPointer &server, void *);
static void
-tunnelServerClosed(int fd, void *data)
+tunnelServerClosed(const CommCloseCbParams ¶ms)
{
- TunnelStateData *tunnelState = (TunnelStateData *)data;
- debugs(26, 3, HERE << "FD " << fd);
+ TunnelStateData *tunnelState = (TunnelStateData *)params.data;
+ debugs(26, 3, HERE << tunnelState->server.conn);
tunnelState->server.conn = NULL;
if (tunnelState->noConnections()) {
}
static void
-tunnelClientClosed(int fd, void *data)
+tunnelClientClosed(const CommCloseCbParams ¶ms)
{
- TunnelStateData *tunnelState = (TunnelStateData *)data;
- debugs(26, 3, HERE << "FD " << fd);
+ TunnelStateData *tunnelState = (TunnelStateData *)params.data;
+ debugs(26, 3, HERE << tunnelState->client.conn);
tunnelState->client.conn = NULL;
if (tunnelState->noConnections()) {
bool dataWritten;
};
-static PF whoisClose;
+static CLCB whoisClose;
static CTCB whoisTimeout;
static IOCB whoisReadReply;
}
static void
-whoisClose(int fd, void *data)
+whoisClose(const CommCloseCbParams ¶ms)
{
- WhoisState *p = (WhoisState *)data;
- debugs(75, 3, "whoisClose: FD " << fd);
+ WhoisState *p = (WhoisState *)params.data;
+ debugs(75, 3, "whoisClose: FD " << params.fd);
p->entry->unlock();
cbdataFree(p);
}