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