]> git.ipfire.org Git - thirdparty/squid.git/blobdiff - src/comm/TcpAcceptor.h
SourceFormat Enforcement
[thirdparty/squid.git] / src / comm / TcpAcceptor.h
index 1c3a12fb03bbfec731da98e826abb3be53d3fb5c..c1a7d857bec67802cca461df28aa5e75b21d00dc 100644 (file)
@@ -1,16 +1,22 @@
+/*
+ * Copyright (C) 1996-2017 The Squid Software Foundation and contributors
+ *
+ * Squid software is distributed under GPLv2+ license and includes
+ * contributions from numerous individuals and organizations.
+ * Please see the COPYING and CONTRIBUTORS files for details.
+ */
+
 #ifndef SQUID_COMM_TCPACCEPTOR_H
 #define SQUID_COMM_TCPACCEPTOR_H
 
-#include "base/AsyncCall.h"
+#include "anyp/forward.h"
+#include "base/AsyncJob.h"
+#include "base/CbcPointer.h"
 #include "base/Subscription.h"
-#include "CommCalls.h"
-#include "comm_err_t.h"
-#include "comm/TcpAcceptor.h"
-#include "ip/Address.h"
+#include "comm/Flag.h"
+#include "comm/forward.h"
 
-#if HAVE_MAP
-#include <map>
-#endif
+class CommCloseCbParams;
 
 namespace Comm
 {
@@ -18,8 +24,8 @@ namespace Comm
 class AcceptLimiter;
 
 /**
- * Listens on an FD for new incoming connections and
- * emits an active FD descriptor for the new client.
+ * Listens on a Comm::Connection for new incoming connections and
+ * emits an active Comm::Connection descriptor for the new client.
  *
  * Handles all event limiting required to quash inbound connection
  * floods within the global FD limits of available Squid_MaxFD and
@@ -31,6 +37,11 @@ class AcceptLimiter;
  */
 class TcpAcceptor : public AsyncJob
 {
+    CBDATA_CLASS(TcpAcceptor);
+
+public:
+    typedef CbcPointer<Comm::TcpAcceptor> Pointer;
+
 private:
     virtual void start();
     virtual bool doneAll() const;
@@ -40,8 +51,8 @@ private:
     TcpAcceptor(const TcpAcceptor &); // not implemented.
 
 public:
-    TcpAcceptor(const int listenFd, const Ip::Address &laddr, int flags,
-                const char *note, const Subscription::Pointer &aSub);
+    TcpAcceptor(const Comm::ConnectionPointer &conn, const char *note, const Subscription::Pointer &aSub);
+    TcpAcceptor(const AnyP::PortCfgPointer &listenPort, const char *note, const Subscription::Pointer &aSub);
 
     /** Subscribe a handler to receive calls back about new connections.
      * Unsubscribes any existing subscribed handler.
@@ -60,16 +71,11 @@ public:
     void acceptNext();
 
     /// Call the subscribed callback handler with details about a new connection.
-    void notify(const comm_err_t flags, const ConnectionDetail &newConnDetails, const int newFd) const;
+    void notify(const Comm::Flag flag, const Comm::ConnectionPointer &details) const;
 
     /// errno code of the last accept() or listen() action if one occurred.
     int errcode;
 
-    /// conn being listened on for new connections
-    /// Reserved for read-only use.
-    // NP: public only until we can hide it behind connection handles
-    int fd;
-
 protected:
     friend class AcceptLimiter;
     int32_t isLimited;                   ///< whether this socket is delayed and on the AcceptLimiter queue.
@@ -77,8 +83,15 @@ protected:
 private:
     Subscription::Pointer theCallSub;    ///< used to generate AsyncCalls handling our events.
 
-    /// IP Address and port being listened on
-    Ip::Address local_addr;
+    /// conn being listened on for new connections
+    /// Reserved for read-only use.
+    ConnectionPointer conn;
+
+    /// configuration details of the listening port (if provided)
+    AnyP::PortCfgPointer listenPort_;
+
+    /// listen socket closure handler
+    AsyncCall::Pointer closer_;
 
     /// Method to test if there are enough file descriptors to open a new client connection
     /// if not the accept() will be postponed
@@ -88,12 +101,14 @@ private:
     static void doAccept(int fd, void *data);
 
     void acceptOne();
-    comm_err_t oldAccept(ConnectionDetail &newConnDetails, int *fd);
+    Comm::Flag oldAccept(Comm::ConnectionPointer &details);
     void setListen();
-
-    CBDATA_CLASS2(TcpAcceptor);
+    void handleClosure(const CommCloseCbParams &io);
+    /// whether we are listening on one of the squid.conf *ports
+    bool intendedForUserConnections() const { return bool(listenPort_); }
 };
 
 } // namespace Comm
 
 #endif /* SQUID_COMM_TCPACCEPTOR_H */
+