1 #ifndef SQUID_COMM_TCPACCEPTOR_H
2 #define SQUID_COMM_TCPACCEPTOR_H
4 #include "anyp/forward.h"
5 #include "base/AsyncJob.h"
6 #include "base/CbcPointer.h"
7 #include "base/Subscription.h"
9 #include "comm/forward.h"
11 class CommCloseCbParams
;
19 * Listens on a Comm::Connection for new incoming connections and
20 * emits an active Comm::Connection descriptor for the new client.
22 * Handles all event limiting required to quash inbound connection
23 * floods within the global FD limits of available Squid_MaxFD and
24 * client_ip_max_connections.
26 * Fills the emitted connection with all connection details able to
27 * be looked up. Currently these are the local/remote IP:port details
28 * and the listening socket transparent-mode flag.
30 class TcpAcceptor
: public AsyncJob
33 typedef CbcPointer
<Comm::TcpAcceptor
> Pointer
;
37 virtual bool doneAll() const;
38 virtual void swanSong();
39 virtual const char *status() const;
41 TcpAcceptor(const TcpAcceptor
&); // not implemented.
44 TcpAcceptor(const Comm::ConnectionPointer
&conn
, const char *note
, const Subscription::Pointer
&aSub
);
45 TcpAcceptor(const AnyP::PortCfgPointer
&listenPort
, const char *note
, const Subscription::Pointer
&aSub
);
47 /** Subscribe a handler to receive calls back about new connections.
48 * Unsubscribes any existing subscribed handler.
50 void subscribe(const Subscription::Pointer
&aSub
);
52 /** Remove the currently waiting callback subscription.
53 * Already scheduled callbacks remain scheduled.
55 void unsubscribe(const char *reason
);
57 /** Try and accept another connection (synchronous).
58 * If one is pending already the subscribed callback handler will be scheduled
59 * to handle it before this method returns.
63 /// Call the subscribed callback handler with details about a new connection.
64 void notify(const Comm::Flag flag
, const Comm::ConnectionPointer
&details
) const;
66 /// errno code of the last accept() or listen() action if one occurred.
70 friend class AcceptLimiter
;
71 int32_t isLimited
; ///< whether this socket is delayed and on the AcceptLimiter queue.
74 Subscription::Pointer theCallSub
; ///< used to generate AsyncCalls handling our events.
76 /// conn being listened on for new connections
77 /// Reserved for read-only use.
78 ConnectionPointer conn
;
80 /// configuration details of the listening port (if provided)
81 AnyP::PortCfgPointer listenPort_
;
83 /// listen socket closure handler
84 AsyncCall::Pointer closer_
;
86 /// Method to test if there are enough file descriptors to open a new client connection
87 /// if not the accept() will be postponed
88 static bool okToAccept();
90 /// Method callback for whenever an FD is ready to accept a client connection.
91 static void doAccept(int fd
, void *data
);
94 Comm::Flag
oldAccept(Comm::ConnectionPointer
&details
);
96 void handleClosure(const CommCloseCbParams
&io
);
98 CBDATA_CLASS2(TcpAcceptor
);
103 #endif /* SQUID_COMM_TCPACCEPTOR_H */