StartListening.cc
Go to the documentation of this file.
1 /*
2  * Copyright (C) 1996-2020 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/TextException.h"
13 #include "comm.h"
14 #include "comm/Connection.h"
15 #include "ipc/SharedListen.h"
16 #include "ipc/StartListening.h"
17 #include "tools.h"
18 
19 #include <cerrno>
20 
22 {
23 }
24 
26 {
27 }
28 
29 std::ostream &Ipc::StartListeningCb::startPrint(std::ostream &os) const
30 {
31  return os << "(" << conn << ", err=" << errNo;
32 }
33 
34 void
35 Ipc::StartListening(int sock_type, int proto, const Comm::ConnectionPointer &listenConn,
37 {
38  StartListeningCb *cbd = dynamic_cast<StartListeningCb*>(callback->getDialer());
39  Must(cbd);
40  cbd->conn = listenConn;
41 
42  const auto giveEachWorkerItsOwnQueue = listenConn->flags & COMM_REUSEPORT;
43  if (!giveEachWorkerItsOwnQueue && UsingSmp()) {
44  // Ask Coordinator for a listening socket.
45  // All askers share one listening queue.
47  p.sock_type = sock_type;
48  p.proto = proto;
49  p.addr = listenConn->local;
50  p.flags = listenConn->flags;
51  p.fdNote = fdNote;
53  return; // wait for the call back
54  }
55 
56  enter_suid();
57  comm_open_listener(sock_type, proto, cbd->conn, FdNote(fdNote));
58  cbd->errNo = Comm::IsConnOpen(cbd->conn) ? 0 : errno;
59  leave_suid();
60 
61  debugs(54, 3, HERE << "opened listen " << cbd->conn);
63 }
64 
int errNo
errno value from the comm_open_listener() call
#define ScheduleCallHere(call)
Definition: AsyncCall.h:166
int fdNote
index into fd_note() comment strings
Definition: SharedListen.h:32
bool IsConnOpen(const Comm::ConnectionPointer &conn)
Definition: Connection.cc:26
const char * FdNote(int fdNodeId)
converts FdNoteId into a string
Definition: FdNotes.cc:16
"shared listen" is when concurrent processes are listening on the same fd
Definition: SharedListen.h:24
void JoinSharedListen(const OpenListenerParams &, AsyncCall::Pointer &)
prepare and send SharedListenRequest to Coordinator
void comm_open_listener(int sock_type, int proto, Comm::ConnectionPointer &conn, const char *note)
Definition: comm.cc:233
void leave_suid(void)
Definition: tools.cc:504
#define NULL
Definition: types.h:166
void StartListening(int sock_type, int proto, const Comm::ConnectionPointer &listenConn, FdNoteId fdNote, AsyncCall::Pointer &callback)
#define debugs(SECTION, LEVEL, CONTENT)
Definition: Debug.h:128
Ip::Address local
Definition: Connection.h:156
std::ostream & HERE(std::ostream &s)
Definition: Debug.h:157
FdNoteId
We cannot send char* FD notes to other processes. Pass int IDs and convert.
Definition: FdNotes.h:20
int conn
the current server connection FD
Definition: Transport.cc:26
#define COMM_REUSEPORT
Definition: Connection.h:52
Ip::Address addr
will be memset and memcopied
Definition: SharedListen.h:35
#define Must(condition)
Like assert() but throws an exception instead of aborting the process.
Definition: TextException.h:69
void enter_suid(void)
Definition: tools.cc:575
void const char HLPCB * callback
Definition: stub_helper.cc:16
common API for all StartListening() callbacks
bool UsingSmp()
Whether there should be more than one worker process running.
Definition: tools.cc:658
std::ostream & startPrint(std::ostream &os) const
starts printing arguments, return os
Comm::ConnectionPointer conn
opened listening socket

 

Introduction

Documentation

Support

Miscellaneous

Web Site Translations

Mirrors