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

Author Topic: Selector Status and TcpSocket Status Different  (Read 2386 times)

0 Members and 1 Guest are viewing this topic.

Ruckamongus

  • Jr. Member
  • **
  • Posts: 70
    • View Profile
Selector Status and TcpSocket Status Different
« on: November 22, 2012, 02:23:11 am »
I've got a few TcpSockets and a TcpListener in a selector. Why does this happen:

if (selector.isReady(client))
{
        // The client has sent some data, we can receive it
        std::cout << "Is ready\n";//Shows
       
        sf::Packet packet;
        int Status = client.receive(packet);
       
        std::cout << "Status: " << Status << '\n';//Displays 1, aka Socket::NotReady
        if (Status == sf::Socket::Done)
        {
                std::cout << "Message recieved!\n"; //Never happens
        }
}
 

Shouldn't these values be the same? I'm using the SocketSelector example in the SFML 2.0 documentation. I am also using the latest git snapshot of SFML. One final thing: both the listener and all TcpSockets are NOT blocking.
« Last Edit: November 22, 2012, 04:15:25 am by Ruckamongus »

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: Selector Status and TcpSocket Status Different
« Reply #1 on: November 22, 2012, 08:08:00 am »
A socket is ready for reading if calling the receive function wouldn't block. So non-blocking sockets are always ready. It doesn't make sense to use a selector with non-blocking sockets.
Laurent Gomila - SFML developer

Ruckamongus

  • Jr. Member
  • **
  • Posts: 70
    • View Profile
Re: Selector Status and TcpSocket Status Different
« Reply #2 on: November 22, 2012, 08:20:19 am »
Yeah, I suppose that makes sense. I would like to mention though, that using the method from above does not work, but the other version does. I mean:

receive (void *data, std::size_t size, std::size_t &received)


Works properly, whereas

receive (Packet &packet)

does not, with the exact same code. Maybe if you have time to test your example on the documentation (http://www.sfml-dev.org/documentation/2.0/classsf_1_1SocketSelector.php) you can see what I mean. the given example does not work with the packet version.