how to read some in vibe.d tcpconnection?
Kagamin via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Sat Mar 7 01:39:40 PST 2015
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();
More information about the Digitalmars-d-learn
mailing list