]> git.ipfire.org Git - thirdparty/squid.git/blobdiff - src/ipc/Port.cc
SourceFormat Enforcement
[thirdparty/squid.git] / src / ipc / Port.cc
index b02c18ee4960e2daf17f1091fd5d9c843ff5e93d..88489dabeb7a45f507cd87c28370db20ff528ac2 100644 (file)
@@ -1,18 +1,25 @@
 /*
- * $Id$
- *
- * DEBUG: section 54    Interprocess Communication
+ * 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.
  */
 
+/* DEBUG: section 54    Interprocess Communication */
 
-#include "config.h"
+#include "squid.h"
+#include "comm.h"
+#include "comm/Connection.h"
+#include "comm/Read.h"
 #include "CommCalls.h"
 #include "ipc/Port.h"
+#include "tools.h"
+#include "util.h"
 
-const char Ipc::coordinatorAddr[] = DEFAULT_PREFIX "/var/run/coordinator.ipc";
-const char Ipc::strandAddrPfx[] = DEFAULT_PREFIX "/var/run/squid";
-
+static const char channelPathPfx[] = DEFAULT_STATEDIR "/";
+static const char coordinatorAddrLabel[] = "-coordinator";
+const char Ipc::strandAddrLabel[] =  "-kid";
 
 Ipc::Port::Port(const String& aListenAddr):
     UdsOp(aListenAddr)
@@ -23,16 +30,17 @@ Ipc::Port::Port(const String& aListenAddr):
 void Ipc::Port::start()
 {
     UdsOp::start();
-    listen();
+    doListen();
 }
 
-void Ipc::Port::listen()
+void Ipc::Port::doListen()
 {
     debugs(54, 6, HERE);
     buf.prepForReading();
-    AsyncCall::Pointer readHandler = asyncCall(54, 6, "Ipc::Port::noteRead",
-        CommCbMemFunT<Port, CommIoCbParams>(this, &Port::noteRead));
-    comm_read(fd(), buf.raw(), buf.size(), readHandler);
+    typedef CommCbMemFunT<Port, CommIoCbParams> Dialer;
+    AsyncCall::Pointer readHandler = JobCallback(54, 6,
+                                     Dialer, this, Port::noteRead);
+    comm_read(conn(), buf.raw(), buf.size(), readHandler);
 }
 
 bool Ipc::Port::doneAll() const
@@ -40,26 +48,42 @@ bool Ipc::Port::doneAll() const
     return false; // listen forever
 }
 
-String Ipc::Port::MakeAddr(const char* pathAddr, int id)
+String Ipc::Port::MakeAddr(const char* processLabel, int id)
 {
     assert(id >= 0);
-    String addr = pathAddr;
+    String addr = channelPathPfx;
+    addr.append(service_name.c_str());
+    addr.append(processLabel);
     addr.append('-');
     addr.append(xitoa(id));
     addr.append(".ipc");
     return addr;
 }
 
+String
+Ipc::Port::CoordinatorAddr()
+{
+    static String coordinatorAddr;
+    if (!coordinatorAddr.size()) {
+        coordinatorAddr= channelPathPfx;
+        coordinatorAddr.append(service_name.c_str());
+        coordinatorAddr.append(coordinatorAddrLabel);
+        coordinatorAddr.append(".ipc");
+    }
+    return coordinatorAddr;
+}
+
 void Ipc::Port::noteRead(const CommIoCbParams& params)
 {
-    debugs(54, 6, HERE << "FD " << params.fd << " flag " << params.flag <<
-        " [" << this << ']');
-    if (params.flag == COMM_OK) {
+    debugs(54, 6, HERE << params.conn << " flag " << params.flag <<
+           " [" << this << ']');
+    if (params.flag == Comm::OK) {
         assert(params.buf == buf.raw());
         receive(buf);
     }
     // TODO: if there was a fatal error on our socket, close the socket before
     // trying to listen again and print a level-1 error message.
 
-    listen();
+    doListen();
 }
+