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