One endpoint of a full-duplex interprocess message pipe.
A Channel wraps one end of an AF_UNIX socketpair() created before forking the child processes, and provides framed, whole-message send and receive operations on top of the byte stream. Each frame is preceded by an 8-byte header containing the payload size and a "more" bit that marks all but the last frame of a multipart message.
Sends never block: bytes that the kernel socket buffer does not accept immediately are stored in a per-channel pending-output buffer, which is flushed opportunistically whenever any Channel in the process waits for input (see wait()). This mimics the previous ZeroMQ setup with an unlimited high-water mark and avoids send-send deadlocks between processes.
Public Member Functions | |
| Channel ()=default | |
| Channel (Channel &&other) noexcept | |
| Channel (const Channel &)=delete | |
| Channel (int fd) | |
| Takes ownership of fd (one end of a socketpair) and makes it non-blocking. | |
| ~Channel () | |
| int | fd () const |
| bool | has_pending_output () const |
| Channel & | operator= (Channel &&other) noexcept |
| Channel & | operator= (const Channel &)=delete |
| Message | recv_frame (bool *more=nullptr) |
| Blocking receive of one complete frame, interruptible by SIGTERM (throws ppoll_error_t, like the poll functions). | |
| void | send_frame (const void *data, std::size_t size, bool more) |
| Queue one frame for sending and write out as much as the socket accepts. | |
| bool | try_flush () |
| Write out pending output; returns true when all of it has been written. | |
| bool | try_recv_frame (Message &msg, bool *more) |
| Non-blocking receive attempt. | |
| bool | valid () const |
Static Public Member Functions | |
| static std::vector< std::size_t > | wait (const std::vector< const Channel * > &read_channels, int timeout_ms) |
| Wait until at least one of read_channels has input available, flushing the pending output of all live Channels in this process meanwhile. | |
Private Member Functions | |
| void | close_fd () |
Static Private Member Functions | |
| static void | throw_connection_closed () |
| Handle end-of-stream / closed-connection conditions; never returns. | |
Private Attributes | |
| int | fd_ = -1 |
| bool | in_have_header_ = false |
| std::uint64_t | in_header_ = 0 |
| std::size_t | in_header_bytes_ = 0 |
| Message | in_msg_ |
| std::size_t | in_msg_bytes_ = 0 |
| std::vector< char > | out_buf_ |
| std::size_t | out_pos_ = 0 |
#include </github/home/ROOT-CI/src/roofit/multiprocess/res/RooFit/MultiProcess/Channel.h>
|
default |
|
explicit |
Takes ownership of fd (one end of a socketpair) and makes it non-blocking.
Definition at line 68 of file Channel.cxx.
| RooFit::MultiProcess::Channel::~Channel | ( | ) |
Definition at line 82 of file Channel.cxx.
|
noexcept |
Definition at line 90 of file Channel.cxx.
|
private |
Definition at line 131 of file Channel.cxx.
|
inline |
Definition at line 107 of file Channel.cxx.
Blocking receive of one complete frame, interruptible by SIGTERM (throws ppoll_error_t, like the poll functions).
Definition at line 255 of file Channel.cxx.
Queue one frame for sending and write out as much as the socket accepts.
Definition at line 158 of file Channel.cxx.
|
staticprivate |
Handle end-of-stream / closed-connection conditions; never returns.
Definition at line 139 of file Channel.cxx.
| bool RooFit::MultiProcess::Channel::try_flush | ( | ) |
Write out pending output; returns true when all of it has been written.
Definition at line 177 of file Channel.cxx.
Non-blocking receive attempt.
Returns true and fills msg/more when a complete frame was received; returns false if more bytes are needed.
Definition at line 198 of file Channel.cxx.
|
static |
Wait until at least one of read_channels has input available, flushing the pending output of all live Channels in this process meanwhile.
Returns the indices into read_channels that are readable. A negative timeout means wait forever; otherwise the result may be empty after timeout_ms milliseconds. Throws ppoll_error_t with num() == EINTR when interrupted by a signal (including the SIGTERM self-pipe wake-up).
Definition at line 264 of file Channel.cxx.
|
private |
|
private |
|
private |
|
private |
|
private |