Bitcoin Core
31.1.0
P2P Digital Currency
Toggle main menu visibility
Loading...
Searching...
No Matches
src
util
tokenpipe.h
Go to the documentation of this file.
1
// Copyright (c) 2021-present The Bitcoin Core developers
2
// Distributed under the MIT software license, see the accompanying
3
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
4
5
#ifndef BITCOIN_UTIL_TOKENPIPE_H
6
#define BITCOIN_UTIL_TOKENPIPE_H
7
8
#ifndef WIN32
9
10
#include <cstdint>
11
#include <optional>
12
14
class
TokenPipeEnd
15
{
16
private
:
17
int
m_fd
= -1;
18
19
public
:
20
TokenPipeEnd
(
int
fd = -1);
21
~TokenPipeEnd
();
22
24
enum
Status
{
25
TS_ERR
= -1,
26
TS_EOS
= -2,
27
};
28
36
int
TokenWrite
(uint8_t token);
37
45
int
TokenRead
();
46
49
void
Close
();
50
53
bool
IsOpen
() {
return
m_fd
!= -1; }
54
55
// Move-only class.
56
TokenPipeEnd
(
TokenPipeEnd
&& other)
57
{
58
m_fd
= other.m_fd;
59
other.m_fd = -1;
60
}
61
TokenPipeEnd
&
operator=
(
TokenPipeEnd
&& other)
62
{
63
Close
();
64
m_fd
= other.m_fd;
65
other.m_fd = -1;
66
return
*
this
;
67
}
68
TokenPipeEnd
(
const
TokenPipeEnd
&) =
delete
;
69
TokenPipeEnd
&
operator=
(
const
TokenPipeEnd
&) =
delete
;
70
};
71
75
class
TokenPipe
76
{
77
private
:
78
int
m_fds
[2] = {-1, -1};
79
80
TokenPipe
(
int
fds[2]) :
m_fds
{fds[0], fds[1]} {}
81
82
public
:
83
~TokenPipe
();
84
88
static
std::optional<TokenPipe>
Make
();
89
93
TokenPipeEnd
TakeReadEnd
();
94
98
TokenPipeEnd
TakeWriteEnd
();
99
102
void
Close
();
103
104
// Move-only class.
105
TokenPipe
(
TokenPipe
&& other)
106
{
107
for
(
int
i = 0; i < 2; ++i) {
108
m_fds
[i] = other.m_fds[i];
109
other.m_fds[i] = -1;
110
}
111
}
112
TokenPipe
&
operator=
(
TokenPipe
&& other)
113
{
114
Close
();
115
for
(
int
i = 0; i < 2; ++i) {
116
m_fds
[i] = other.m_fds[i];
117
other.m_fds[i] = -1;
118
}
119
return
*
this
;
120
}
121
TokenPipe
(
const
TokenPipe
&) =
delete
;
122
TokenPipe
&
operator=
(
const
TokenPipe
&) =
delete
;
123
};
124
125
#endif
// WIN32
126
127
#endif
// BITCOIN_UTIL_TOKENPIPE_H
TokenPipeEnd
One end of a token pipe.
Definition
tokenpipe.h:15
TokenPipeEnd::operator=
TokenPipeEnd & operator=(TokenPipeEnd &&other)
Definition
tokenpipe.h:61
TokenPipeEnd::TokenPipeEnd
TokenPipeEnd(const TokenPipeEnd &)=delete
TokenPipeEnd::TokenPipeEnd
TokenPipeEnd(TokenPipeEnd &&other)
Definition
tokenpipe.h:56
TokenPipeEnd::TokenPipeEnd
TokenPipeEnd(int fd=-1)
Definition
tokenpipe.cpp:29
TokenPipeEnd::Status
Status
Return value constants for TokenWrite and TokenRead.
Definition
tokenpipe.h:24
TokenPipeEnd::TS_ERR
@ TS_ERR
I/O error.
Definition
tokenpipe.h:25
TokenPipeEnd::TS_EOS
@ TS_EOS
Unexpected end of stream.
Definition
tokenpipe.h:26
TokenPipeEnd::m_fd
int m_fd
Definition
tokenpipe.h:17
TokenPipeEnd::IsOpen
bool IsOpen()
Return whether endpoint is open.
Definition
tokenpipe.h:53
TokenPipeEnd::TokenWrite
int TokenWrite(uint8_t token)
Write token to endpoint.
Definition
tokenpipe.cpp:38
TokenPipeEnd::Close
void Close()
Explicit close function.
Definition
tokenpipe.cpp:76
TokenPipeEnd::operator=
TokenPipeEnd & operator=(const TokenPipeEnd &)=delete
TokenPipeEnd::TokenRead
int TokenRead()
Read token from endpoint.
Definition
tokenpipe.cpp:56
TokenPipeEnd::~TokenPipeEnd
~TokenPipeEnd()
Definition
tokenpipe.cpp:33
TokenPipe::Close
void Close()
Close and end of the pipe that hasn't been moved out.
Definition
tokenpipe.cpp:102
TokenPipe::TakeReadEnd
TokenPipeEnd TakeReadEnd()
Take the read end of this pipe.
Definition
tokenpipe.cpp:15
TokenPipe::TakeWriteEnd
TokenPipeEnd TakeWriteEnd()
Take the write end of this pipe.
Definition
tokenpipe.cpp:22
TokenPipe::m_fds
int m_fds[2]
Definition
tokenpipe.h:78
TokenPipe::Make
static std::optional< TokenPipe > Make()
Create a new pipe.
Definition
tokenpipe.cpp:82
TokenPipe::operator=
TokenPipe & operator=(TokenPipe &&other)
Definition
tokenpipe.h:112
TokenPipe::operator=
TokenPipe & operator=(const TokenPipe &)=delete
TokenPipe::~TokenPipe
~TokenPipe()
Definition
tokenpipe.cpp:97
TokenPipe::TokenPipe
TokenPipe(TokenPipe &&other)
Definition
tokenpipe.h:105
TokenPipe::TokenPipe
TokenPipe(int fds[2])
Definition
tokenpipe.h:80
TokenPipe::TokenPipe
TokenPipe(const TokenPipe &)=delete
Generated on
for Bitcoin Core by
1.17.0