]> git.ipfire.org Git - thirdparty/squid.git/blob - src/ipc/Port.cc
Merged from trunk
[thirdparty/squid.git] / src / ipc / Port.cc
1 /*
2 * $Id$
3 *
4 * DEBUG: section 54 Interprocess Communication
5 *
6 */
7
8 #include "config.h"
9 #include "comm.h"
10 #include "CommCalls.h"
11 #include "comm/Connection.h"
12 #include "ipc/Port.h"
13
14 const char Ipc::coordinatorAddr[] = DEFAULT_PREFIX "/var/run/coordinator.ipc";
15 const char Ipc::strandAddrPfx[] = DEFAULT_PREFIX "/var/run/squid";
16
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 listen();
28 }
29
30 void Ipc::Port::listen()
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* pathAddr, int id)
46 {
47 assert(id >= 0);
48 String addr = pathAddr;
49 addr.append('-');
50 addr.append(xitoa(id));
51 addr.append(".ipc");
52 return addr;
53 }
54
55 void Ipc::Port::noteRead(const CommIoCbParams& params)
56 {
57 debugs(54, 6, HERE << params.conn << " flag " << params.flag <<
58 " [" << this << ']');
59 if (params.flag == COMM_OK) {
60 assert(params.buf == buf.raw());
61 receive(buf);
62 }
63 // TODO: if there was a fatal error on our socket, close the socket before
64 // trying to listen again and print a level-1 error message.
65
66 listen();
67 }