]>
Commit | Line | Data |
---|---|---|
10cefb7b | 1 | /* |
4ac4a490 | 2 | * Copyright (C) 1996-2017 The Squid Software Foundation and contributors |
10cefb7b | 3 | * |
bbc27441 AJ |
4 | * Squid software is distributed under GPLv2+ license and includes |
5 | * contributions from numerous individuals and organizations. | |
6 | * Please see the COPYING and CONTRIBUTORS files for details. | |
10cefb7b | 7 | */ |
8 | ||
bbc27441 AJ |
9 | /* DEBUG: section 54 Interprocess Communication */ |
10 | ||
f7f3304a | 11 | #include "squid.h" |
8942ceb3 | 12 | #include "comm.h" |
8942ceb3 | 13 | #include "comm/Connection.h" |
7e66d5e2 | 14 | #include "comm/Read.h" |
602d9612 | 15 | #include "CommCalls.h" |
10cefb7b | 16 | #include "ipc/Port.h" |
8b505ba9 | 17 | #include "tools.h" |
ed6e9fb9 | 18 | #include "util.h" |
10cefb7b | 19 | |
1ee292b7 AJ |
20 | static const char channelPathPfx[] = DEFAULT_STATEDIR "/"; |
21 | static const char coordinatorAddrLabel[] = "-coordinator"; | |
22 | const char Ipc::strandAddrLabel[] = "-kid"; | |
10cefb7b | 23 | |
10cefb7b | 24 | Ipc::Port::Port(const String& aListenAddr): |
f53969cc | 25 | UdsOp(aListenAddr) |
10cefb7b | 26 | { |
ba568924 AR |
27 | setOptions(COMM_NONBLOCKING | COMM_DOBIND); |
28 | } | |
29 | ||
30 | void Ipc::Port::start() | |
31 | { | |
32 | UdsOp::start(); | |
c3317fea | 33 | doListen(); |
10cefb7b | 34 | } |
35 | ||
c3317fea | 36 | void Ipc::Port::doListen() |
10cefb7b | 37 | { |
38 | debugs(54, 6, HERE); | |
7230e9c7 | 39 | buf.prepForReading(); |
4299f876 AR |
40 | typedef CommCbMemFunT<Port, CommIoCbParams> Dialer; |
41 | AsyncCall::Pointer readHandler = JobCallback(54, 6, | |
4cb2536f | 42 | Dialer, this, Port::noteRead); |
ec20038e | 43 | comm_read(conn(), buf.raw(), buf.size(), readHandler); |
10cefb7b | 44 | } |
45 | ||
ba568924 AR |
46 | bool Ipc::Port::doneAll() const |
47 | { | |
48 | return false; // listen forever | |
49 | } | |
50 | ||
1ee292b7 | 51 | String Ipc::Port::MakeAddr(const char* processLabel, int id) |
10cefb7b | 52 | { |
53 | assert(id >= 0); | |
1ee292b7 | 54 | String addr = channelPathPfx; |
d5f21615 | 55 | addr.append(service_name.c_str()); |
1ee292b7 | 56 | addr.append(processLabel); |
10cefb7b | 57 | addr.append('-'); |
58 | addr.append(xitoa(id)); | |
ba568924 | 59 | addr.append(".ipc"); |
10cefb7b | 60 | return addr; |
61 | } | |
62 | ||
1ee292b7 AJ |
63 | String |
64 | Ipc::Port::CoordinatorAddr() | |
65 | { | |
66 | static String coordinatorAddr; | |
67 | if (!coordinatorAddr.size()) { | |
68 | coordinatorAddr= channelPathPfx; | |
d5f21615 | 69 | coordinatorAddr.append(service_name.c_str()); |
1ee292b7 AJ |
70 | coordinatorAddr.append(coordinatorAddrLabel); |
71 | coordinatorAddr.append(".ipc"); | |
72 | } | |
73 | return coordinatorAddr; | |
74 | } | |
75 | ||
10cefb7b | 76 | void Ipc::Port::noteRead(const CommIoCbParams& params) |
77 | { | |
e0d28505 | 78 | debugs(54, 6, HERE << params.conn << " flag " << params.flag << |
5667a628 | 79 | " [" << this << ']'); |
c8407295 | 80 | if (params.flag == Comm::OK) { |
ba568924 | 81 | assert(params.buf == buf.raw()); |
ba568924 | 82 | receive(buf); |
10cefb7b | 83 | } |
ba568924 | 84 | // TODO: if there was a fatal error on our socket, close the socket before |
1bac0258 | 85 | // trying to listen again and print a level-1 error message. |
ba568924 | 86 | |
c3317fea | 87 | doListen(); |
10cefb7b | 88 | } |
f53969cc | 89 |