QuestionerId.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 1996-2022 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 #ifndef SQUID_SRC_IPC_QUESTIONERID_H
10 #define SQUID_SRC_IPC_QUESTIONERID_H
11 
12 #include "ipc/forward.h"
13 
14 #include <iosfwd>
15 
16 namespace Ipc
17 {
18 
22 {
23 public:
25  QuestionerId() = default;
26 
28  void pack(TypedMsgHdr &) const;
29 
31  void unpack(const TypedMsgHdr &);
32 
34  void rejectAnswerIfStale() const;
35 
37  void print(std::ostream &) const;
38 
39 private:
41  explicit QuestionerId(const pid_t aPid): pid(aPid) {}
43 
46  pid_t pid = -1;
47 };
48 
51 
54 template <class Answer>
55 const Answer &
56 Mine(const Answer &answer)
57 {
58  answer.intendedRecepient().rejectAnswerIfStale();
59  return answer;
60 }
61 
62 inline std::ostream &
63 operator <<(std::ostream &os, const QuestionerId &qid)
64 {
65  qid.print(os);
66  return os;
67 }
68 
69 } // namespace Ipc;
70 
71 #endif /* SQUID_SRC_IPC_QUESTIONERID_H */
72 
const Answer & Mine(const Answer &answer)
Definition: QuestionerId.h:56
void rejectAnswerIfStale() const
does nothing but throws if the questioner was not the current process
Definition: QuestionerId.cc:37
void pack(TypedMsgHdr &) const
for sending the ID of the asking process
Definition: QuestionerId.cc:25
void unpack(const TypedMsgHdr &)
for receiving the ID of the asking process
Definition: QuestionerId.cc:31
friend QuestionerId MyQuestionerId()
the questioner ID of the current/calling process
QuestionerId()=default
to-be-determined ID
QuestionerId MyQuestionerId()
the questioner ID of the current/calling process
Definition: QuestionerId.cc:18
QuestionerId(const pid_t aPid)
for MyQuestionerId() convenience
Definition: QuestionerId.h:41
struct msghdr with a known type, fixed-size I/O and control buffers
Definition: TypedMsgHdr.h:33
std::ostream & operator<<(std::ostream &os, const QuestionerId &qid)
Definition: QuestionerId.h:63
void print(std::ostream &) const
reports the stored opaque ID value (for debugging)
Definition: QuestionerId.cc:47
Definition: IpcIoFile.h:24

 

Introduction

Documentation

Support

Miscellaneous

Web Site Translations

Mirrors