-
/*
- * $Id$
+ * Copyright (C) 1996-2017 The Squid Software Foundation and contributors
+ *
+ * Squid software is distributed under GPLv2+ license and includes
+ * contributions from numerous individuals and organizations.
+ * Please see the COPYING and CONTRIBUTORS files for details.
*/
#ifndef SQUID_COMMCALLS_H
#include "base/AsyncCall.h"
#include "base/AsyncJobCalls.h"
-#include "comm/comm_err_t.h"
+#include "comm/Flag.h"
#include "comm/forward.h"
+#include "MasterXaction.h"
/* CommCalls implement AsyncCall interface for comm_* callbacks.
* The classes cover two call dialer kinds:
* - A C-style call using a function pointer (depricated);
* - A C++-style call to an AsyncJob child.
- * and three comm_* callback kinds:
- * - accept (IOACB),
- * - connect (CNCB),
- * - I/O (IOCB).
+ * and several comm_* callback kinds:
+ * - accept (IOACB)
+ * - connect (CNCB)
+ * - I/O (IOCB)
+ * - timeout (CTCB)
+ * - close (CLCB)
+ * and a special callback kind for passing pipe FD, disk FD or fd_table index 'FD' to the handler:
+ * - FD passing callback (FDECB)
*/
-typedef void IOACB(int fd, const Comm::ConnectionPointer &details, comm_err_t flag, int xerrno, void *data);
-typedef void CNCB(const Comm::ConnectionPointer &conn, comm_err_t status, int xerrno, void *data);
-typedef void IOCB(const Comm::ConnectionPointer &conn, char *, size_t size, comm_err_t flag, int xerrno, void *data);
+class CommAcceptCbParams;
+typedef void IOACB(const CommAcceptCbParams ¶ms);
+
+typedef void CNCB(const Comm::ConnectionPointer &conn, Comm::Flag status, int xerrno, void *data);
+typedef void IOCB(const Comm::ConnectionPointer &conn, char *, size_t size, Comm::Flag flag, int xerrno, void *data);
+
+class CommTimeoutCbParams;
+typedef void CTCB(const CommTimeoutCbParams ¶ms);
+
+class CommCloseCbParams;
+typedef void CLCB(const CommCloseCbParams ¶ms);
+
+class FdeCbParams;
+typedef void FDECB(const FdeCbParams ¶ms);
/*
* TODO: When there are no function-pointer-based callbacks left, all
* known to comm and there are many kinds of parameters.
*/
-
/* Comm*CbParams classes below handle callback parameters */
// Maintains parameters common to all comm callbacks
public:
void *data; // cbdata-protected
+
+ /** The connection which this call pertains to.
+ * - On accept() calls this is the new client connection.
+ * - On connect() finished calls this is the newely opened connection.
+ * - On write calls this is the connection just written to.
+ * - On read calls this is the connection just read from.
+ * - On close calls this describes the connection which is now closed.
+ * - On timeouts this is the connection whose operation timed out.
+ * + NP: timeouts might also return to the connect/read/write handler with Comm::TIMEOUT.
+ */
Comm::ConnectionPointer conn;
- int fd; // raw FD from legacy calls. use conn instead.
- int xerrno;
- comm_err_t flag;
+ Comm::Flag flag; ///< comm layer result status.
+ int xerrno; ///< The last errno to occur. non-zero if flag is Comm::COMM_ERROR.
+
+ int fd; ///< FD which the call was about. Set by the async call creator.
private:
// should not be needed and not yet implemented
CommCommonCbParams &operator =(const CommCommonCbParams ¶ms);
{
public:
CommAcceptCbParams(void *aData);
+
+ void print(std::ostream &os) const;
+
+ /// Transaction which this call is part of.
+ MasterXaction::Pointer xaction;
};
// connect parameters
CommTimeoutCbParams(void *aData);
};
+/// Special Calls parameter, for direct use of an FD without a controlling Comm::Connection
+/// This is used for pipe() FD with helpers, and internally by Comm when handling some special FD actions.
+class FdeCbParams: public CommCommonCbParams
+{
+public:
+ FdeCbParams(void *aData);
+ // TODO make this a standalone object with FD value and pointer to fde table entry.
+ // that requires all the existing Comm handlers to be updated first though
+};
+
// Interface to expose comm callback parameters of all comm dialers.
// GetCommParams() uses this interface to access comm parameters.
template <class Params_>
return dp->params;
}
-
// All job dialers with comm parameters are merged into one since they
// all have exactly one callback argument and differ in Params type only
template <class C, class Params_>
typedef Params_ Params;
typedef void (C::*Method)(const Params &io);
- CommCbMemFunT(const CbcPointer<C> &job, Method meth): JobDialer<C>(job),
- CommDialerParamsT<Params_>(job.get()),
- method(meth) {}
+ CommCbMemFunT(const CbcPointer<C> &aJob, Method aMeth): JobDialer<C>(aJob),
+ CommDialerParamsT<Params_>(aJob->toCbdata()),
+ method(aMeth) {}
virtual bool canDial(AsyncCall &c) {
return JobDialer<C>::canDial(c) &&
virtual void doDial() { ((&(*this->job))->*method)(this->params); }
};
-
// accept (IOACB) dialer
class CommAcceptCbPtrFun: public CallDialer,
- public CommDialerParamsT<CommAcceptCbParams>
+ public CommDialerParamsT<CommAcceptCbParams>
{
public:
typedef CommAcceptCbParams Params;
// connect (CNCB) dialer
class CommConnectCbPtrFun: public CallDialer,
- public CommDialerParamsT<CommConnectCbParams>
+ public CommDialerParamsT<CommConnectCbParams>
{
public:
typedef CommConnectCbParams Params;
CNCB *handler;
};
-
// read/write (IOCB) dialer
class CommIoCbPtrFun: public CallDialer,
- public CommDialerParamsT<CommIoCbParams>
+ public CommDialerParamsT<CommIoCbParams>
{
public:
typedef CommIoCbParams Params;
IOCB *handler;
};
-
-// close (PF) dialer
+// close (CLCB) dialer
class CommCloseCbPtrFun: public CallDialer,
- public CommDialerParamsT<CommCloseCbParams>
+ 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,
- public CommDialerParamsT<CommTimeoutCbParams>
+ public CommDialerParamsT<CommTimeoutCbParams>
{
public:
typedef CommTimeoutCbParams Params;
- CommTimeoutCbPtrFun(PF *aHandler, const Params &aParams);
+ CommTimeoutCbPtrFun(CTCB *aHandler, const Params &aParams);
void dial();
virtual void print(std::ostream &os) const;
public:
- PF *handler;
+ CTCB *handler;
+};
+
+/// FD event (FDECB) dialer
+class FdeCbPtrFun: public CallDialer,
+ public CommDialerParamsT<FdeCbParams>
+{
+public:
+ typedef FdeCbParams Params;
+
+ FdeCbPtrFun(FDECB *aHandler, const Params &aParams);
+ void dial();
+ virtual void print(std::ostream &os) const;
+
+public:
+ FDECB *handler;
};
// AsyncCall to comm handlers implemented as global functions.
inline CommCbFunPtrCallT(int debugSection, int debugLevel,
const char *callName, const Dialer &aDialer);
- inline CommCbFunPtrCallT(const Pointer &p) :
- AsyncCall(p->debugSection, p->debugLevel, p->name),
- dialer(p->dialer)
- {}
+ inline CommCbFunPtrCallT(const CommCbFunPtrCallT &o) :
+ AsyncCall(o.debugSection, o.debugLevel, o.name),
+ dialer(o.dialer) {}
+
+ ~CommCbFunPtrCallT() {}
virtual CallDialer* getDialer() { return &dialer; }
protected:
inline virtual bool canFire();
inline virtual void fire();
+
+private:
+ CommCbFunPtrCallT & operator=(const CommCbFunPtrCallT &); // not defined. not permitted.
};
// Conveninece wrapper: It is often easier to call a templated function than
template <class Dialer>
CommCbFunPtrCallT<Dialer>::CommCbFunPtrCallT(int aDebugSection, int aDebugLevel,
const char *callName, const Dialer &aDialer):
- AsyncCall(aDebugSection, aDebugLevel, callName),
- dialer(aDialer)
+ AsyncCall(aDebugSection, aDebugLevel, callName),
+ dialer(aDialer)
{
}
-
template <class Dialer>
bool
CommCbFunPtrCallT<Dialer>::canFire()
}
#endif /* SQUID_COMMCALLS_H */
+