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:

  1. If you simply want to stream from an InputStream to an OutputStream, you can call output.write(input) and it will pipe everything until the input connection is closed (or until the specified limit is reached).

  2. 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]);
    }