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
instead.
Header File
#include <ply-runtime/io/Pipe.h>
Also included from <ply-runtime/Base.h>
.
Member Functions
-
Cast this
InPipe
to a derived type such asInPipe_Win32
,InPipe_FD
orInPipe_Winsock
in order to access additional functions or data members. A runtime check is performed to ensure the cast is valid. -
Attempts to read some data into
buf
from the input source. If theInPipe
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 ofbuf
. Returns 0 if EOF/error is encountered. -
Attempts to completely fill
buf
with data from the input source. If theInPipe
is waiting for data, this function will block untilbuf
is completely filled. Returnstrue
if successful. [FIXME: Reconsider how incomplete reads are handled] -
If the
InPipe
is reading from a file, returns the size of the file in bytes.