how would I go about creating a Socket receiveAll method?

Adam D. Ruppe destructionator at gmail.com
Tue Dec 12 21:14:30 UTC 2017


On Tuesday, 12 December 2017 at 21:03:54 UTC, Unazed Spectaculum 
wrote:
> I've decided to go for the run-time approach to this, it works 
> fine with all of my tests so you have my greatest gratitude.

the way I'd do it btw is simply:

ubyte[] result;
ubyte[1024] buffer;
auto got = socket.receive(buffer[]);
while(got > 0) {
    result ~= buffer[0 .. got];
}

if(got < 0)
   throw new Exception(lastSocketError());

return result;


so it uses the one static buffer to receive the stuff one block 
at a time but just copies it over to the dynamic array with the 
~= operator


More information about the Digitalmars-d-learn mailing list