SFML community forums

Help => Network => Topic started by: ARandomFurry on June 10, 2015, 08:32:09 pm

Title: Question about TcpSocket::receive()
Post by: ARandomFurry on June 10, 2015, 08:32:09 pm
When I call receive() on a TcpSocket and there is more data available than the size of the buffer what happens to the rest of the data? Would I simple get it in a subsequent call of receive()? I'm using SFML 2.1 by the way and I know there is a partial status given for send() on Tcp now (in 2.3).

A small example case; lets suppose I use receive() to read a single character at a time, if I use a selector would selector.wait() trigger immediately, or would I have to stick selector.isready in a while loop?
Title: Re: Question about TcpSocket::receive()
Post by: binary1248 on June 11, 2015, 01:43:58 am
The selector triggers when a subsequent read operation is guaranteed not to block. This means that even if you don't read all the received data in one go, wait() will still return immediately if called after that. It will keep doing so until you completely emptied out the socket receive buffer after which it would block as usual.

TcpSocket::receive(), as stated clearly in the documentation, takes a size parameter which indicates the "Maximum number of bytes that can be received". It doesn't have to be able to fit all the data in it at once, and this was never the idea. Think of the socket buffer like a std::deque, you pop data from the front and new data is pushed in the back. Nothing is lost unless you yourself throw it away.
Title: Re: Question about TcpSocket::receive()
Post by: ARandomFurry on June 11, 2015, 04:59:29 pm
Thank you, so you're saying that reading the TcpSocket buffer a single character at a time will work with a normal Selector.wait loop, awesome. No, I'm not actually reading a single character at a time.