OutPipe
OutPipe
is a class for writing output to an arbitrary destination such as a file, network socket,
or encryption/compression codec. It's often used as the underlying output destination of an
OutStream
.
OutPipe
is a lower-level class than OutStream
and is more akin to a Unix file descriptor. When
the OutPipe
writes to a file or network socket, each call to write()
invokes a system call to
the OS kernel. Therefore, when writing directly to an OutPipe
, it's best to write medium-to-large
quantities of data (say, several KB) at a time in order to minimize system call overhead.
If writing 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 OutStream
instead.
Header File
#include <ply-runtime/io/Pipe.h>
Also included from <ply-runtime/Base.h>
.
Member Functions
-
Cast this
OutPipe
to a derived type such asOutPipe_Win32
,OutPipe_FD
orOutPipe_Winsock
in order to access additional functions or data members. A runtime check is performed to ensure the cast is valid. -
Attempts to write the entire contents of
buf
to the output destination. This call may block depending on the state of theOutPipe
. For example, if theOutPipe
is a network socket or interprocess pipe, and the process on the other end is not reading quickly enough,write()
may block. Returnstrue
if successful. Returnfalse
if the write fails such as when attempting to write to a network socket that was closed prematurely. -
Flushes any application-level memory buffers in the same manner as
flushMem()
, then performs an implementation-specific device flush iftoDevice
istrue
. For example, iftoDevice
istrue
, this will callfsync()
on when writing to a POSIX file descriptor orFlushFileBuffers()
when writing to a Windows file handle. Returnstrue
unless there's an error in the implementation-specific device flush. -
Flushes any application-level memory buffers maintained by the
OutPipe
will be flushed to their destination. Appropriate to use when theOutPipe
is a line feed filter or any kind of application-level conversion, compression or encryption filter. -
If the output destination is seekable, seeks to the specified file offset and returns the current file offset. To get the current file offset without changing it, call
seek(0, SeekDir::Cur)
.