tango.io.device.Conduit

License:

BSD style: see license.txt

Version:

Mar 2004: Initial release

Author:

Kris
class Conduit : IConduit
Conduit abstract base-class, implementing interface IConduit. Only the conduit-specific read(), write(), detach() and bufferSize() need to be implemented for a concrete conduit implementation. See File for an example.
Conduits provide virtualized access to external content, and represent things like files or Internet connections. Conduits expose a pair of streams, are modelled by tango.io.model.IConduit, and are implemented via classes such as File & SocketConduit.

Additional kinds of conduit are easy to construct: either subclass tango.io.device.Conduit, or implement tango.io.model.IConduit. A conduit typically reads and writes via a Buffer in large chunks, typically the entire buffer. Alternatively, one can invoke method read(dst[]) and/or write(src[]) directly.
this()
Test for asynchronous capability. This will be eligable for scheduling where (a) it is created within a fiber and (b) there is a scheduler attached to the fiber at the time this is invoked.
Note that fibers may schedule just one outstanding I/O request at a time.
~this()
Clean up when collected. See method detach().
string toString() [override, abstract]
Return the name of this conduit.
size_t bufferSize() [const, abstract]
Return a preferred size for buffering conduit I/O.
size_t read(void[] dst) [abstract]
Read from conduit into a target array. The provided dst will be populated with content from the conduit.
Returns the number of bytes read, which may be less than requested in dst. Eof is returned whenever an end-of-flow condition arises.
size_t write(const(void)[] src) [abstract]
Write to conduit from a source array. The provided src content will be written to the conduit.
Returns the number of bytes written from src, which may be less than the quantity provided. Eof is returned when an end-of-flow condition arises.
void detach() [abstract]
Disconnect this conduit. Note that this may be invoked both explicitly by the user, and implicitly by the GC. Be sure to manage multiple detachment requests correctly: set a flag, or sentinel value as necessary.
void timeout(uint millisec) [@property, final]
Set the active timeout period for IO calls (in milliseconds.)
uint timeout() [@property, final, const]
Get the active timeout period for IO calls (in milliseconds.)
bool isAlive() [@property, const]
Is the conduit alive? Default behaviour returns true.
IConduit conduit() [@property, final]
Return the host. This is part of the Stream interface.
IOStream flush()
Emit buffered output or reset buffered input.
void close()
Close this conduit.
Both input and output are detached, and are no longer usable.
void error(const(char[]) msg) [final]
Throw an IOException, with the provided message.
InputStream input() [@property, final]
Return the input stream.
OutputStream output() [@property, final]
Return the output stream.
Conduit put(void[] src) [final]
Emit fixed-length content from 'src' into this conduit, throwing an IOException upon Eof.
Conduit get(void[] dst) [final]
Consume fixed-length content into 'dst' from this conduit, throwing an IOException upon Eof.
Conduit rewind() [final]
Rewind to beginning of file.
OutputStream copy(InputStream src, size_t max = -1)
Transfer the content of another conduit to this one. Returns the dst OutputStream, or throws IOException on failure.
long seek(long offset, Anchor anchor = Begin)
Seek on this stream. Source conduits that don't support seeking will throw an IOException.
char[] text(T = char)(size_t max = -1)
Load text from a stream, and return them all in an array.
Returns an array representing the content, and throws IOException on error.
void[] load(size_t max = -1)
Load the bits from a stream, and return them all in an array. The dst array can be provided as an option, which will be expanded as necessary to consume the input.
Returns an array representing the content, and throws IOException on error.
void[] load(InputStream src, size_t max = -1) [static]
Load the bits from a stream, and return them all in an array. The dst array can be provided as an option, which will be expanded as necessary to consume input.
Returns an array representing the content, and throws IOException on error.
void put(void[] src, OutputStream output) [static]
Emit fixed-length content from 'src' into 'output', throwing an IOException upon Eof.
void get(void[] dst, InputStream input) [static]
Consume fixed-length content into 'dst' from 'input', throwing an IOException upon Eof.
size_t transfer(InputStream src, OutputStream dst, size_t max = -1) [static]
Low-level data transfer, where max represents the maximum number of bytes to transfer.
Returns Eof on failure, number of bytes copied on success.
class InputFilter : InputStream
Base class for input stream filtering. The provided source stream should generally never be null, though some filters have a need to set this lazily.
this(InputStream source)
Attach to the provided stream. The provided source stream should generally never be null, though some filters have a need to set this lazily.
IConduit conduit() [@property]
Return the hosting conduit.
size_t read(void[] dst)
Read from conduit into a target array. The provided dst will be populated with content from the conduit.
Returns the number of bytes read, which may be less than requested in dst. Eof is returned whenever an end-of-flow condition arises.
void[] load(size_t max = -1)
Load the bits from a stream, and return them all in an array. The dst array can be provided as an option, which will be expanded as necessary to consume the input.
Returns an array representing the content, and throws IOException on error.
IOStream flush()
Clear any buffered content.
long seek(long offset, Anchor anchor = Begin)
Seek on this stream. Target conduits that don't support seeking will throw an IOException.
InputStream input() [@property]
Return the upstream host of this filter.
void close()
Close the input.
class OutputFilter : OutputStream
Base class for output stream filtering. The provided sink stream should generally never be null, though some filters have a need to set this lazily.
this(OutputStream sink)
Attach to the provided stream.
IConduit conduit() [@property]
Return the hosting conduit.
size_t write(const(void)[] src)
Write to conduit from a source array. The provided src content will be written to the conduit.
Returns the number of bytes written from src, which may be less than the quantity provided. Eof is returned when an end-of-flow condition arises.
OutputStream copy(InputStream src, size_t max = -1)
Transfer the content of another conduit to this one. Returns a reference to this class, or throws IOException on failure.
IOStream flush()
Emit/purge buffered content.
long seek(long offset, Anchor anchor = Begin)
Seek on this stream. Target conduits that don't support seeking will throw an IOException.
OutputStream output() [@property]
Return the upstream host of this filter.
void close()
Close the output.