]>
Commit | Line | Data |
---|---|---|
0d0bce6a AR |
1 | /* |
2 | * $Id$ | |
3 | * | |
4 | * DEBUG: section 54 Interprocess Communication | |
5 | * | |
6 | */ | |
7 | ||
8 | #include "config.h" | |
9 | #include "comm.h" | |
10 | #include "TextException.h" | |
11 | #include "ipc/SharedListen.h" | |
12 | #include "ipc/StartListening.h" | |
13 | ||
14 | ||
15 | Ipc::StartListeningCb::StartListeningCb(): fd(-1), errNo(0) | |
16 | { | |
17 | } | |
18 | ||
19 | Ipc::StartListeningCb::~StartListeningCb() | |
20 | { | |
21 | } | |
22 | ||
23 | std::ostream &Ipc::StartListeningCb::startPrint(std::ostream &os) const | |
24 | { | |
25 | return os << "(FD " << fd << ", err=" << errNo; | |
26 | } | |
27 | ||
28 | ||
29 | void Ipc::StartListening(int sock_type, int proto, IpAddress &addr, | |
5667a628 | 30 | int flags, FdNoteId fdNote, AsyncCall::Pointer &callback) |
0d0bce6a AR |
31 | { |
32 | OpenListenerParams p; | |
33 | p.sock_type = sock_type; | |
34 | p.proto = proto; | |
35 | p.addr = addr; | |
36 | p.flags = flags; | |
37 | p.fdNote = fdNote; | |
38 | ||
67858492 | 39 | if (UsingSmp()) { // if SMP is on, share |
0d0bce6a AR |
40 | Ipc::JoinSharedListen(p, callback); |
41 | return; // wait for the call back | |
42 | } | |
43 | ||
44 | enter_suid(); | |
45 | const int sock = comm_open_listener(p.sock_type, p.proto, p.addr, p.flags, | |
5667a628 | 46 | FdNote(p.fdNote)); |
0d0bce6a AR |
47 | const int errNo = (sock >= 0) ? 0 : errno; |
48 | leave_suid(); | |
49 | ||
50 | debugs(54, 3, HERE << "opened listen FD " << sock << " for " << p.addr); | |
51 | ||
52 | StartListeningCb *cbd = | |
53 | dynamic_cast<StartListeningCb*>(callback->getDialer()); | |
54 | Must(cbd); | |
55 | cbd->fd = sock; | |
56 | cbd->errNo = errNo; | |
57 | ScheduleCallHere(callback); | |
58 | } |