StartListening.cc
Go to the documentation of this file.
1/*
2 * Copyright (C) 1996-2023 The Squid Software Foundation and contributors
3 *
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.
7 */
8
9/* DEBUG: section 54 Interprocess Communication */
10
11#include "squid.h"
12#include "base/AsyncCallbacks.h"
13#include "base/TextException.h"
14#include "comm.h"
15#include "comm/Connection.h"
16#include "ipc/SharedListen.h"
17#include "ipc/StartListening.h"
18#include "tools.h"
19
20#include <cerrno>
21
22std::ostream &
23Ipc::operator <<(std::ostream &os, const StartListeningAnswer &answer)
24{
25 os << answer.conn;
26 if (answer.errNo)
27 os << ", err=" << answer.errNo;
28 return os;
29}
30
31void
32Ipc::StartListening(int sock_type, int proto, const Comm::ConnectionPointer &listenConn,
33 const FdNoteId fdNote, StartListeningCallback &callback)
34{
35 auto &answer = callback.answer();
36 answer.conn = listenConn;
37
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.
43 p.sock_type = sock_type;
44 p.proto = proto;
45 p.addr = listenConn->local;
46 p.flags = listenConn->flags;
47 p.fdNote = fdNote;
48 JoinSharedListen(p, callback);
49 return; // wait for the call back
50 }
51
52 enter_suid();
53 comm_open_listener(sock_type, proto, answer.conn, FdNote(fdNote));
54 const auto savedErrno = errno;
55 leave_suid();
56
57 answer.errNo = Comm::IsConnOpen(answer.conn) ? 0 : savedErrno;
58
59 debugs(54, 3, "opened listen " << answer);
60 ScheduleCallHere(callback.release());
61}
62
#define ScheduleCallHere(call)
Definition: AsyncCall.h:166
#define COMM_REUSEPORT
Definition: Connection.h:52
AsyncCall::Pointer release()
Answer & answer()
Ip::Address local
Definition: Connection.h:146
"shared listen" is when concurrent processes are listening on the same fd
Definition: SharedListen.h:29
int fdNote
index into fd_note() comment strings
Definition: SharedListen.h:36
Ip::Address addr
will be memset and memcopied
Definition: SharedListen.h:39
StartListening() result.
int errNo
errno value from the comm_open_listener() call
Comm::ConnectionPointer conn
opened listening socket
void comm_open_listener(int sock_type, int proto, Comm::ConnectionPointer &conn, const char *note)
Definition: comm.cc:256
#define debugs(SECTION, LEVEL, CONTENT)
Definition: Stream.h:194
bool IsConnOpen(const Comm::ConnectionPointer &conn)
Definition: Connection.cc:27
FdNoteId
We cannot send char* FD notes to other processes. Pass int IDs and convert.
Definition: FdNotes.h:20
void StartListening(int sock_type, int proto, const Comm::ConnectionPointer &listenConn, FdNoteId, StartListeningCallback &)
const char * FdNote(int fdNodeId)
converts FdNoteId into a string
Definition: FdNotes.cc:16
void JoinSharedListen(const OpenListenerParams &, StartListeningCallback &)
prepare and send SharedListenRequest to Coordinator
std::ostream & operator<<(std::ostream &os, const QuestionerId &qid)
Definition: QuestionerId.h:63
void leave_suid(void)
Definition: tools.cc:559
void enter_suid(void)
Definition: tools.cc:623
bool UsingSmp()
Whether there should be more than one worker process running.
Definition: tools.cc:696

 

Introduction

Documentation

Support

Miscellaneous

Web Site Translations

Mirrors