update to sfml 1.5

git-svn-id: https://dolphin-emu.googlecode.com/svn/trunk@3594 8ced0084-cf51-0410-be5f-012b33b47a6e
This commit is contained in:
Shawn Hoffman 2009-06-29 15:51:35 +00:00
parent 4b60442332
commit 466eb88ee6
25 changed files with 78 additions and 77 deletions

View File

@ -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

View File

@ -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.

View File

@ -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.

View File

@ -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 :

View File

@ -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 ==

View File

@ -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.

View File

@ -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.

View File

@ -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.

View File

@ -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.

View File

@ -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.

View File

@ -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.

View File

@ -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

View File

@ -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.

View File

@ -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.

View File

@ -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 <SFML/Config.hpp>
//#include <SFML/System/Clock.hpp>
//#include <SFML/System/Lock.hpp>
//#include <SFML/System/Mutex.hpp>
//#include <SFML/System/Randomizer.hpp>
//#include <SFML/System/Sleep.hpp>
//#include <SFML/System/Thread.hpp>
//#include <SFML/System/Unicode.hpp>
//#include <SFML/System/Vector2.hpp>
//#include <SFML/System/Vector3.hpp>
// #include <SFML/System/Clock.hpp>
// #include <SFML/System/Lock.hpp>
// #include <SFML/System/Mutex.hpp>
// #include <SFML/System/Randomizer.hpp>
// #include <SFML/System/Sleep.hpp>
// #include <SFML/System/Thread.hpp>
// #include <SFML/System/Unicode.hpp>
// #include <SFML/System/Vector2.hpp>
// #include <SFML/System/Vector3.hpp>
#endif // SFML_SYSTEM_HPP

View File

@ -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.

View File

@ -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.

View File

@ -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();

View File

@ -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();
}

View File

@ -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.

View File

@ -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.

View File

@ -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.

View File

@ -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<std::size_t>(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<char*>(&PacketSize), sizeof(PacketSize), Received, Address);
Socket::Status Status = Receive(reinterpret_cast<char*>(&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<std::size_t>(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;

View File

@ -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;

View File

@ -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.