On Saturday, 7 March 2015 at 09:39:42 UTC, Kagamin wrote:
On Saturday, 7 March 2015 at 02:23:10 UTC, zhmt wrote:
Hi,I got the right answer in vibe.d forum,here is the link:
http://forum.rejectedsoftware.com/groups/rejectedsoftware.vibed/thread/24403/#post-24416
If that's correct, you can write an extension method for
InputStream in terms of asio:
ubyte[] readSome(InputStream input, ubyte[] buffer)
{
if(input.empty)return null;
const len = min(input.leastSize, buffer.length);
ubyte[] chunk = buffer[0 .. len];
input.read(chunk); // guaranteed to not block now
return chunk;
}
And use:
InputStream input=...;
ubyte[256] buffer;
auto chunk = input.readSome(buffer);
if(chunk==null)return done();
Yes, this a good idea, if the author of vibe.d do this, will be
better, it is used frequently in many scenes.