]> git.ipfire.org Git - thirdparty/squid.git/blob - src/comm/TcpAcceptor.h
Broken: define and use stub_libauth.cc
[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/forward.h"
8 #include "comm_err_t.h"
9
10 namespace Comm
11 {
12
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 */
27 class TcpAcceptor : public AsyncJob
28 {
29 public:
30 typedef CbcPointer<Comm::TcpAcceptor> Pointer;
31
32 private:
33 virtual void start();
34 virtual bool doneAll() const;
35 virtual void swanSong();
36 virtual const char *status() const;
37
38 TcpAcceptor(const TcpAcceptor &); // not implemented.
39
40 public:
41 TcpAcceptor(const Comm::ConnectionPointer &conn, const char *note, const Subscription::Pointer &aSub);
42
43 /** Subscribe a handler to receive calls back about new connections.
44 * Unsubscribes any existing subscribed handler.
45 */
46 void subscribe(const Subscription::Pointer &aSub);
47
48 /** Remove the currently waiting callback subscription.
49 * Already scheduled callbacks remain scheduled.
50 */
51 void unsubscribe(const char *reason);
52
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.
56 */
57 void acceptNext();
58
59 /// Call the subscribed callback handler with details about a new connection.
60 void notify(const comm_err_t flag, const Comm::ConnectionPointer &details) const;
61
62 /// errno code of the last accept() or listen() action if one occurred.
63 int errcode;
64
65 protected:
66 friend class AcceptLimiter;
67 int32_t isLimited; ///< whether this socket is delayed and on the AcceptLimiter queue.
68
69 private:
70 Subscription::Pointer theCallSub; ///< used to generate AsyncCalls handling our events.
71
72 /// conn being listened on for new connections
73 /// Reserved for read-only use.
74 ConnectionPointer conn;
75
76 /// Method to test if there are enough file descriptors to open a new client connection
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
83 void acceptOne();
84 comm_err_t oldAccept(Comm::ConnectionPointer &details);
85 void setListen();
86
87 CBDATA_CLASS2(TcpAcceptor);
88 };
89
90 } // namespace Comm
91
92 #endif /* SQUID_COMM_TCPACCEPTOR_H */