TcpAcceptor.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 1996-2023 The Squid Software Foundation and contributors
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 
9 #ifndef SQUID_SRC_COMM_TCPACCEPTOR_H
10 #define SQUID_SRC_COMM_TCPACCEPTOR_H
11 
12 #include "anyp/forward.h"
13 #include "base/AsyncJob.h"
14 #include "base/CbcPointer.h"
15 #include "base/Subscription.h"
16 #include "comm/Flag.h"
17 #include "comm/forward.h"
18 
19 class CommCloseCbParams;
20 
21 namespace Comm
22 {
23 
24 class AcceptLimiter;
25 
38 class TcpAcceptor : public AsyncJob
39 {
41 
42 public:
44 
45 private:
46  void start() override;
47  bool doneAll() const override;
48  void swanSong() override;
49  const char *status() const override;
50 
51  TcpAcceptor(const TcpAcceptor &); // not implemented.
52 
53 public:
54  TcpAcceptor(const Comm::ConnectionPointer &conn, const char *note, const Subscription::Pointer &aSub);
55  TcpAcceptor(const AnyP::PortCfgPointer &listenPort, const char *note, const Subscription::Pointer &aSub);
56 
57 protected:
61  void subscribe(const Subscription::Pointer &aSub);
62 
66  void unsubscribe(const char *reason);
67 
72  void acceptNext();
73 
75  void notify(const Comm::Flag flag, const Comm::ConnectionPointer &details) const;
76 
78  int errcode;
79 
82  static bool okToAccept();
83 
84  friend class AcceptLimiter;
85 
86 private:
88 
92 
95 
98 
100  static void doAccept(int fd, void *data);
101 
102  void acceptOne();
104  void setListen();
105  void handleClosure(const CommCloseCbParams &io);
107  bool intendedForUserConnections() const { return bool(listenPort_); }
108  void logAcceptError(const ConnectionPointer &tcpClient) const;
109 };
110 
111 } // namespace Comm
112 
113 #endif /* SQUID_SRC_COMM_TCPACCEPTOR_H */
114 
AsyncCall::Pointer closer_
listen socket closure handler
Definition: TcpAcceptor.h:97
void swanSong() override
Definition: TcpAcceptor.cc:108
void handleClosure(const CommCloseCbParams &io)
Definition: TcpAcceptor.cc:190
Abstraction layer for TCP, UDP, TLS, UDS and filedescriptor sockets.
Definition: AcceptLimiter.h:16
CbcPointer< Comm::TcpAcceptor > Pointer
Definition: TcpAcceptor.h:43
ConnectionPointer conn
Definition: TcpAcceptor.h:91
bool acceptInto(Comm::ConnectionPointer &)
Definition: TcpAcceptor.cc:344
TcpAcceptor(const TcpAcceptor &)
bool doneAll() const override
whether positive goal has been reached
Definition: TcpAcceptor.cc:91
void unsubscribe(const char *reason)
Definition: TcpAcceptor.cc:68
void notify(const Comm::Flag flag, const Comm::ConnectionPointer &details) const
Call the subscribed callback handler with details about a new connection.
Definition: TcpAcceptor.cc:320
bool intendedForUserConnections() const
whether we are listening on one of the squid.conf *ports
Definition: TcpAcceptor.h:107
Flag
Definition: Flag.h:15
static void doAccept(int fd, void *data)
Method callback for whenever an FD is ready to accept a client connection.
Definition: TcpAcceptor.cc:210
const char * status() const override
internal cleanup; do not call directly
Definition: TcpAcceptor.cc:124
AnyP::PortCfgPointer listenPort_
configuration details of the listening port (if provided)
Definition: TcpAcceptor.h:94
void start() override
called by AsyncStart; do not call directly
Definition: TcpAcceptor.cc:75
void logAcceptError(const ConnectionPointer &tcpClient) const
Definition: TcpAcceptor.cc:248
static bool okToAccept()
Definition: TcpAcceptor.cc:232
void subscribe(const Subscription::Pointer &aSub)
Definition: TcpAcceptor.cc:60
int errcode
errno code of the last accept() or listen() action if one occurred.
Definition: TcpAcceptor.h:78
Subscription::Pointer theCallSub
used to generate AsyncCalls handling our events.
Definition: TcpAcceptor.h:87
CBDATA_CHILD(TcpAcceptor)

 

Introduction

Documentation

Support

Miscellaneous