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

Author Topic: Usage of sf::Socket::Status in non-blocking sockets?  (Read 4380 times)

0 Members and 1 Guest are viewing this topic.

D

  • Newbie
  • *
  • Posts: 12
    • View Profile
Usage of sf::Socket::Status in non-blocking sockets?
« on: January 17, 2011, 05:15:49 pm »
Hi. I'm using SFML2 in my project and non-blocking UDP socket. According to the API, I should get enum code 1 (NotReady), when I send data when the previous data hasn't been completely sent yet, do I understand this correctly?

When I run the code (just sending data in a loop), on OS X, I get enum code 3 (Error) when the previous data hasn't been sent yet. On Windows, I get 0 (Done) all the time. Either there's a bug in the library, or I'm just understanding the whole thing wrong. Receiving works correctly afaik.

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Usage of sf::Socket::Status in non-blocking sockets?
« Reply #1 on: January 18, 2011, 08:04:22 am »
Can you show a complete and minimal piece of code that reproduces this problem?
Laurent Gomila - SFML developer

D

  • Newbie
  • *
  • Posts: 12
    • View Profile
Usage of sf::Socket::Status in non-blocking sockets?
« Reply #2 on: January 18, 2011, 09:54:57 am »
The following code:
Code: [Select]
#include <SFML/Network.hpp>
#include <iostream>

int main() {
  sf::IpAddress ip("localhost");
  sf::UdpSocket socket;
  sf::Packet packet;
  sf::Socket::Status socket_status = sf::Socket::Done;
  sf::Socket::Status receive_status = sf::Socket::Done;
  unsigned short port = 55555;

  socket.Bind(sf::UdpSocket::Socket::AnyPort);
  socket.SetBlocking(false);

  while (true) {
    socket_status = socket.Send(packet, ip, port);

    if (receive_status==0) {
      receive_status = socket.Receive(packet,ip,port);
      std::cout << "Received." << std::endl;
    }

    std::cout << "Socket status is: " << socket_status << std::endl;
    std::cout << "Receive status is: " << receive_status << std::endl;

    if (!socket_status==0)
      return 1;

    packet.Clear();
  }

}


Produces following output (on Mac OS X 10.6.6):
Code: [Select]
Socket status is: 0
Receive status is: 1
Socket status is: 3
Receive status is: 1


Strangely, I found out that if I comment out the receive part (even if it is not called even once), both statuses are always 0. I don't know how what output Windows does, because I don't have a Windows computer around, but I'll post it too later on, if needed. I didn't have any server running when doing this test, but it shouldn't affect the outcome, should it?

Is this a bug or is it my code? :) Thanks for your help.

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Usage of sf::Socket::Status in non-blocking sockets?
« Reply #3 on: January 18, 2011, 10:22:54 am »
Ok I'll test that, thanks for the code. I'll try it on Linux, the network code is the same as on Mac OS X.
Laurent Gomila - SFML developer

D

  • Newbie
  • *
  • Posts: 12
    • View Profile
Usage of sf::Socket::Status in non-blocking sockets?
« Reply #4 on: January 31, 2011, 10:07:04 pm »
Any news regarding to the issue?

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Usage of sf::Socket::Status in non-blocking sockets?
« Reply #5 on: February 01, 2011, 07:56:40 am »
Not yet, sorry. There are so many things that I have to test... :cry:
Laurent Gomila - SFML developer

 

anything