QuestionerId.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#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
19{
20 static const QuestionerId qid(getpid());
21 return qid;
22}
23
24void
26{
27 hdrMsg.putPod(pid);
28}
29
30void
32{
33 hdrMsg.getPod(pid);
34}
35
36void
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
46void
47Ipc::QuestionerId::print(std::ostream &os) const
48{
49 os << pid;
50}
51
#define Here()
source code location of the caller
Definition: Here.h:15
static pid_t pid
Definition: IcmpSquid.cc:34
static std::ostream & Extra(std::ostream &)
Definition: debug.cc:1313
void pack(TypedMsgHdr &) const
for sending the ID of the asking process
Definition: QuestionerId.cc:25
void print(std::ostream &) const
reports the stored opaque ID value (for debugging)
Definition: QuestionerId.cc:47
void unpack(const TypedMsgHdr &)
for receiving the ID of the asking process
Definition: QuestionerId.cc:31
void rejectAnswerIfStale() const
does nothing but throws if the questioner was not the current process
Definition: QuestionerId.cc:37
struct msghdr with a known type, fixed-size I/O and control buffers
Definition: TypedMsgHdr.h:35
void getPod(Pod &pod) const
load POD
Definition: TypedMsgHdr.h:118
void putPod(const Pod &pod)
store POD
Definition: TypedMsgHdr.h:126
an std::runtime_error with thrower location info
Definition: TextException.h:21
QuestionerId MyQuestionerId()
the questioner ID of the current/calling process
Definition: QuestionerId.cc:18
SBuf ToSBuf(Args &&... args)
slowly stream-prints all arguments into a freshly allocated SBuf
Definition: Stream.h:63

 

Introduction

Documentation

Support

Miscellaneous

Web Site Translations

Mirrors