]>
git.ipfire.org Git - thirdparty/squid.git/blob - src/comm/TcpAcceptor.h
1 #ifndef SQUID_COMM_TCPACCEPTOR_H
2 #define SQUID_COMM_TCPACCEPTOR_H
4 #include "base/AsyncJob.h"
5 #include "base/CbcPointer.h"
6 #include "base/Subscription.h"
8 #include "comm/forward.h"
10 class CommCloseCbParams
;
18 * Listens on a Comm::Connection for new incoming connections and
19 * emits an active Comm::Connection descriptor for the new client.
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.
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.
29 class TcpAcceptor
: public AsyncJob
32 typedef CbcPointer
<Comm::TcpAcceptor
> Pointer
;
36 virtual bool doneAll() const;
37 virtual void swanSong();
38 virtual const char *status() const;
40 TcpAcceptor(const TcpAcceptor
&); // not implemented.
43 TcpAcceptor(const Comm::ConnectionPointer
&conn
, const char *note
, const Subscription::Pointer
&aSub
);
45 /** Subscribe a handler to receive calls back about new connections.
46 * Unsubscribes any existing subscribed handler.
48 void subscribe(const Subscription::Pointer
&aSub
);
50 /** Remove the currently waiting callback subscription.
51 * Already scheduled callbacks remain scheduled.
53 void unsubscribe(const char *reason
);
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.
61 /// Call the subscribed callback handler with details about a new connection.
62 void notify(const Comm::Flag flag
, const Comm::ConnectionPointer
&details
) const;
64 /// errno code of the last accept() or listen() action if one occurred.
68 friend class AcceptLimiter
;
69 int32_t isLimited
; ///< whether this socket is delayed and on the AcceptLimiter queue.
72 Subscription::Pointer theCallSub
; ///< used to generate AsyncCalls handling our events.
74 /// conn being listened on for new connections
75 /// Reserved for read-only use.
76 ConnectionPointer conn
;
78 /// listen socket closure handler
79 AsyncCall::Pointer closer_
;
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();
85 /// Method callback for whenever an FD is ready to accept a client connection.
86 static void doAccept(int fd
, void *data
);
89 Comm::Flag
oldAccept(Comm::ConnectionPointer
&details
);
91 void handleClosure(const CommCloseCbParams
&io
);
93 CBDATA_CLASS2(TcpAcceptor
);
98 #endif /* SQUID_COMM_TCPACCEPTOR_H */