Seastar
High performance C++ framework for concurrent servers
Public Member Functions | Public Attributes | List of all members
seastar::pipe< T > Class Template Reference

Detailed Description

template<typename T>
class seastar::pipe< T >

A fixed-size pipe for communicating between two fibers.

A pipe<T> is a mechanism to transfer data between two fibers, one producing data, and the other consuming it. The fixed-size buffer also ensures a balanced execution of the two fibers, because the producer fiber blocks when it writes to a full pipe, until the consumer fiber gets to run and read from the pipe.

A pipe<T> resembles a Unix pipe, in that it has a read side, a write side, and a fixed-sized buffer between them, and supports either end to be closed independently (and EOF or broken pipe when using the other side). A pipe<T> object holds the reader and write sides of the pipe as two separate objects. These objects can be moved into two different fibers. Importantly, if one of the pipe ends is destroyed (i.e., the continuations capturing it end), the other end of the pipe will stop blocking, so the other fiber will not hang.

The pipe's read and write interfaces are future-based blocking. I.e., the write() and read() methods return a future which is fulfilled when the operation is complete. The pipe is single-reader single-writer, meaning that until the future returned by read() is fulfilled, read() must not be called again (and same for write).

Note: The pipe reader and writer are movable, but not copyable. It is often convenient to wrap each end in a shared pointer, so it can be copied (e.g., used in an std::function which needs to be copyable) or easily captured into multiple continuations.

#include <seastar/core/pipe.hh>

Public Member Functions

 pipe (size_t size)
 

Public Attributes

pipe_reader< T > reader
 
pipe_writer< T > writer
 

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