]> git.ipfire.org Git - thirdparty/squid.git/blob - src/ipc/Port.cc
Switched from sendto/recvfrom to sendmsg/recvmsg for UDS I/O. Replaced
[thirdparty/squid.git] / src / ipc / Port.cc
1 /*
2 * $Id$
3 *
4 * DEBUG: section 54 Interprocess Communication
5 *
6 */
7
8
9 #include "config.h"
10 #include "CommCalls.h"
11 #include "ipc/Port.h"
12
13 const char Ipc::coordinatorAddr[] = DEFAULT_PREFIX "/var/run/coordinator.ipc";
14 const char Ipc::strandAddrPfx[] = DEFAULT_PREFIX "/var/run/squid";
15
16
17 Ipc::Port::Port(const String& aListenAddr):
18 UdsOp(aListenAddr)
19 {
20 setOptions(COMM_NONBLOCKING | COMM_DOBIND);
21 buf.allocate();
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 AsyncCall::Pointer readHandler = asyncCall(54, 6, "Ipc::Port::noteRead",
34 CommCbMemFunT<Port, CommIoCbParams>(this, &Port::noteRead));
35 comm_read(fd(), buf.raw(), buf.size(), readHandler);
36 }
37
38 bool Ipc::Port::doneAll() const
39 {
40 return false; // listen forever
41 }
42
43 String Ipc::Port::MakeAddr(const char* pathAddr, int id)
44 {
45 assert(id >= 0);
46 String addr = pathAddr;
47 addr.append('-');
48 addr.append(xitoa(id));
49 addr.append(".ipc");
50 return addr;
51 }
52
53 void Ipc::Port::noteRead(const CommIoCbParams& params)
54 {
55 debugs(54, 6, HERE << "FD " << params.fd << " flag " << params.flag <<
56 " [" << this << ']');
57 if (params.flag == COMM_OK) {
58 assert(params.buf == buf.raw());
59 receive(buf);
60 }
61 // TODO: if there was a fatal error on our socket, close the socket before
62 // trying to listen again and print a level-1 error message.
63
64 listen();
65 }