From 466eb88ee65af6c66d21f35db11bbf09e283d962 Mon Sep 17 00:00:00 2001 From: Shawn Hoffman Date: Mon, 29 Jun 2009 15:51:35 +0000 Subject: [PATCH] update to sfml 1.5 git-svn-id: https://dolphin-emu.googlecode.com/svn/trunk@3594 8ced0084-cf51-0410-be5f-012b33b47a6e --- Externals/SFML/include/SFML/Config.hpp | 7 +++- Externals/SFML/include/SFML/Network.hpp | 2 +- Externals/SFML/include/SFML/Network/Ftp.hpp | 2 +- Externals/SFML/include/SFML/Network/Http.hpp | 7 ++-- .../SFML/include/SFML/Network/IPAddress.hpp | 6 ++-- .../SFML/include/SFML/Network/Packet.hpp | 2 +- .../SFML/include/SFML/Network/Selector.hpp | 2 +- .../SFML/include/SFML/Network/Selector.inl | 2 +- .../include/SFML/Network/SelectorBase.hpp | 2 +- .../include/SFML/Network/SocketHelper.hpp | 2 +- .../SFML/include/SFML/Network/SocketTCP.hpp | 2 +- .../SFML/include/SFML/Network/SocketUDP.hpp | 8 +++-- .../SFML/include/SFML/Network/Sockets.hpp | 2 +- .../SFML/Network/Win32/SocketHelper.hpp | 2 +- Externals/SFML/include/SFML/System.hpp | 20 +++++------ .../SFML/include/SFML/System/NonCopyable.hpp | 2 +- Externals/SFML/src/SFML/Network/Ftp.cpp | 2 +- Externals/SFML/src/SFML/Network/Http.cpp | 6 ++-- Externals/SFML/src/SFML/Network/IPAddress.cpp | 36 ++++++------------- Externals/SFML/src/SFML/Network/Packet.cpp | 2 +- .../SFML/src/SFML/Network/SelectorBase.cpp | 2 +- Externals/SFML/src/SFML/Network/SocketTCP.cpp | 2 +- Externals/SFML/src/SFML/Network/SocketUDP.cpp | 25 +++++++------ .../src/SFML/Network/Unix/SocketHelper.cpp | 8 ++++- .../src/SFML/Network/Win32/SocketHelper.cpp | 2 +- 25 files changed, 78 insertions(+), 77 deletions(-) diff --git a/Externals/SFML/include/SFML/Config.hpp b/Externals/SFML/include/SFML/Config.hpp index 86800e42aa..91d052f8dc 100644 --- a/Externals/SFML/include/SFML/Config.hpp +++ b/Externals/SFML/include/SFML/Config.hpp @@ -1,7 +1,7 @@ //////////////////////////////////////////////////////////// // // SFML - Simple and Fast Multimedia Library -// Copyright (C) 2007 Laurent Gomila (laurent.gom@gmail.com) +// Copyright (C) 2007-2009 Laurent Gomila (laurent.gom@gmail.com) // // This software is provided 'as-is', without any express or implied warranty. // In no event will the authors be held liable for any damages arising from the use of this software. @@ -49,6 +49,11 @@ // MacOS #define SFML_SYSTEM_MACOS +#elif defined(__FreeBSD__) + + // FreeBSD + #define SFML_SYSTEM_FREEBSD + #else // Unsupported system diff --git a/Externals/SFML/include/SFML/Network.hpp b/Externals/SFML/include/SFML/Network.hpp index fe1730ad62..6ec13d3535 100644 --- a/Externals/SFML/include/SFML/Network.hpp +++ b/Externals/SFML/include/SFML/Network.hpp @@ -1,7 +1,7 @@ //////////////////////////////////////////////////////////// // // SFML - Simple and Fast Multimedia Library -// Copyright (C) 2007 Laurent Gomila (laurent.gom@gmail.com) +// Copyright (C) 2007-2009 Laurent Gomila (laurent.gom@gmail.com) // // This software is provided 'as-is', without any express or implied warranty. // In no event will the authors be held liable for any damages arising from the use of this software. diff --git a/Externals/SFML/include/SFML/Network/Ftp.hpp b/Externals/SFML/include/SFML/Network/Ftp.hpp index 673b9048c9..f2f1bd33d1 100644 --- a/Externals/SFML/include/SFML/Network/Ftp.hpp +++ b/Externals/SFML/include/SFML/Network/Ftp.hpp @@ -1,7 +1,7 @@ //////////////////////////////////////////////////////////// // // SFML - Simple and Fast Multimedia Library -// Copyright (C) 2007-2008 Laurent Gomila (laurent.gom@gmail.com) +// Copyright (C) 2007-2009 Laurent Gomila (laurent.gom@gmail.com) // // This software is provided 'as-is', without any express or implied warranty. // In no event will the authors be held liable for any damages arising from the use of this software. diff --git a/Externals/SFML/include/SFML/Network/Http.hpp b/Externals/SFML/include/SFML/Network/Http.hpp index 3e02531fb8..54e5c1fccc 100644 --- a/Externals/SFML/include/SFML/Network/Http.hpp +++ b/Externals/SFML/include/SFML/Network/Http.hpp @@ -1,7 +1,7 @@ //////////////////////////////////////////////////////////// // // SFML - Simple and Fast Multimedia Library -// Copyright (C) 2007-2008 Laurent Gomila (laurent.gom@gmail.com) +// Copyright (C) 2007-2009 Laurent Gomila (laurent.gom@gmail.com) // // This software is provided 'as-is', without any express or implied warranty. // In no event will the authors be held liable for any damages arising from the use of this software. @@ -315,12 +315,13 @@ public : /// not return instantly; use a thread if you don't want to block your /// application. /// - /// \param Req : Request to send + /// \param Req : Request to send + /// \param Timeout : Maximum time to wait, in seconds (0 by default, means no timeout) /// /// \return Server's response /// //////////////////////////////////////////////////////////// - Response SendRequest(const Request& Req); + Response SendRequest(const Request& Req, float Timeout = 0.f); private : diff --git a/Externals/SFML/include/SFML/Network/IPAddress.hpp b/Externals/SFML/include/SFML/Network/IPAddress.hpp index 8373315228..638dc47889 100644 --- a/Externals/SFML/include/SFML/Network/IPAddress.hpp +++ b/Externals/SFML/include/SFML/Network/IPAddress.hpp @@ -1,7 +1,7 @@ //////////////////////////////////////////////////////////// // // SFML - Simple and Fast Multimedia Library -// Copyright (C) 2007-2008 Laurent Gomila (laurent.gom@gmail.com) +// Copyright (C) 2007-2009 Laurent Gomila (laurent.gom@gmail.com) // // This software is provided 'as-is', without any express or implied warranty. // In no event will the authors be held liable for any damages arising from the use of this software. @@ -123,10 +123,12 @@ public : /// distant website ; as a consequence, this function may be /// very slow -- use it as few as possible ! /// + /// \param Timeout : Maximum time to wait, in seconds (0 by default : no timeout) + /// /// \return Public IP address /// //////////////////////////////////////////////////////////// - static IPAddress GetPublicAddress(); + static IPAddress GetPublicAddress(float Timeout = 0.f); //////////////////////////////////////////////////////////// /// Comparison operator == diff --git a/Externals/SFML/include/SFML/Network/Packet.hpp b/Externals/SFML/include/SFML/Network/Packet.hpp index 3add17ffcc..9c5463f423 100644 --- a/Externals/SFML/include/SFML/Network/Packet.hpp +++ b/Externals/SFML/include/SFML/Network/Packet.hpp @@ -1,7 +1,7 @@ //////////////////////////////////////////////////////////// // // SFML - Simple and Fast Multimedia Library -// Copyright (C) 2007-2008 Laurent Gomila (laurent.gom@gmail.com) +// Copyright (C) 2007-2009 Laurent Gomila (laurent.gom@gmail.com) // // This software is provided 'as-is', without any express or implied warranty. // In no event will the authors be held liable for any damages arising from the use of this software. diff --git a/Externals/SFML/include/SFML/Network/Selector.hpp b/Externals/SFML/include/SFML/Network/Selector.hpp index 3ab7dfaa70..588a72c1cc 100644 --- a/Externals/SFML/include/SFML/Network/Selector.hpp +++ b/Externals/SFML/include/SFML/Network/Selector.hpp @@ -1,7 +1,7 @@ //////////////////////////////////////////////////////////// // // SFML - Simple and Fast Multimedia Library -// Copyright (C) 2007-2008 Laurent Gomila (laurent.gom@gmail.com) +// Copyright (C) 2007-2009 Laurent Gomila (laurent.gom@gmail.com) // // This software is provided 'as-is', without any express or implied warranty. // In no event will the authors be held liable for any damages arising from the use of this software. diff --git a/Externals/SFML/include/SFML/Network/Selector.inl b/Externals/SFML/include/SFML/Network/Selector.inl index 326c994602..40ac948afe 100644 --- a/Externals/SFML/include/SFML/Network/Selector.inl +++ b/Externals/SFML/include/SFML/Network/Selector.inl @@ -1,7 +1,7 @@ //////////////////////////////////////////////////////////// // // SFML - Simple and Fast Multimedia Library -// Copyright (C) 2007-2008 Laurent Gomila (laurent.gom@gmail.com) +// Copyright (C) 2007-2009 Laurent Gomila (laurent.gom@gmail.com) // // This software is provided 'as-is', without any express or implied warranty. // In no event will the authors be held liable for any damages arising from the use of this software. diff --git a/Externals/SFML/include/SFML/Network/SelectorBase.hpp b/Externals/SFML/include/SFML/Network/SelectorBase.hpp index 433e7893c4..4b9e9157a7 100644 --- a/Externals/SFML/include/SFML/Network/SelectorBase.hpp +++ b/Externals/SFML/include/SFML/Network/SelectorBase.hpp @@ -1,7 +1,7 @@ //////////////////////////////////////////////////////////// // // SFML - Simple and Fast Multimedia Library -// Copyright (C) 2007-2008 Laurent Gomila (laurent.gom@gmail.com) +// Copyright (C) 2007-2009 Laurent Gomila (laurent.gom@gmail.com) // // This software is provided 'as-is', without any express or implied warranty. // In no event will the authors be held liable for any damages arising from the use of this software. diff --git a/Externals/SFML/include/SFML/Network/SocketHelper.hpp b/Externals/SFML/include/SFML/Network/SocketHelper.hpp index 36126dbb8a..166ce6074c 100644 --- a/Externals/SFML/include/SFML/Network/SocketHelper.hpp +++ b/Externals/SFML/include/SFML/Network/SocketHelper.hpp @@ -1,7 +1,7 @@ //////////////////////////////////////////////////////////// // // SFML - Simple and Fast Multimedia Library -// Copyright (C) 2007-2008 Laurent Gomila (laurent.gom@gmail.com) +// Copyright (C) 2007-2009 Laurent Gomila (laurent.gom@gmail.com) // // This software is provided 'as-is', without any express or implied warranty. // In no event will the authors be held liable for any damages arising from the use of this software. diff --git a/Externals/SFML/include/SFML/Network/SocketTCP.hpp b/Externals/SFML/include/SFML/Network/SocketTCP.hpp index 452b3045cd..964686a590 100644 --- a/Externals/SFML/include/SFML/Network/SocketTCP.hpp +++ b/Externals/SFML/include/SFML/Network/SocketTCP.hpp @@ -1,7 +1,7 @@ //////////////////////////////////////////////////////////// // // SFML - Simple and Fast Multimedia Library -// Copyright (C) 2007-2008 Laurent Gomila (laurent.gom@gmail.com) +// Copyright (C) 2007-2009 Laurent Gomila (laurent.gom@gmail.com) // // This software is provided 'as-is', without any express or implied warranty. // In no event will the authors be held liable for any damages arising from the use of this software. diff --git a/Externals/SFML/include/SFML/Network/SocketUDP.hpp b/Externals/SFML/include/SFML/Network/SocketUDP.hpp index ba43762de5..37df3f7dd6 100644 --- a/Externals/SFML/include/SFML/Network/SocketUDP.hpp +++ b/Externals/SFML/include/SFML/Network/SocketUDP.hpp @@ -1,7 +1,7 @@ //////////////////////////////////////////////////////////// // // SFML - Simple and Fast Multimedia Library -// Copyright (C) 2007-2008 Laurent Gomila (laurent.gom@gmail.com) +// Copyright (C) 2007-2009 Laurent Gomila (laurent.gom@gmail.com) // // This software is provided 'as-is', without any express or implied warranty. // In no event will the authors be held liable for any damages arising from the use of this software. @@ -100,11 +100,12 @@ public : /// \param MaxSize : Maximum number of bytes to read /// \param SizeReceived : Number of bytes received /// \param Address : Address of the computer which sent the data + /// \param Port : Port on which the remote computer sent the data /// /// \return Status code /// //////////////////////////////////////////////////////////// - Socket::Status Receive(char* Data, std::size_t MaxSize, std::size_t& SizeReceived, IPAddress& Address); + Socket::Status Receive(char* Data, std::size_t MaxSize, std::size_t& SizeReceived, IPAddress& Address, unsigned short& Port); //////////////////////////////////////////////////////////// /// Send a packet of data @@ -124,11 +125,12 @@ public : /// /// \param PacketToReceive : Packet to fill with received data /// \param Address : Address of the computer which sent the packet + /// \param Port : Port on which the remote computer sent the data /// /// \return Status code /// //////////////////////////////////////////////////////////// - Socket::Status Receive(Packet& PacketToReceive, IPAddress& Address); + Socket::Status Receive(Packet& PacketToReceive, IPAddress& Address, unsigned short& Port); //////////////////////////////////////////////////////////// /// Close the socket diff --git a/Externals/SFML/include/SFML/Network/Sockets.hpp b/Externals/SFML/include/SFML/Network/Sockets.hpp index b611e852b8..1359cb973e 100644 --- a/Externals/SFML/include/SFML/Network/Sockets.hpp +++ b/Externals/SFML/include/SFML/Network/Sockets.hpp @@ -1,7 +1,7 @@ //////////////////////////////////////////////////////////// // // SFML - Simple and Fast Multimedia Library -// Copyright (C) 2007-2008 Laurent Gomila (laurent.gom@gmail.com) +// Copyright (C) 2007-2009 Laurent Gomila (laurent.gom@gmail.com) // // This software is provided 'as-is', without any express or implied warranty. // In no event will the authors be held liable for any damages arising from the use of this software. diff --git a/Externals/SFML/include/SFML/Network/Win32/SocketHelper.hpp b/Externals/SFML/include/SFML/Network/Win32/SocketHelper.hpp index d7851b4645..6199c0a2ce 100644 --- a/Externals/SFML/include/SFML/Network/Win32/SocketHelper.hpp +++ b/Externals/SFML/include/SFML/Network/Win32/SocketHelper.hpp @@ -1,7 +1,7 @@ //////////////////////////////////////////////////////////// // // SFML - Simple and Fast Multimedia Library -// Copyright (C) 2007-2008 Laurent Gomila (laurent.gom@gmail.com) +// Copyright (C) 2007-2009 Laurent Gomila (laurent.gom@gmail.com) // // This software is provided 'as-is', without any express or implied warranty. // In no event will the authors be held liable for any damages arising from the use of this software. diff --git a/Externals/SFML/include/SFML/System.hpp b/Externals/SFML/include/SFML/System.hpp index 0fd60564be..769262b459 100644 --- a/Externals/SFML/include/SFML/System.hpp +++ b/Externals/SFML/include/SFML/System.hpp @@ -1,7 +1,7 @@ //////////////////////////////////////////////////////////// // // SFML - Simple and Fast Multimedia Library -// Copyright (C) 2007 Laurent Gomila (laurent.gom@gmail.com) +// Copyright (C) 2007-2009 Laurent Gomila (laurent.gom@gmail.com) // // This software is provided 'as-is', without any express or implied warranty. // In no event will the authors be held liable for any damages arising from the use of this software. @@ -30,14 +30,14 @@ //////////////////////////////////////////////////////////// #include -//#include -//#include -//#include -//#include -//#include -//#include -//#include -//#include -//#include +// #include +// #include +// #include +// #include +// #include +// #include +// #include +// #include +// #include #endif // SFML_SYSTEM_HPP diff --git a/Externals/SFML/include/SFML/System/NonCopyable.hpp b/Externals/SFML/include/SFML/System/NonCopyable.hpp index 338653db6d..3ac6719fca 100644 --- a/Externals/SFML/include/SFML/System/NonCopyable.hpp +++ b/Externals/SFML/include/SFML/System/NonCopyable.hpp @@ -1,7 +1,7 @@ //////////////////////////////////////////////////////////// // // SFML - Simple and Fast Multimedia Library -// Copyright (C) 2007-2008 Laurent Gomila (laurent.gom@gmail.com) +// Copyright (C) 2007-2009 Laurent Gomila (laurent.gom@gmail.com) // // This software is provided 'as-is', without any express or implied warranty. // In no event will the authors be held liable for any damages arising from the use of this software. diff --git a/Externals/SFML/src/SFML/Network/Ftp.cpp b/Externals/SFML/src/SFML/Network/Ftp.cpp index 090e6af803..9dff2b7f4a 100644 --- a/Externals/SFML/src/SFML/Network/Ftp.cpp +++ b/Externals/SFML/src/SFML/Network/Ftp.cpp @@ -1,7 +1,7 @@ //////////////////////////////////////////////////////////// // // SFML - Simple and Fast Multimedia Library -// Copyright (C) 2007-2008 Laurent Gomila (laurent.gom@gmail.com) +// Copyright (C) 2007-2009 Laurent Gomila (laurent.gom@gmail.com) // // This software is provided 'as-is', without any express or implied warranty. // In no event will the authors be held liable for any damages arising from the use of this software. diff --git a/Externals/SFML/src/SFML/Network/Http.cpp b/Externals/SFML/src/SFML/Network/Http.cpp index 4794aff131..2f4c140e8d 100644 --- a/Externals/SFML/src/SFML/Network/Http.cpp +++ b/Externals/SFML/src/SFML/Network/Http.cpp @@ -1,7 +1,7 @@ //////////////////////////////////////////////////////////// // // SFML - Simple and Fast Multimedia Library -// Copyright (C) 2007-2008 Laurent Gomila (laurent.gom@gmail.com) +// Copyright (C) 2007-2009 Laurent Gomila (laurent.gom@gmail.com) // // This software is provided 'as-is', without any express or implied warranty. // In no event will the authors be held liable for any damages arising from the use of this software. @@ -364,7 +364,7 @@ void Http::SetHost(const std::string& Host, unsigned short Port) /// not return instantly; use a thread if you don't want to block your /// application. //////////////////////////////////////////////////////////// -Http::Response Http::SendRequest(const Http::Request& Req) +Http::Response Http::SendRequest(const Http::Request& Req, float Timeout) { // First make sure the request is valid -- add missing mandatory fields Request ToSend(Req); @@ -391,7 +391,7 @@ Http::Response Http::SendRequest(const Http::Request& Req) Response Received; // Connect the socket to the host - if (myConnection.Connect(myPort, myHost) == Socket::Done) + if (myConnection.Connect(myPort, myHost, Timeout) == Socket::Done) { // Convert the request to string and send it through the connected socket std::string RequestStr = ToSend.ToString(); diff --git a/Externals/SFML/src/SFML/Network/IPAddress.cpp b/Externals/SFML/src/SFML/Network/IPAddress.cpp index fa766ae81a..18bf3dd967 100644 --- a/Externals/SFML/src/SFML/Network/IPAddress.cpp +++ b/Externals/SFML/src/SFML/Network/IPAddress.cpp @@ -1,7 +1,7 @@ //////////////////////////////////////////////////////////// // // SFML - Simple and Fast Multimedia Library -// Copyright (C) 2007-2008 Laurent Gomila (laurent.gom@gmail.com) +// Copyright (C) 2007-2009 Laurent Gomila (laurent.gom@gmail.com) // // This software is provided 'as-is', without any express or implied warranty. // In no event will the authors be held liable for any damages arising from the use of this software. @@ -20,7 +20,6 @@ // // 3. This notice may not be removed or altered from any source distribution. // -// ** ALTERED SOURCE : replaced GetPublicAddress() ** //////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////// @@ -158,7 +157,7 @@ IPAddress IPAddress::GetLocalAddress() { // The method here is to connect a UDP socket to anyone (here to localhost), // and get the local socket address with the getsockname function. - // UDP connection will not send anything to the network, so this function won't cause any overhead + // UDP connection will not send anything to the network, so this function won't cause any overhead. IPAddress LocalAddress; @@ -202,35 +201,22 @@ IPAddress IPAddress::GetLocalAddress() //////////////////////////////////////////////////////////// /// Get the computer's public IP address (from the web point of view) //////////////////////////////////////////////////////////// -IPAddress IPAddress::GetPublicAddress() +IPAddress IPAddress::GetPublicAddress(float Timeout) { // The trick here is more complicated, because the only way // to get our public IP address is to get it from a distant computer. - // Here we get the web page from http://www.whatismyip.org + // Here we get the web page from http://www.sfml-dev.org/ip-provider.php // and parse the result to extract our IP address - // (not very hard : the web page contains only our IP address) + // (not very hard : the web page contains only our IP address). - IPAddress PublicAddress; - std::string PageBody; - - // Connect to the web server and get its index page - // www.whatismyip.org is so slow that it times out after ~60s - // better use this one instead, it is much faster... at least here :P - Http Server("www.monip.org"); - Http::Request Request(Http::Request::Get, "/"); - Http::Response Page = Server.SendRequest(Request); - - // If the request was successful, we can extract - // the address from the body of the web page + Http Server("www.sfml-dev.org"); + Http::Request Request(Http::Request::Get, "/ip-provider.php"); + Http::Response Page = Server.SendRequest(Request, Timeout); if (Page.GetStatus() == Http::Response::Ok) - PageBody = Page.GetBody(); + return IPAddress(Page.GetBody()); - size_t str_start = PageBody.find("IP : ", 0) + 5; - size_t str_end = PageBody.find('<', str_start); - - PublicAddress = PageBody.substr(str_start, str_end - str_start); - - return PublicAddress; + // Something failed: return an invalid address + return IPAddress(); } diff --git a/Externals/SFML/src/SFML/Network/Packet.cpp b/Externals/SFML/src/SFML/Network/Packet.cpp index 9bc37ddaff..b1472b424f 100644 --- a/Externals/SFML/src/SFML/Network/Packet.cpp +++ b/Externals/SFML/src/SFML/Network/Packet.cpp @@ -1,7 +1,7 @@ //////////////////////////////////////////////////////////// // // SFML - Simple and Fast Multimedia Library -// Copyright (C) 2007-2008 Laurent Gomila (laurent.gom@gmail.com) +// Copyright (C) 2007-2009 Laurent Gomila (laurent.gom@gmail.com) // // This software is provided 'as-is', without any express or implied warranty. // In no event will the authors be held liable for any damages arising from the use of this software. diff --git a/Externals/SFML/src/SFML/Network/SelectorBase.cpp b/Externals/SFML/src/SFML/Network/SelectorBase.cpp index ebe31a7be7..4afb893493 100644 --- a/Externals/SFML/src/SFML/Network/SelectorBase.cpp +++ b/Externals/SFML/src/SFML/Network/SelectorBase.cpp @@ -1,7 +1,7 @@ //////////////////////////////////////////////////////////// // // SFML - Simple and Fast Multimedia Library -// Copyright (C) 2007-2008 Laurent Gomila (laurent.gom@gmail.com) +// Copyright (C) 2007-2009 Laurent Gomila (laurent.gom@gmail.com) // // This software is provided 'as-is', without any express or implied warranty. // In no event will the authors be held liable for any damages arising from the use of this software. diff --git a/Externals/SFML/src/SFML/Network/SocketTCP.cpp b/Externals/SFML/src/SFML/Network/SocketTCP.cpp index f7f9ec1498..eb32179b30 100644 --- a/Externals/SFML/src/SFML/Network/SocketTCP.cpp +++ b/Externals/SFML/src/SFML/Network/SocketTCP.cpp @@ -1,7 +1,7 @@ //////////////////////////////////////////////////////////// // // SFML - Simple and Fast Multimedia Library -// Copyright (C) 2007-2008 Laurent Gomila (laurent.gom@gmail.com) +// Copyright (C) 2007-2009 Laurent Gomila (laurent.gom@gmail.com) // // This software is provided 'as-is', without any express or implied warranty. // In no event will the authors be held liable for any damages arising from the use of this software. diff --git a/Externals/SFML/src/SFML/Network/SocketUDP.cpp b/Externals/SFML/src/SFML/Network/SocketUDP.cpp index 2cd42274ab..822e167fc5 100644 --- a/Externals/SFML/src/SFML/Network/SocketUDP.cpp +++ b/Externals/SFML/src/SFML/Network/SocketUDP.cpp @@ -1,7 +1,7 @@ //////////////////////////////////////////////////////////// // // SFML - Simple and Fast Multimedia Library -// Copyright (C) 2007-2008 Laurent Gomila (laurent.gom@gmail.com) +// Copyright (C) 2007-2009 Laurent Gomila (laurent.gom@gmail.com) // // This software is provided 'as-is', without any express or implied warranty. // In no event will the authors be held liable for any damages arising from the use of this software. @@ -66,12 +66,8 @@ bool SocketUDP::Bind(unsigned short Port) // Check if the socket is already bound to the specified port if (myPort != Port) { - // If the socket was previously bound to another port, we need to recreate it - if (myPort != 0) - { - Close(); - Create(); - } + // If the socket was previously bound to another port, we need to unbind it first + Unbind(); if (Port != 0) { @@ -163,7 +159,7 @@ Socket::Status SocketUDP::Send(const char* Data, std::size_t Size, const IPAddre /// Receive an array of bytes. /// This function will block if the socket is blocking //////////////////////////////////////////////////////////// -Socket::Status SocketUDP::Receive(char* Data, std::size_t MaxSize, std::size_t& SizeReceived, IPAddress& Address) +Socket::Status SocketUDP::Receive(char* Data, std::size_t MaxSize, std::size_t& SizeReceived, IPAddress& Address, unsigned short& Port) { // First clear the size received SizeReceived = 0; @@ -185,7 +181,7 @@ Socket::Status SocketUDP::Receive(char* Data, std::size_t MaxSize, std::size_t& // Data that will be filled with the other computer's address sockaddr_in Sender; Sender.sin_family = AF_INET; - Sender.sin_port = htons(myPort); + Sender.sin_port = 0; Sender.sin_addr.s_addr = INADDR_ANY; memset(Sender.sin_zero, 0, sizeof(Sender.sin_zero)); SocketHelper::LengthType SenderSize = sizeof(Sender); @@ -197,12 +193,14 @@ Socket::Status SocketUDP::Receive(char* Data, std::size_t MaxSize, std::size_t& if (Received > 0) { Address = IPAddress(inet_ntoa(Sender.sin_addr)); + Port = ntohs(Sender.sin_port); SizeReceived = static_cast(Received); return Socket::Done; } else { Address = IPAddress(); + Port = 0; return Received == 0 ? Socket::Disconnected : SocketHelper::GetErrorStatus(); } } @@ -244,7 +242,7 @@ Socket::Status SocketUDP::Send(Packet& PacketToSend, const IPAddress& Address, u /// Receive a packet. /// This function will block if the socket is blocking //////////////////////////////////////////////////////////// -Socket::Status SocketUDP::Receive(Packet& PacketToReceive, IPAddress& Address) +Socket::Status SocketUDP::Receive(Packet& PacketToReceive, IPAddress& Address, unsigned short& Port) { // This is not safe at all, as data can be lost, duplicated, or arrive in a different order. // So if a packet is split into more than one chunk, nobody knows what could happen... @@ -255,7 +253,7 @@ Socket::Status SocketUDP::Receive(Packet& PacketToReceive, IPAddress& Address) std::size_t Received = 0; if (myPendingPacketSize < 0) { - Socket::Status Status = Receive(reinterpret_cast(&PacketSize), sizeof(PacketSize), Received, Address); + Socket::Status Status = Receive(reinterpret_cast(&PacketSize), sizeof(PacketSize), Received, Address, Port); if (Status != Socket::Done) return Status; @@ -273,6 +271,7 @@ Socket::Status SocketUDP::Receive(Packet& PacketToReceive, IPAddress& Address) // Use another address instance for receiving the packet data ; // chunks of data coming from a different sender will be discarded (and lost...) IPAddress Sender; + unsigned short SenderPort; // Then loop until we receive all the packet data char Buffer[1024]; @@ -280,7 +279,7 @@ Socket::Status SocketUDP::Receive(Packet& PacketToReceive, IPAddress& Address) { // Receive a chunk of data std::size_t SizeToGet = std::min(static_cast(PacketSize - myPendingPacket.size()), sizeof(Buffer)); - Socket::Status Status = Receive(Buffer, SizeToGet, Received, Sender); + Socket::Status Status = Receive(Buffer, SizeToGet, Received, Sender, SenderPort); if (Status != Socket::Done) { // We must save the size of the pending packet until we can receive its content @@ -290,7 +289,7 @@ Socket::Status SocketUDP::Receive(Packet& PacketToReceive, IPAddress& Address) } // Append it into the packet - if ((Sender == Address) && (Received > 0)) + if ((Sender == Address) && (SenderPort == Port) && (Received > 0)) { myPendingPacket.resize(myPendingPacket.size() + Received); char* Begin = &myPendingPacket[0] + myPendingPacket.size() - Received; diff --git a/Externals/SFML/src/SFML/Network/Unix/SocketHelper.cpp b/Externals/SFML/src/SFML/Network/Unix/SocketHelper.cpp index 2a2e6b2cfc..16df524027 100644 --- a/Externals/SFML/src/SFML/Network/Unix/SocketHelper.cpp +++ b/Externals/SFML/src/SFML/Network/Unix/SocketHelper.cpp @@ -1,7 +1,7 @@ //////////////////////////////////////////////////////////// // // SFML - Simple and Fast Multimedia Library -// Copyright (C) 2007 Laurent Gomila (laurent.gom@gmail.com) +// Copyright (C) 2007-2009 Laurent Gomila (laurent.gom@gmail.com) // // This software is provided 'as-is', without any express or implied warranty. // In no event will the authors be held liable for any damages arising from the use of this software. @@ -68,6 +68,12 @@ void SocketHelper::SetBlocking(SocketHelper::SocketType Socket, bool Block) //////////////////////////////////////////////////////////// Socket::Status SocketHelper::GetErrorStatus() { + // The followings are sometimes equal to EWOULDBLOCK, + // so we have to make a special case for them in order + // to avoid having double values in the switch case + if ((errno == EAGAIN) || (errno == EINPROGRESS)) + return Socket::NotReady; + switch (errno) { case EWOULDBLOCK : return Socket::NotReady; diff --git a/Externals/SFML/src/SFML/Network/Win32/SocketHelper.cpp b/Externals/SFML/src/SFML/Network/Win32/SocketHelper.cpp index f3ddb0855e..e4389f2e88 100644 --- a/Externals/SFML/src/SFML/Network/Win32/SocketHelper.cpp +++ b/Externals/SFML/src/SFML/Network/Win32/SocketHelper.cpp @@ -1,7 +1,7 @@ //////////////////////////////////////////////////////////// // // SFML - Simple and Fast Multimedia Library -// Copyright (C) 2007-2008 Laurent Gomila (laurent.gom@gmail.com) +// Copyright (C) 2007-2009 Laurent Gomila (laurent.gom@gmail.com) // // This software is provided 'as-is', without any express or implied warranty. // In no event will the authors be held liable for any damages arising from the use of this software.