]>
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/AsyncCall.h"
5 #include "base/Subscription.h"
7 #include "comm_err_t.h"
8 #include "comm/TcpAcceptor.h"
9 #include "ip/Address.h"
21 * Listens on an FD for new incoming connections and
22 * emits an active FD descriptor for the new client.
24 * Handles all event limiting required to quash inbound connection
25 * floods within the global FD limits of available Squid_MaxFD and
26 * client_ip_max_connections.
28 * Fills the emitted connection with all connection details able to
29 * be looked up. Currently these are the local/remote IP:port details
30 * and the listening socket transparent-mode flag.
32 class TcpAcceptor
: public AsyncJob
36 virtual bool doneAll() const;
37 virtual void swanSong();
38 virtual const char *status() const;
40 TcpAcceptor(const TcpAcceptor
&); // not implemented.
43 TcpAcceptor(const int listenFd
, const Ip::Address
&laddr
, int flags
,
44 const char *note
, const Subscription::Pointer
&aSub
);
46 /** Subscribe a handler to receive calls back about new connections.
47 * Unsubscribes any existing subscribed handler.
49 void subscribe(const Subscription::Pointer
&aSub
);
51 /** Remove the currently waiting callback subscription.
52 * Already scheduled callbacks remain scheduled.
54 void unsubscribe(const char *reason
);
56 /** Try and accept another connection (synchronous).
57 * If one is pending already the subscribed callback handler will be scheduled
58 * to handle it before this method returns.
62 /// Call the subscribed callback handler with details about a new connection.
63 void notify(const comm_err_t flags
, const ConnectionDetail
&newConnDetails
, const int newFd
) const;
65 /// errno code of the last accept() or listen() action if one occurred.
68 /// conn being listened on for new connections
69 /// Reserved for read-only use.
70 // NP: public only until we can hide it behind connection handles
74 friend class AcceptLimiter
;
75 int32_t isLimited
; ///< whether this socket is delayed and on the AcceptLimiter queue.
78 Subscription::Pointer theCallSub
; ///< used to generate AsyncCalls handling our events.
80 /// IP Address and port being listened on
81 Ip::Address local_addr
;
83 /// Method to test if there are enough file descriptors to open a new client connection
84 /// if not the accept() will be postponed
85 static bool okToAccept();
87 /// Method callback for whenever an FD is ready to accept a client connection.
88 static void doAccept(int fd
, void *data
);
91 comm_err_t
oldAccept(ConnectionDetail
&newConnDetails
, int *fd
);
94 CBDATA_CLASS2(TcpAcceptor
);
99 #endif /* SQUID_COMM_TCPACCEPTOR_H */