]>
Commit | Line | Data |
---|---|---|
10cefb7b | 1 | /* |
10cefb7b | 2 | * DEBUG: section 54 Interprocess Communication |
3 | * | |
4 | */ | |
5 | ||
f7f3304a | 6 | #include "squid.h" |
8942ceb3 | 7 | #include "comm.h" |
8942ceb3 | 8 | #include "comm/Connection.h" |
7e66d5e2 | 9 | #include "comm/Read.h" |
602d9612 | 10 | #include "CommCalls.h" |
1ee292b7 | 11 | #include "globals.h" |
10cefb7b | 12 | #include "ipc/Port.h" |
13 | ||
1ee292b7 AJ |
14 | static const char channelPathPfx[] = DEFAULT_STATEDIR "/"; |
15 | static const char coordinatorAddrLabel[] = "-coordinator"; | |
16 | const char Ipc::strandAddrLabel[] = "-kid"; | |
10cefb7b | 17 | |
10cefb7b | 18 | Ipc::Port::Port(const String& aListenAddr): |
5667a628 | 19 | UdsOp(aListenAddr) |
10cefb7b | 20 | { |
ba568924 AR |
21 | setOptions(COMM_NONBLOCKING | COMM_DOBIND); |
22 | } | |
23 | ||
24 | void Ipc::Port::start() | |
25 | { | |
26 | UdsOp::start(); | |
c3317fea | 27 | doListen(); |
10cefb7b | 28 | } |
29 | ||
c3317fea | 30 | void Ipc::Port::doListen() |
10cefb7b | 31 | { |
32 | debugs(54, 6, HERE); | |
7230e9c7 | 33 | buf.prepForReading(); |
4299f876 AR |
34 | typedef CommCbMemFunT<Port, CommIoCbParams> Dialer; |
35 | AsyncCall::Pointer readHandler = JobCallback(54, 6, | |
4cb2536f | 36 | Dialer, this, Port::noteRead); |
ec20038e | 37 | comm_read(conn(), buf.raw(), buf.size(), readHandler); |
10cefb7b | 38 | } |
39 | ||
ba568924 AR |
40 | bool Ipc::Port::doneAll() const |
41 | { | |
42 | return false; // listen forever | |
43 | } | |
44 | ||
1ee292b7 | 45 | String Ipc::Port::MakeAddr(const char* processLabel, int id) |
10cefb7b | 46 | { |
47 | assert(id >= 0); | |
1ee292b7 AJ |
48 | String addr = channelPathPfx; |
49 | addr.append(service_name); | |
50 | addr.append(processLabel); | |
10cefb7b | 51 | addr.append('-'); |
52 | addr.append(xitoa(id)); | |
ba568924 | 53 | addr.append(".ipc"); |
10cefb7b | 54 | return addr; |
55 | } | |
56 | ||
1ee292b7 AJ |
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 | ||
10cefb7b | 70 | void Ipc::Port::noteRead(const CommIoCbParams& params) |
71 | { | |
e0d28505 | 72 | debugs(54, 6, HERE << params.conn << " flag " << params.flag << |
5667a628 | 73 | " [" << this << ']'); |
c8407295 | 74 | if (params.flag == Comm::OK) { |
ba568924 | 75 | assert(params.buf == buf.raw()); |
ba568924 | 76 | receive(buf); |
10cefb7b | 77 | } |
ba568924 | 78 | // TODO: if there was a fatal error on our socket, close the socket before |
1bac0258 | 79 | // trying to listen again and print a level-1 error message. |
ba568924 | 80 | |
c3317fea | 81 | doListen(); |
10cefb7b | 82 | } |