]>
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"
7 #include "comm/forward.h"
8 #include "comm_err_t.h"
16 * Listens on a Comm::Connection for new incoming connections and
17 * emits an active Comm::Connection descriptor for the new client.
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.
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.
27 class TcpAcceptor
: public AsyncJob
30 typedef CbcPointer
<Comm::TcpAcceptor
> Pointer
;
34 virtual bool doneAll() const;
35 virtual void swanSong();
36 virtual const char *status() const;
38 TcpAcceptor(const TcpAcceptor
&); // not implemented.
41 TcpAcceptor(const Comm::ConnectionPointer
&conn
, const char *note
, const Subscription::Pointer
&aSub
);
43 /** Subscribe a handler to receive calls back about new connections.
44 * Unsubscribes any existing subscribed handler.
46 void subscribe(const Subscription::Pointer
&aSub
);
48 /** Remove the currently waiting callback subscription.
49 * Already scheduled callbacks remain scheduled.
51 void unsubscribe(const char *reason
);
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.
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;
62 /// errno code of the last accept() or listen() action if one occurred.
66 friend class AcceptLimiter
;
67 int32_t isLimited
; ///< whether this socket is delayed and on the AcceptLimiter queue.
70 Subscription::Pointer theCallSub
; ///< used to generate AsyncCalls handling our events.
72 /// conn being listened on for new connections
73 /// Reserved for read-only use.
74 ConnectionPointer conn
;
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();
80 /// Method callback for whenever an FD is ready to accept a client connection.
81 static void doAccept(int fd
, void *data
);
84 comm_err_t
oldAccept(Comm::ConnectionPointer
&details
);
87 CBDATA_CLASS2(TcpAcceptor
);
92 #endif /* SQUID_COMM_TCPACCEPTOR_H */