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