4 * DEBUG: section 54 Interprocess Communication
9 #include "base/Subscription.h"
10 #include "base/TextException.h"
12 #include "comm/ConnAcceptor.h"
13 #include "comm/Connection.h"
14 #include "ipc/SharedListen.h"
15 #include "ipc/StartListening.h"
18 Ipc::StartListeningCb::StartListeningCb(): conn(NULL
), errNo(0)
22 Ipc::StartListeningCb::~StartListeningCb()
26 std::ostream
&Ipc::StartListeningCb::startPrint(std::ostream
&os
) const
28 return os
<< "(" << conn
<< ", err=" << errNo
;
32 Ipc::StartListening(int sock_type
, int proto
, const Comm::ConnectionPointer
&listenConn
,
33 FdNoteId fdNote
, AsyncCall::Pointer
&callback
, const Subscription::Pointer
&sub
)
35 if (UsingSmp()) { // if SMP is on, share
37 p
.sock_type
= sock_type
;
39 p
.addr
= listenConn
->local
;
40 p
.flags
= listenConn
->flags
;
42 p
.handlerSubscription
= sub
;
44 Ipc::JoinSharedListen(p
, callback
);
45 return; // wait for the call back
48 StartListeningCb
*cbd
= dynamic_cast<StartListeningCb
*>(callback
->getDialer());
50 cbd
->conn
= listenConn
;
53 if (sock_type
== SOCK_STREAM
) {
54 // TCP: setup the subscriptions such that new connections accepted by listenConn are handled by HTTP
55 AsyncJob::Start(new Comm::ConnAcceptor(cbd
->conn
, FdNote(fdNote
), sub
));
56 } else if (sock_type
== SOCK_DGRAM
) {
57 // UDP: setup the listener socket, but do not set a subscriber
58 Comm::ConnectionPointer udpConn
= listenConn
;
59 comm_open_listener(sock_type
, proto
, udpConn
, FdNote(fdNote
));
61 fatalf("Invalid Socket Type (%d)",sock_type
);
63 cbd
->errNo
= cbd
->conn
->isOpen() ? 0 : errno
;
66 debugs(54, 3, HERE
<< "opened listen " << cbd
->conn
);
67 ScheduleCallHere(callback
);