]> git.ipfire.org Git - thirdparty/squid.git/blob - src/comm/TcpAcceptor.h
Merged from trunk r13474.
[thirdparty/squid.git] / src / comm / TcpAcceptor.h
1 #ifndef SQUID_COMM_TCPACCEPTOR_H
2 #define SQUID_COMM_TCPACCEPTOR_H
3
4 #include "base/AsyncJob.h"
5 #include "base/CbcPointer.h"
6 #include "base/Subscription.h"
7 #include "comm/Flag.h"
8 #include "comm/forward.h"
9
10 class CommCloseCbParams;
11
12 namespace Comm
13 {
14
15 class AcceptLimiter;
16
17 /**
18 * Listens on a Comm::Connection for new incoming connections and
19 * emits an active Comm::Connection descriptor for the new client.
20 *
21 * Handles all event limiting required to quash inbound connection
22 * floods within the global FD limits of available Squid_MaxFD and
23 * client_ip_max_connections.
24 *
25 * Fills the emitted connection with all connection details able to
26 * be looked up. Currently these are the local/remote IP:port details
27 * and the listening socket transparent-mode flag.
28 */
29 class TcpAcceptor : public AsyncJob
30 {
31 public:
32 typedef CbcPointer<Comm::TcpAcceptor> Pointer;
33
34 private:
35 virtual void start();
36 virtual bool doneAll() const;
37 virtual void swanSong();
38 virtual const char *status() const;
39
40 TcpAcceptor(const TcpAcceptor &); // not implemented.
41
42 public:
43 TcpAcceptor(const Comm::ConnectionPointer &conn, const char *note, const Subscription::Pointer &aSub);
44
45 /** Subscribe a handler to receive calls back about new connections.
46 * Unsubscribes any existing subscribed handler.
47 */
48 void subscribe(const Subscription::Pointer &aSub);
49
50 /** Remove the currently waiting callback subscription.
51 * Already scheduled callbacks remain scheduled.
52 */
53 void unsubscribe(const char *reason);
54
55 /** Try and accept another connection (synchronous).
56 * If one is pending already the subscribed callback handler will be scheduled
57 * to handle it before this method returns.
58 */
59 void acceptNext();
60
61 /// Call the subscribed callback handler with details about a new connection.
62 void notify(const Comm::Flag flag, const Comm::ConnectionPointer &details) const;
63
64 /// errno code of the last accept() or listen() action if one occurred.
65 int errcode;
66
67 protected:
68 friend class AcceptLimiter;
69 int32_t isLimited; ///< whether this socket is delayed and on the AcceptLimiter queue.
70
71 private:
72 Subscription::Pointer theCallSub; ///< used to generate AsyncCalls handling our events.
73
74 /// conn being listened on for new connections
75 /// Reserved for read-only use.
76 ConnectionPointer conn;
77
78 /// listen socket closure handler
79 AsyncCall::Pointer closer_;
80
81 /// Method to test if there are enough file descriptors to open a new client connection
82 /// if not the accept() will be postponed
83 static bool okToAccept();
84
85 /// Method callback for whenever an FD is ready to accept a client connection.
86 static void doAccept(int fd, void *data);
87
88 void acceptOne();
89 Comm::Flag oldAccept(Comm::ConnectionPointer &details);
90 void setListen();
91 void handleClosure(const CommCloseCbParams &io);
92
93 CBDATA_CLASS2(TcpAcceptor);
94 };
95
96 } // namespace Comm
97
98 #endif /* SQUID_COMM_TCPACCEPTOR_H */