]>
Commit | Line | Data |
---|---|---|
bbc27441 | 1 | /* |
f70aedc4 | 2 | * Copyright (C) 1996-2021 The Squid Software Foundation and contributors |
bbc27441 AJ |
3 | * |
4 | * Squid software is distributed under GPLv2+ license and includes | |
5 | * contributions from numerous individuals and organizations. | |
6 | * Please see the COPYING and CONTRIBUTORS files for details. | |
7 | */ | |
8 | ||
cbff89ba AJ |
9 | #ifndef SQUID_COMM_TCPACCEPTOR_H |
10 | #define SQUID_COMM_TCPACCEPTOR_H | |
04f55905 | 11 | |
fa720bfb | 12 | #include "anyp/forward.h" |
69bb9399 AJ |
13 | #include "base/AsyncJob.h" |
14 | #include "base/CbcPointer.h" | |
5b67dfa4 | 15 | #include "base/Subscription.h" |
c8407295 | 16 | #include "comm/Flag.h" |
f9b72e0c | 17 | #include "comm/forward.h" |
04f55905 | 18 | |
6f09127c AR |
19 | class CommCloseCbParams; |
20 | ||
97b8ac39 A |
21 | namespace Comm |
22 | { | |
04f55905 | 23 | |
5b67dfa4 AJ |
24 | class AcceptLimiter; |
25 | ||
26 | /** | |
27 | * Listens on a Comm::Connection for new incoming connections and | |
28 | * emits an active Comm::Connection descriptor for the new client. | |
29 | * | |
30 | * Handles all event limiting required to quash inbound connection | |
31 | * floods within the global FD limits of available Squid_MaxFD and | |
32 | * client_ip_max_connections. | |
33 | * | |
34 | * Fills the emitted connection with all connection details able to | |
35 | * be looked up. Currently these are the local/remote IP:port details | |
36 | * and the listening socket transparent-mode flag. | |
37 | */ | |
cbff89ba | 38 | class TcpAcceptor : public AsyncJob |
04f55905 | 39 | { |
5c2f68b7 AJ |
40 | CBDATA_CLASS(TcpAcceptor); |
41 | ||
69bb9399 AJ |
42 | public: |
43 | typedef CbcPointer<Comm::TcpAcceptor> Pointer; | |
44 | ||
a9870624 | 45 | private: |
5b67dfa4 AJ |
46 | virtual void start(); |
47 | virtual bool doneAll() const; | |
48 | virtual void swanSong(); | |
cbff89ba AJ |
49 | virtual const char *status() const; |
50 | ||
51 | TcpAcceptor(const TcpAcceptor &); // not implemented. | |
04f55905 AJ |
52 | |
53 | public: | |
8bbb16e3 | 54 | TcpAcceptor(const Comm::ConnectionPointer &conn, const char *note, const Subscription::Pointer &aSub); |
fa720bfb | 55 | TcpAcceptor(const AnyP::PortCfgPointer &listenPort, const char *note, const Subscription::Pointer &aSub); |
04f55905 | 56 | |
0ba55a12 | 57 | /** Subscribe a handler to receive calls back about new connections. |
cbff89ba | 58 | * Unsubscribes any existing subscribed handler. |
0ba55a12 | 59 | */ |
5b67dfa4 | 60 | void subscribe(const Subscription::Pointer &aSub); |
0ba55a12 AJ |
61 | |
62 | /** Remove the currently waiting callback subscription. | |
cbff89ba | 63 | * Already scheduled callbacks remain scheduled. |
0ba55a12 | 64 | */ |
5b67dfa4 | 65 | void unsubscribe(const char *reason); |
0ba55a12 | 66 | |
4c5518e5 AJ |
67 | /** Try and accept another connection (synchronous). |
68 | * If one is pending already the subscribed callback handler will be scheduled | |
69 | * to handle it before this method returns. | |
0ba55a12 | 70 | */ |
04f55905 | 71 | void acceptNext(); |
0ba55a12 AJ |
72 | |
73 | /// Call the subscribed callback handler with details about a new connection. | |
c8407295 | 74 | void notify(const Comm::Flag flag, const Comm::ConnectionPointer &details) const; |
04f55905 | 75 | |
1fc32b95 | 76 | /// errno code of the last accept() or listen() action if one occurred. |
04f55905 AJ |
77 | int errcode; |
78 | ||
f3b976f7 CG |
79 | /// Method to test if there are enough file descriptors to open a new client connection |
80 | /// if not the accept() will be postponed | |
81 | static bool okToAccept(); | |
82 | ||
cbff89ba | 83 | protected: |
5b67dfa4 | 84 | friend class AcceptLimiter; |
cbff89ba AJ |
85 | |
86 | private: | |
5b67dfa4 | 87 | Subscription::Pointer theCallSub; ///< used to generate AsyncCalls handling our events. |
0ba55a12 | 88 | |
5b67dfa4 AJ |
89 | /// conn being listened on for new connections |
90 | /// Reserved for read-only use. | |
91 | ConnectionPointer conn; | |
a9870624 | 92 | |
fa720bfb AJ |
93 | /// configuration details of the listening port (if provided) |
94 | AnyP::PortCfgPointer listenPort_; | |
95 | ||
6f09127c AR |
96 | /// listen socket closure handler |
97 | AsyncCall::Pointer closer_; | |
98 | ||
04f55905 AJ |
99 | /// Method callback for whenever an FD is ready to accept a client connection. |
100 | static void doAccept(int fd, void *data); | |
101 | ||
971581ee | 102 | void acceptOne(); |
c8407295 | 103 | Comm::Flag oldAccept(Comm::ConnectionPointer &details); |
273f66c4 | 104 | void setListen(); |
6f09127c | 105 | void handleClosure(const CommCloseCbParams &io); |
da6dbcd1 EB |
106 | /// whether we are listening on one of the squid.conf *ports |
107 | bool intendedForUserConnections() const { return bool(listenPort_); } | |
ccfbe8f4 | 108 | void logAcceptError(const ConnectionPointer &tcpClient) const; |
273f66c4 | 109 | }; |
04f55905 | 110 | |
b0388924 | 111 | } // namespace Comm |
04f55905 | 112 | |
cbff89ba | 113 | #endif /* SQUID_COMM_TCPACCEPTOR_H */ |
f53969cc | 114 |