On Fri, 06 Mar 2015 11:23:52 GMT, Sönke Ludwig wrote:
On Fri, 06 Mar 2015 10:24:57 GMT, zhmt wrote:
in boost::asio, It has a method like this :
basicstreamsocket::read_some (1 of 2 overloads)
This function is used to read data from the stream socket. The
function call will block until one or more bytes of data has been
read successfully, or until an error occurs.how can I get this function in vibe.d?
You have two possibilities depending on how low level you need to go:
If you simply want to stream from an
InputStream
to anOutputStream
, you can calloutput.write(input)
and it will pipe everything until the input connection is closed (or until the specified limit is reached).The underlying low-level functionality is achieved using the
leastSize
property. It returns the amount of data that has currently already been received:ubyte[256] buffer; while (!input.empty) { auto chunk = min(input.leastSize, buffer.length); input.read(buffer[0 .. chunk]); // guaranteed to not block now output.write(buffer[0 .. chunk]); }
Thank u very much.
I will choose the first.
But the second is very useful for me in other scenes.
That is a big help, Thanks.