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

Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Topics - addisonElliott

Pages: [1]
1
Feature requests / Select function
« on: June 06, 2015, 06:43:48 am »
Hello,
I would like to request that a Select function be added to the TcpSocket class. The main benefit of this would be for programmers who are utilizing non-blocking.

In my case, I am working on a game that needs to be responsive at all times. This means that the connect, receive, or send functions cannot be blocking. Here is how I would like to do it:
while (running)
{
    sf::TcpClient::Status status = socket.Select();
    if (status & sf::TcpClient::Write)
    {
          socket.Send(buffer);
    }
   
    if (status & sf::TcpClient::Read)
    {
          socket.Recv(buffer);
    }

    if (status & sf::TcpClient::Error)
    {
          Error.
    }
    // Other game stuff
}

The current way to achieve this is to continually call connect, in which the host & port parameters are required everytime. Then once you are connected, you call send/recv in the hopes that data is there or that it is able to send data. The reason why I would like the select function is because it is one function that will tell you if there was an error, if its ready to send data, and if it has data waiting to be received.

A problem I see with my proposed implementation of the Select function is that you are 'doubling' up on error checking. Currently, WSAGetLastError is called in the connect, recv, and send functions to report any error. But then you are calling Select which will report if there is an error there as well. This doesn't have a huge affect on anything, but it is unnecessary to do this.

Since SFML does not offer what I need, I have my own wrapper which does the same thing effectively. I would prefer to use SFML's networking class just to be consistent since the rest of the game uses it.

Pages: [1]