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