]> git.ipfire.org Git - thirdparty/squid.git/blame - src/ipc/StartListening.cc
Source Format Enforcement (#1234)
[thirdparty/squid.git] / src / ipc / StartListening.cc
CommitLineData
0d0bce6a 1/*
b8ae064d 2 * Copyright (C) 1996-2023 The Squid Software Foundation and contributors
0d0bce6a 3 *
bbc27441
AJ
4 * Squid software is distributed under GPLv2+ license and includes
5 * contributions from numerous individuals and organizations.
6 * Please see the COPYING and CONTRIBUTORS files for details.
0d0bce6a
AR
7 */
8
bbc27441
AJ
9/* DEBUG: section 54 Interprocess Communication */
10
f7f3304a 11#include "squid.h"
e5ddd4ce 12#include "base/AsyncCallbacks.h"
a67d2b2e 13#include "base/TextException.h"
e0d28505 14#include "comm.h"
e0d28505 15#include "comm/Connection.h"
0d0bce6a
AR
16#include "ipc/SharedListen.h"
17#include "ipc/StartListening.h"
561076e2 18#include "tools.h"
0d0bce6a 19
1a30fdf5 20#include <cerrno>
21d845b1 21
e5ddd4ce
AR
22std::ostream &
23Ipc::operator <<(std::ostream &os, const StartListeningAnswer &answer)
0d0bce6a 24{
e5ddd4ce
AR
25 os << answer.conn;
26 if (answer.errNo)
27 os << ", err=" << answer.errNo;
28 return os;
0d0bce6a
AR
29}
30
e0d28505
AJ
31void
32Ipc::StartListening(int sock_type, int proto, const Comm::ConnectionPointer &listenConn,
e5ddd4ce 33 const FdNoteId fdNote, StartListeningCallback &callback)
0d0bce6a 34{
e5ddd4ce
AR
35 auto &answer = callback.answer();
36 answer.conn = listenConn;
b72fb55d 37
7d17a6a6
EB
38 const auto giveEachWorkerItsOwnQueue = listenConn->flags & COMM_REUSEPORT;
39 if (!giveEachWorkerItsOwnQueue && UsingSmp()) {
40 // Ask Coordinator for a listening socket.
41 // All askers share one listening queue.
e0d28505
AJ
42 OpenListenerParams p;
43 p.sock_type = sock_type;
44 p.proto = proto;
45 p.addr = listenConn->local;
46 p.flags = listenConn->flags;
47 p.fdNote = fdNote;
e5ddd4ce 48 JoinSharedListen(p, callback);
0d0bce6a
AR
49 return; // wait for the call back
50 }
51
52 enter_suid();
e5ddd4ce
AR
53 comm_open_listener(sock_type, proto, answer.conn, FdNote(fdNote));
54 const auto savedErrno = errno;
0d0bce6a
AR
55 leave_suid();
56
e5ddd4ce
AR
57 answer.errNo = Comm::IsConnOpen(answer.conn) ? 0 : savedErrno;
58
59 debugs(54, 3, "opened listen " << answer);
60 ScheduleCallHere(callback.release());
0d0bce6a 61}
f53969cc 62