]>
Commit | Line | Data |
---|---|---|
10cefb7b | 1 | /* |
bbc27441 | 2 | * Copyright (C) 1996-2014 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" |
10cefb7b | 18 | |
1ee292b7 AJ |
19 | static const char channelPathPfx[] = DEFAULT_STATEDIR "/"; |
20 | static const char coordinatorAddrLabel[] = "-coordinator"; | |
21 | const char Ipc::strandAddrLabel[] = "-kid"; | |
10cefb7b | 22 | |
10cefb7b | 23 | Ipc::Port::Port(const String& aListenAddr): |
5667a628 | 24 | UdsOp(aListenAddr) |
10cefb7b | 25 | { |
ba568924 AR |
26 | setOptions(COMM_NONBLOCKING | COMM_DOBIND); |
27 | } | |
28 | ||
29 | void Ipc::Port::start() | |
30 | { | |
31 | UdsOp::start(); | |
c3317fea | 32 | doListen(); |
10cefb7b | 33 | } |
34 | ||
c3317fea | 35 | void Ipc::Port::doListen() |
10cefb7b | 36 | { |
37 | debugs(54, 6, HERE); | |
7230e9c7 | 38 | buf.prepForReading(); |
4299f876 AR |
39 | typedef CommCbMemFunT<Port, CommIoCbParams> Dialer; |
40 | AsyncCall::Pointer readHandler = JobCallback(54, 6, | |
4cb2536f | 41 | Dialer, this, Port::noteRead); |
ec20038e | 42 | comm_read(conn(), buf.raw(), buf.size(), readHandler); |
10cefb7b | 43 | } |
44 | ||
ba568924 AR |
45 | bool Ipc::Port::doneAll() const |
46 | { | |
47 | return false; // listen forever | |
48 | } | |
49 | ||
1ee292b7 | 50 | String Ipc::Port::MakeAddr(const char* processLabel, int id) |
10cefb7b | 51 | { |
52 | assert(id >= 0); | |
1ee292b7 | 53 | String addr = channelPathPfx; |
d5f21615 | 54 | addr.append(service_name.c_str()); |
1ee292b7 | 55 | addr.append(processLabel); |
10cefb7b | 56 | addr.append('-'); |
57 | addr.append(xitoa(id)); | |
ba568924 | 58 | addr.append(".ipc"); |
10cefb7b | 59 | return addr; |
60 | } | |
61 | ||
1ee292b7 AJ |
62 | String |
63 | Ipc::Port::CoordinatorAddr() | |
64 | { | |
65 | static String coordinatorAddr; | |
66 | if (!coordinatorAddr.size()) { | |
67 | coordinatorAddr= channelPathPfx; | |
d5f21615 | 68 | coordinatorAddr.append(service_name.c_str()); |
1ee292b7 AJ |
69 | coordinatorAddr.append(coordinatorAddrLabel); |
70 | coordinatorAddr.append(".ipc"); | |
71 | } | |
72 | return coordinatorAddr; | |
73 | } | |
74 | ||
10cefb7b | 75 | void Ipc::Port::noteRead(const CommIoCbParams& params) |
76 | { | |
e0d28505 | 77 | debugs(54, 6, HERE << params.conn << " flag " << params.flag << |
5667a628 | 78 | " [" << this << ']'); |
c8407295 | 79 | if (params.flag == Comm::OK) { |
ba568924 | 80 | assert(params.buf == buf.raw()); |
ba568924 | 81 | receive(buf); |
10cefb7b | 82 | } |
ba568924 | 83 | // TODO: if there was a fatal error on our socket, close the socket before |
1bac0258 | 84 | // trying to listen again and print a level-1 error message. |
ba568924 | 85 | |
c3317fea | 86 | doListen(); |
10cefb7b | 87 | } |