InPipe

InPipe is a class for reading input from an arbitrary data source such as a file, network socket, or encryption/compression codec. It's often used as the underlying input source of an InStream.

InPipe is a lower-level class than InStream and is more akin to a Unix file descriptor. When the InPipe reads from a file or network socket, each call to readSome() or read() invokes a system call to the OS kernel. Therefore, when reading directly from an InPipe, it's best to read medium-to-large quantities of data (say, several KB) at a time in order to minimize system call overhead.

If reading small amounts of data (say, a few bytes) at a time -- for example, to parse text or binary formats -- it's better to work with InStream or StringReader instead.

Header File

#include <ply-runtime/io/Pipe.h>

Also included from <ply-runtime/Base.h>.

Member Functions

template <typename T>
T* cast() [code]

Cast this InPipe to a derived type such as InPipe_Win32, InPipe_FD or InPipe_Winsock in order to access additional functions or data members. A runtime check is performed to ensure the cast is valid.

u32 readSome(BufferView buf) [code]

Attempts to read some data into buf from the input source. If the InPipe is waiting for data, this function will block until some data arrives. Returns the actual number of bytes read, which might be less than the size of buf. Returns 0 if EOF/error is encountered.

bool read(BufferView buf) [code]

Attempts to completely fill buf with data from the input source. If the InPipe is waiting for data, this function will block until buf is completely filled. Returns true if successful. [FIXME: Reconsider how incomplete reads are handled]

u64 getFileSize() const [code]

If the InPipe is reading from a file, returns the size of the file in bytes.