how would I go about creating a Socket receiveAll method?

Ali Çehreli acehreli at yahoo.com
Tue Dec 12 21:52:57 UTC 2017


On 12/12/2017 01:14 PM, Adam D. Ruppe wrote:
 > 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:

I know you normally do it much better. :)

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

There are a couple of bugs in that code. The same buffer is used for all 
segments and socket.receive should be inside while.

Ali



More information about the Digitalmars-d-learn mailing list