Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: Question about TcpSocket::receive()  (Read 2366 times)

0 Members and 1 Guest are viewing this topic.

ARandomFurry

  • Newbie
  • *
  • Posts: 10
    • View Profile
    • Email
Question about TcpSocket::receive()
« 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?

binary1248

  • SFML Team
  • Hero Member
  • *****
  • Posts: 1405
  • I am awesome.
    • View Profile
    • The server that really shouldn't be running
Re: Question about TcpSocket::receive()
« Reply #1 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.
SFGUI # SFNUL # GLS # Wyrm <- Why do I waste my time on such a useless project? Because I am awesome (first meaning).

ARandomFurry

  • Newbie
  • *
  • Posts: 10
    • View Profile
    • Email
Re: Question about TcpSocket::receive()
« Reply #2 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.

 

anything