]> git.ipfire.org Git - thirdparty/squid.git/blob - src/ipc/StartListening.cc
SourceFormat Enforcement
[thirdparty/squid.git] / src / ipc / StartListening.cc
1 /*
2 * $Id$
3 *
4 * DEBUG: section 54 Interprocess Communication
5 *
6 */
7
8 #include "config.h"
9 #include "base/TextException.h"
10 #include "comm.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 void
29 Ipc::StartListening(int sock_type, int proto, Ip::Address &addr, int flags,
30 FdNoteId fdNote, AsyncCall::Pointer &callback)
31 {
32 if (UsingSmp()) { // if SMP is on, share
33 OpenListenerParams p;
34 p.sock_type = sock_type;
35 p.proto = proto;
36 p.addr = addr;
37 p.flags = flags;
38 p.fdNote = fdNote;
39 Ipc::JoinSharedListen(p, callback);
40 return; // wait for the call back
41 }
42
43 StartListeningCb *cbd = dynamic_cast<StartListeningCb*>(callback->getDialer());
44 Must(cbd);
45
46 enter_suid();
47 cbd->fd = comm_open_listener(sock_type, proto, addr, flags, FdNote(fdNote));
48 cbd->errNo = cbd->fd >= 0 ? 0 : errno;
49 leave_suid();
50
51 debugs(54, 3, HERE << "opened listen FD " << cbd->fd << " on " << addr);
52 ScheduleCallHere(callback);
53 }