class ThreadPipe: tango.io.device.Conduit.Conduit;
Conduit to support a data stream between 2 threads. One creates a
ThreadPipe, then uses the OutputStream and the InputStream from it to
communicate. All traffic is automatically synchronized, so one just uses
the streams like they were normal device streams.
It works by maintaining a circular buffer, where data is written to, and
read from, in a FIFO fashion.
auto tc = new ThreadPipe;
void outFunc()
{
Stdout.copy(tc.input);
}
auto t = new Thread(&outFunc);
t.start();
tc.write("hello, thread!");
tc.close();
t.join();
this(ulong bufferSize = cast(ulong)(1024 * 16));
Create a new ThreadPipe with the given buffer size.
Params:
ulong bufferSize
The size to allocate the buffer.
const const size_t bufferSize();
Implements IConduit.bufferSize.
Returns the appropriate buffer size that should be used to buffer the
ThreadPipe. Note that this is simply the buffer size passed in, and
since all the ThreadPipe data is in memory, buffering doesn't make
much sense.
string toString();
Implements IConduit.toString
Returns "<thread conduit>"
const const bool isAlive();
Returns true if there is data left to be read, and the write end isn't
closed.
size_t remaining();
Return the number of bytes remaining to be read in the circular buffer.
size_t writable();
Return the number of bytes that can be written to the circular buffer.
void stop();
Close the write end of the conduit. Writing to the conduit after it is
closed will return Eof.
The read end is not closed until the buffer is empty.
void detach();
This does nothing because we have no clue whether the members have been
collected, and detach is run in the destructor. To stop communications,
use stop().
TODO:
move stop() functionality to detach when it becomes possible to
have fully-owned members
size_t read(void[] dst);
Implements InputStream.read.
Read from the conduit into a target array. The provided dst will be
populated with content from the stream.
Returns the number of bytes read, which may be less than requested in
dst. Eof is returned whenever an end-of-flow condition arises.
ThreadPipe clear();
Implements InputStream.clear().
Clear any buffered content.
size_t write(const(void)[] src);
Implements OutputStream.write.
Write to stream from a source array. The provided src content will be
written to the stream.
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.
Page generated by Ddoc. Copyright (c) 2008 Steven Schveighoffer.
All rights reserved