Squid Web Cache
master
Loading...
Searching...
No Matches
QuestionerId.cc
Go to the documentation of this file.
1
/*
2
* Copyright (C) 1996-2025 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
#include "
squid.h
"
10
#include "
base/TextException.h
"
11
#include "
ipc/QuestionerId.h
"
12
#include "
ipc/TypedMsgHdr.h
"
13
#include "
sbuf/Stream.h
"
14
15
#include <iostream>
16
17
Ipc::QuestionerId
18
Ipc::MyQuestionerId
()
19
{
20
static
const
QuestionerId
qid(getpid());
21
return
qid;
22
}
23
24
void
25
Ipc::QuestionerId::pack
(
TypedMsgHdr
&hdrMsg)
const
26
{
27
hdrMsg.
putPod
(
pid
);
28
}
29
30
void
31
Ipc::QuestionerId::unpack
(
const
TypedMsgHdr
&hdrMsg)
32
{
33
hdrMsg.
getPod
(
pid
);
34
}
35
36
void
37
Ipc::QuestionerId::rejectAnswerIfStale
()
const
38
{
39
const
auto
myPid =
MyQuestionerId
().
pid
;
40
if
(myPid !=
pid
) {
41
throw
TextException
(
ToSBuf
(
"received answer to an IPC question asked by process "
,
pid
,
42
Debug::Extra
,
"my process PID: "
, myPid),
Here
());
43
}
44
}
45
46
void
47
Ipc::QuestionerId::print
(std::ostream &os)
const
48
{
49
os <<
pid
;
50
}
51
Here
#define Here()
source code location of the caller
Definition
Here.h:15
pid
static pid_t pid
Definition
IcmpSquid.cc:36
QuestionerId.h
TextException.h
TypedMsgHdr.h
Debug::Extra
static std::ostream & Extra(std::ostream &)
Definition
debug.cc:1316
Ipc::QuestionerId
Definition
QuestionerId.h:22
Ipc::QuestionerId::pid
pid_t pid
Definition
QuestionerId.h:46
Ipc::QuestionerId::pack
void pack(TypedMsgHdr &) const
for sending the ID of the asking process
Definition
QuestionerId.cc:25
Ipc::QuestionerId::print
void print(std::ostream &) const
reports the stored opaque ID value (for debugging)
Definition
QuestionerId.cc:47
Ipc::QuestionerId::unpack
void unpack(const TypedMsgHdr &)
for receiving the ID of the asking process
Definition
QuestionerId.cc:31
Ipc::QuestionerId::rejectAnswerIfStale
void rejectAnswerIfStale() const
does nothing but throws if the questioner was not the current process
Definition
QuestionerId.cc:37
Ipc::TypedMsgHdr
struct msghdr with a known type, fixed-size I/O and control buffers
Definition
TypedMsgHdr.h:35
Ipc::TypedMsgHdr::getPod
void getPod(Pod &pod) const
load POD
Definition
TypedMsgHdr.h:118
Ipc::TypedMsgHdr::putPod
void putPod(const Pod &pod)
store POD
Definition
TypedMsgHdr.h:126
TextException
an std::runtime_error with thrower location info
Definition
TextException.h:21
Ipc::MyQuestionerId
QuestionerId MyQuestionerId()
the questioner ID of the current/calling process
Definition
QuestionerId.cc:18
Stream.h
ToSBuf
SBuf ToSBuf(Args &&... args)
slowly stream-prints all arguments into a freshly allocated SBuf
Definition
Stream.h:63
squid.h
squid
src
ipc
QuestionerId.cc
Generated by
1.9.8