Reading data from the network without knowing the size of the buffer that is coming
Vladimir Panteleev
thecybershadow.lists at gmail.com
Fri Mar 22 10:32:44 UTC 2019
On Thursday, 21 March 2019 at 16:54:01 UTC, Roman Sztergbaum
wrote:
> I would like to get rid of the "ubytes[256]" because I do not
> know the size of the data that is comming, I would like to read
> the entire buffer that I send at once. Can someone point me?
If you do not know the size of the response, then how can you
know when you should stop waiting for more bytes?
Some connections are stream-oriented, and some are
datagram-oriented. With a datagram-oriented connection, each
packet has a fixed size (though there is a maximum size). You
mentioned this is a UNIX socket connection, and I believe UNIX
sockets can be either stream-oriented or datagram-oriented.
If the socket is stream-oriented, there should generally be a way
for the other end to signal when it's done sending bytes. This
can be in the form of a fixed-size "header" containing the body
length, or maybe the other end just closes the connection when
it's done writing. Other approaches, like reading until there are
no more bytes in the buffer (though more may yet to arrive one
millisecond later) are generally not reliable.
Perhaps you should include more information like what program you
are trying to talk to, or the protocol being used.
More information about the Digitalmars-d-learn
mailing list