Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed socket reuse not conforming to documentation #1408

Merged
merged 1 commit into from Apr 14, 2018

Conversation

binary1248
Copy link
Member

Fixes #1346 and the scenarios listed here.

Test with:

#include <SFML/Network.hpp>
#include <iostream>

#define TEST1

int main()
{

#if defined(TEST1)

    sf::TcpListener l;
    l.listen(2016);
    l.listen(2017);

    sf::TcpSocket s;
    if (s.connect(sf::IpAddress::LocalHost, 2017) == sf::Socket::Done)
        std::cout << "This message should be displayed\n";

#elif defined(TEST2)

    sf::TcpListener l;
    l.listen(2017);

    sf::TcpSocket sock;
    if (sock.connect(sf::IpAddress::LocalHost, 2017) == sf::Socket::Done)
        std::cout << "This message should be displayed\n";

    if (sock.connect({1,2,3,4}, 2017) == sf::Socket::Done)
        std::cout << "This message should NOT be displayed\n";

#elif defined(TEST3)

    sf::TcpListener l;
    l.listen(2017);

    sf::TcpSocket s;
    if (s.connect({1,2,3,4}, 2017, sf::milliseconds(200)) == sf::Socket::Done)
        std::cout << "This message should NOT be displayed\n";

    if (s.connect(sf::IpAddress::LocalHost, 2017) == sf::Socket::Done)
        std::cout << "This message should be displayed\n";

#elif defined(TEST4)

    char data[5];
    std::size_t size = sizeof(data);
    sf::IpAddress address;
    unsigned short port;

    sf::UdpSocket s;
    s.bind(2016);
    s.bind(2017);

    if (s.send("Test", 5, sf::IpAddress::LocalHost, 2017) == sf::Socket::Done)
        std::cout << "This message should be displayed\n";

    if (s.receive(reinterpret_cast<void*>(data), size, size, address, port) == sf::Socket::Done)
        std::cout << "This message should be displayed\n";

#endif

    char ch;
    std::cin >> ch;
}

All test scenarios should print or not print the corresponding messages. Without this patch they would all fail.

Copy link
Member

@LaurentGomila LaurentGomila left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good 👍

@eXpl0it3r eXpl0it3r added this to Discussion in SFML 2.5.0 via automation Apr 8, 2018
@eXpl0it3r eXpl0it3r added this to the 2.5 milestone Apr 8, 2018
@eXpl0it3r eXpl0it3r moved this from Discussion to Ready in SFML 2.5.0 Apr 8, 2018
…ng listen or connect while the underlying socket object already exists, also adjusted UdpSocket to be consistent with connect and listen behaviour when calling bind while the underlying socket object already exists. Fixes #1346
@eXpl0it3r eXpl0it3r merged commit 9bdd6d4 into master Apr 14, 2018
SFML 2.5.0 automation moved this from Ready to Merged / Superseded Apr 14, 2018
@eXpl0it3r eXpl0it3r deleted the bugfix/socket_reuse branch April 14, 2018 08:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
No open projects
SFML 2.5.0
  
Merged / Superseded
Development

Successfully merging this pull request may close these issues.

None yet

3 participants