]> git.ipfire.org Git - thirdparty/squid.git/blob - src/ipc/Port.cc
merge from trunk
[thirdparty/squid.git] / src / ipc / Port.cc
1 /*
2 * DEBUG: section 54 Interprocess Communication
3 *
4 */
5
6 #include "squid.h"
7 #include "comm.h"
8 #include "comm/Connection.h"
9 #include "CommCalls.h"
10 #include "globals.h"
11 #include "ipc/Port.h"
12
13 static const char channelPathPfx[] = DEFAULT_STATEDIR "/";
14 static const char coordinatorAddrLabel[] = "-coordinator";
15 const char Ipc::strandAddrLabel[] = "-kid";
16
17 Ipc::Port::Port(const String& aListenAddr):
18 UdsOp(aListenAddr)
19 {
20 setOptions(COMM_NONBLOCKING | COMM_DOBIND);
21 }
22
23 void Ipc::Port::start()
24 {
25 UdsOp::start();
26 doListen();
27 }
28
29 void Ipc::Port::doListen()
30 {
31 debugs(54, 6, HERE);
32 buf.prepForReading();
33 typedef CommCbMemFunT<Port, CommIoCbParams> Dialer;
34 AsyncCall::Pointer readHandler = JobCallback(54, 6,
35 Dialer, this, Port::noteRead);
36 comm_read(conn(), buf.raw(), buf.size(), readHandler);
37 }
38
39 bool Ipc::Port::doneAll() const
40 {
41 return false; // listen forever
42 }
43
44 String Ipc::Port::MakeAddr(const char* processLabel, int id)
45 {
46 assert(id >= 0);
47 String addr = channelPathPfx;
48 addr.append(service_name);
49 addr.append(processLabel);
50 addr.append('-');
51 addr.append(xitoa(id));
52 addr.append(".ipc");
53 return addr;
54 }
55
56 String
57 Ipc::Port::CoordinatorAddr()
58 {
59 static String coordinatorAddr;
60 if (!coordinatorAddr.size()) {
61 coordinatorAddr= channelPathPfx;
62 coordinatorAddr.append(service_name);
63 coordinatorAddr.append(coordinatorAddrLabel);
64 coordinatorAddr.append(".ipc");
65 }
66 return coordinatorAddr;
67 }
68
69 void Ipc::Port::noteRead(const CommIoCbParams& params)
70 {
71 debugs(54, 6, HERE << params.conn << " flag " << params.flag <<
72 " [" << this << ']');
73 if (params.flag == COMM_OK) {
74 assert(params.buf == buf.raw());
75 receive(buf);
76 }
77 // TODO: if there was a fatal error on our socket, close the socket before
78 // trying to listen again and print a level-1 error message.
79
80 doListen();
81 }