Bitcoin Core 28.99.0
P2P Digital Currency
Public Member Functions | Private Member Functions | Private Attributes | List of all members
DynSock::Pipe Class Reference

Unidirectional bytes or CNetMessage queue (FIFO). More...

#include <net.h>

Collaboration diagram for DynSock::Pipe:
[legend]

Public Member Functions

ssize_t GetBytes (void *buf, size_t len, int flags=0) EXCLUSIVE_LOCKS_REQUIRED(!m_mutex)
 Get bytes and remove them from the pipe. More...
 
std::optional< CNetMessageGetNetMsg () EXCLUSIVE_LOCKS_REQUIRED(!m_mutex)
 Deserialize a CNetMessage and remove it from the pipe. More...
 
void PushBytes (const void *buf, size_t len) EXCLUSIVE_LOCKS_REQUIRED(!m_mutex)
 Push bytes to the pipe. More...
 
template<typename... Args>
void PushNetMsg (const std::string &type, Args &&... payload) EXCLUSIVE_LOCKS_REQUIRED(!m_mutex)
 Construct and push CNetMessage to the pipe. More...
 
void Eof () EXCLUSIVE_LOCKS_REQUIRED(!m_mutex)
 Signal end-of-file on the receiving end (GetBytes() or GetNetMsg()). More...
 

Private Member Functions

void WaitForDataOrEof (UniqueLock< Mutex > &lock) EXCLUSIVE_LOCKS_REQUIRED(m_mutex)
 Return when there is some data to read or EOF has been signaled. More...
 
std::vector< uint8_t > m_data GUARDED_BY (m_mutex)
 
bool m_eof GUARDED_BY (m_mutex)
 

Private Attributes

Mutex m_mutex
 
std::condition_variable m_cond
 

Detailed Description

Unidirectional bytes or CNetMessage queue (FIFO).

Definition at line 218 of file net.h.

Member Function Documentation

◆ Eof()

void DynSock::Pipe::Eof ( )

Signal end-of-file on the receiving end (GetBytes() or GetNetMsg()).

Definition at line 315 of file net.cpp.

◆ GetBytes()

ssize_t DynSock::Pipe::GetBytes ( void *  buf,
size_t  len,
int  flags = 0 
)

Get bytes and remove them from the pipe.

Parameters
[in]bufDestination to write bytes to.
[in]lenWrite up to this number of bytes.
[in]flagsSame as the flags of recv(2). Just MSG_PEEK is honored.
Returns
The number of bytes written to buf. 0 if Eof() has been called. If no bytes are available then -1 is returned and errno is set to EAGAIN.

Definition at line 247 of file net.cpp.

◆ GetNetMsg()

std::optional< CNetMessage > DynSock::Pipe::GetNetMsg ( )

Deserialize a CNetMessage and remove it from the pipe.

If not enough bytes are available then the function will wait. If parsing fails or EOF is signaled to the pipe, then std::nullopt is returned.

Definition at line 269 of file net.cpp.

◆ GUARDED_BY() [1/2]

std::vector< uint8_t > m_data DynSock::Pipe::GUARDED_BY ( m_mutex  )
private

◆ GUARDED_BY() [2/2]

bool m_eof DynSock::Pipe::GUARDED_BY ( m_mutex  )
inlineprivate

Definition at line 264 of file net.h.

◆ PushBytes()

void DynSock::Pipe::PushBytes ( const void *  buf,
size_t  len 
)

Push bytes to the pipe.

Definition at line 307 of file net.cpp.

◆ PushNetMsg()

template<typename... Args>
void DynSock::Pipe::PushNetMsg ( const std::string &  type,
Args &&...  payload 
)

Construct and push CNetMessage to the pipe.

Definition at line 337 of file net.h.

Here is the call graph for this function:

◆ WaitForDataOrEof()

void DynSock::Pipe::WaitForDataOrEof ( UniqueLock< Mutex > &  lock)
private

Return when there is some data to read or EOF has been signaled.

Parameters
[in,out]lockUnique lock that must have been derived from m_mutex by WAIT_LOCK(m_mutex, lock).

Definition at line 322 of file net.cpp.

Here is the call graph for this function:

Member Data Documentation

◆ m_cond

std::condition_variable DynSock::Pipe::m_cond
private

Definition at line 262 of file net.h.

◆ m_mutex

Mutex DynSock::Pipe::m_mutex
private

Definition at line 261 of file net.h.


The documentation for this class was generated from the following files: