Conduit

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.

Constructors

this
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.

Destructor

~this
~this()

Clean up when collected. See method detach().

Members

Functions

bufferSize
size_t bufferSize()

Return a preferred size for buffering conduit I/O.

close
void close()

Close this conduit.

copy
OutputStream copy(InputStream src, size_t max)

Transfer the content of another conduit to this one. Returns the dst OutputStream, or throws IOException on failure.

detach
void detach()

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.

error
void error(const(char[]) msg)

Throw an IOException, with the provided message.

flush
IOStream flush()

Emit buffered output or reset buffered input.

get
Conduit get(void[] dst)

Consume fixed-length content into 'dst' from this conduit, throwing an IOException upon Eof.

load
void[] load(size_t max)

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.

put
Conduit put(void[] src)

Emit fixed-length content from 'src' into this conduit, throwing an IOException upon Eof.

read
size_t read(void[] dst)

Read from conduit into a target array. The provided dst will be populated with content from the conduit.

rewind
Conduit rewind()

Rewind to beginning of file.

seek
long seek(long offset, Anchor anchor)

Seek on this stream. Source conduits that don't support seeking will throw an IOException.

text
char[] text(size_t max)

Load text from a stream, and return them all in an array.

toString
string toString()

Return the name of this conduit.

write
size_t write(const(void)[] src)

Write to conduit from a source array. The provided src content will be written to the conduit.

Properties

conduit
IConduit conduit [@property getter]

Return the host. This is part of the Stream interface.

input
InputStream input [@property getter]

Return the input stream.

isAlive
bool isAlive [@property getter]

Is the conduit alive? Default behaviour returns true.

output
OutputStream output [@property getter]

Return the output stream.

timeout
uint timeout [@property setter]

Set the active timeout period for IO calls (in milliseconds.)

timeout
uint timeout [@property getter]

Get the active timeout period for IO calls (in milliseconds.)

Static functions

get
void get(void[] dst, InputStream input)

Consume fixed-length content into 'dst' from 'input', throwing an IOException upon Eof.

load
void[] load(InputStream src, size_t max)

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.

put
void put(void[] src, OutputStream output)

Emit fixed-length content from 'src' into 'output', throwing an IOException upon Eof.

transfer
size_t transfer(InputStream src, OutputStream dst, size_t max)

Low-level data transfer, where max represents the maximum number of bytes to transfer.

Variables

scheduler
Fiber.Scheduler scheduler;
Undocumented in source.

Meta