mirror of
https://github.com/izzy2lost/dolphin.git
synced 2026-06-19 01:16:48 -07:00
Merge pull request #13276 from JoshuaVandaele/sfml-3.0.0
Migrate to SFML 3.0.0
This commit is contained in:
@@ -84,3 +84,6 @@
|
||||
[submodule "Externals/Vulkan-Headers"]
|
||||
path = Externals/Vulkan-Headers
|
||||
url = https://github.com/KhronosGroup/Vulkan-Headers.git
|
||||
[submodule "Externals/SFML/SFML"]
|
||||
path = Externals/SFML/SFML
|
||||
url = https://github.com/SFML/SFML.git
|
||||
|
||||
+11
-6
@@ -87,9 +87,10 @@ if(SFML_FIND_VERSION AND SFML_INCLUDE_DIR)
|
||||
set(SFML_CONFIG_HPP_INPUT "${SFML_INCLUDE_DIR}/SFML/Config.hpp")
|
||||
endif()
|
||||
FILE(READ "${SFML_CONFIG_HPP_INPUT}" SFML_CONFIG_HPP_CONTENTS)
|
||||
STRING(REGEX MATCH ".*#define SFML_VERSION_MAJOR ([0-9]+).*#define SFML_VERSION_MINOR ([0-9]+).*" SFML_CONFIG_HPP_CONTENTS "${SFML_CONFIG_HPP_CONTENTS}")
|
||||
STRING(REGEX REPLACE ".*#define SFML_VERSION_MAJOR ([0-9]+).*" "\\1" SFML_VERSION_MAJOR "${SFML_CONFIG_HPP_CONTENTS}")
|
||||
STRING(REGEX REPLACE ".*#define SFML_VERSION_MINOR ([0-9]+).*" "\\1" SFML_VERSION_MINOR "${SFML_CONFIG_HPP_CONTENTS}")
|
||||
STRING(REGEX MATCH "#define SFML_VERSION_MAJOR[ \t]+([0-9]+)" SFML_VERSION_MAJOR_MATCH "${SFML_CONFIG_HPP_CONTENTS}")
|
||||
STRING(REGEX MATCH "#define SFML_VERSION_MINOR[ \t]+([0-9]+)" SFML_VERSION_MINOR_MATCH "${SFML_CONFIG_HPP_CONTENTS}")
|
||||
STRING(REGEX REPLACE "#define SFML_VERSION_MAJOR[ \t]+([0-9]+)" "\\1" SFML_VERSION_MAJOR "${SFML_VERSION_MAJOR_MATCH}")
|
||||
STRING(REGEX REPLACE "#define SFML_VERSION_MINOR[ \t]+([0-9]+)" "\\1" SFML_VERSION_MINOR "${SFML_VERSION_MINOR_MATCH}")
|
||||
math(EXPR SFML_REQUESTED_VERSION "${SFML_FIND_VERSION_MAJOR} * 10 + ${SFML_FIND_VERSION_MINOR}")
|
||||
|
||||
# if we could extract them, compare with the requested version number
|
||||
@@ -102,10 +103,14 @@ if(SFML_FIND_VERSION AND SFML_INCLUDE_DIR)
|
||||
set(SFML_VERSION_OK FALSE)
|
||||
endif()
|
||||
else()
|
||||
# SFML version is < 2.0
|
||||
if (SFML_REQUESTED_VERSION GREATER 19)
|
||||
# SFML version is < 3.0
|
||||
if (SFML_REQUESTED_VERSION GREATER 29)
|
||||
set(SFML_VERSION_OK FALSE)
|
||||
set(SFML_VERSION_MAJOR 1)
|
||||
if (SFML_REQUESTED_VERSION GREATER 19)
|
||||
set(SFML_VERSION_MAJOR 1)
|
||||
else()
|
||||
set(SFML_VERSION_MAJOR 2)
|
||||
endif()
|
||||
set(SFML_VERSION_MINOR x)
|
||||
endif()
|
||||
endif()
|
||||
|
||||
+1
-1
@@ -713,7 +713,7 @@ if(NOT ANDROID)
|
||||
add_definitions(-D__LIBUSB__)
|
||||
endif()
|
||||
|
||||
dolphin_find_optional_system_library(SFML Externals/SFML 2.1 COMPONENTS network system)
|
||||
dolphin_find_optional_system_library(SFML Externals/SFML 3.0 COMPONENTS Network System)
|
||||
|
||||
if(USE_UPNP)
|
||||
dolphin_find_optional_system_library(MINIUPNPC Externals/miniupnpc 1.6)
|
||||
|
||||
Vendored
+19
-16
@@ -1,31 +1,34 @@
|
||||
set(SRC_NETWORK
|
||||
src/SFML/Network/Http.cpp
|
||||
src/SFML/Network/IPAddress.cpp
|
||||
src/SFML/Network/Packet.cpp
|
||||
src/SFML/Network/Socket.cpp
|
||||
src/SFML/Network/SocketSelector.cpp
|
||||
src/SFML/Network/TcpListener.cpp
|
||||
src/SFML/Network/TcpSocket.cpp
|
||||
src/SFML/Network/UdpSocket.cpp
|
||||
SFML/src/SFML/Network/Http.cpp
|
||||
SFML/src/SFML/Network/IpAddress.cpp
|
||||
SFML/src/SFML/Network/Packet.cpp
|
||||
SFML/src/SFML/Network/Socket.cpp
|
||||
SFML/src/SFML/Network/SocketSelector.cpp
|
||||
SFML/src/SFML/Network/TcpListener.cpp
|
||||
SFML/src/SFML/Network/TcpSocket.cpp
|
||||
SFML/src/SFML/Network/UdpSocket.cpp
|
||||
)
|
||||
|
||||
if(WIN32)
|
||||
list(APPEND SRC_NETWORK src/SFML/Network/Win32/SocketImpl.cpp)
|
||||
list(APPEND SRC_NETWORK SFML/src/SFML/Network/Win32/SocketImpl.cpp)
|
||||
else()
|
||||
list(APPEND SRC_NETWORK src/SFML/Network/Unix/SocketImpl.cpp)
|
||||
list(APPEND SRC_NETWORK SFML/src/SFML/Network/Unix/SocketImpl.cpp)
|
||||
endif()
|
||||
|
||||
set(SRC_SYSTEM
|
||||
src/SFML/System/Err.cpp
|
||||
src/SFML/System/String.cpp
|
||||
src/SFML/System/Time.cpp
|
||||
SFML/src/SFML/System/Err.cpp
|
||||
SFML/include/SFML/System/String.hpp
|
||||
SFML/src/SFML/System/String.cpp
|
||||
SFML/src/SFML/System/Utils.cpp
|
||||
)
|
||||
|
||||
add_library(sfml-network STATIC ${SRC_NETWORK})
|
||||
add_library(sfml-system STATIC ${SRC_SYSTEM})
|
||||
target_compile_features(sfml-network PUBLIC cxx_std_17)
|
||||
target_compile_features(sfml-system PUBLIC cxx_std_17)
|
||||
target_compile_definitions(sfml-system PUBLIC SFML_STATIC)
|
||||
target_include_directories(sfml-system PUBLIC include PRIVATE src)
|
||||
target_include_directories(sfml-network PUBLIC include PRIVATE src)
|
||||
target_include_directories(sfml-system PUBLIC SFML/include PRIVATE SFML/src)
|
||||
target_include_directories(sfml-network PUBLIC SFML/include PRIVATE SFML/src)
|
||||
target_link_libraries(sfml-network PUBLIC sfml-system)
|
||||
dolphin_disable_warnings(sfml-network)
|
||||
dolphin_disable_warnings(sfml-system)
|
||||
dolphin_disable_warnings(sfml-system)
|
||||
+1
Submodule Externals/SFML/SFML added at 7f1162dfea
Vendored
+67
@@ -0,0 +1,67 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project>
|
||||
<Import Project="..\..\Source\VSProps\Base.Macros.props" />
|
||||
<Import Project="$(VSPropsDir)Base.Targets.props" />
|
||||
<PropertyGroup Label="Globals">
|
||||
<ProjectGuid>{93D73454-2512-424E-9CDA-4BB357FE13DD}</ProjectGuid>
|
||||
</PropertyGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
|
||||
<Import Project="$(VSPropsDir)Configuration.StaticLibrary.props" />
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
|
||||
<ImportGroup Label="ExtensionSettings" />
|
||||
<ImportGroup Label="PropertySheets">
|
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props"
|
||||
Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')"
|
||||
Label="LocalAppDataPlatform" />
|
||||
<Import Project="$(VSPropsDir)Base.props" />
|
||||
<Import Project="$(VSPropsDir)ClDisableAllWarnings.props" />
|
||||
</ImportGroup>
|
||||
<PropertyGroup Label="UserMacros" />
|
||||
<ItemDefinitionGroup>
|
||||
<ClCompile>
|
||||
<AdditionalIncludeDirectories>SFML\include;SFML\src;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
|
||||
<PreprocessorDefinitions>SFML_STATIC;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
</ClCompile>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="SFML\src\SFML\Network\Http.cpp" />
|
||||
<ClCompile Include="SFML\src\SFML\Network\IpAddress.cpp" />
|
||||
<ClCompile Include="SFML\src\SFML\Network\Packet.cpp" />
|
||||
<ClCompile Include="SFML\src\SFML\Network\Socket.cpp" />
|
||||
<ClCompile Include="SFML\src\SFML\Network\SocketSelector.cpp" />
|
||||
<ClCompile Include="SFML\src\SFML\Network\TcpListener.cpp" />
|
||||
<ClCompile Include="SFML\src\SFML\Network\TcpSocket.cpp" />
|
||||
<ClCompile Include="SFML\src\SFML\Network\UdpSocket.cpp" />
|
||||
<ClCompile Include="SFML\src\SFML\Network\Win32\SocketImpl.cpp" />
|
||||
<ClCompile Include="SFML\src\SFML\System\Err.cpp" />
|
||||
<ClCompile Include="SFML\src\SFML\System\String.cpp" />
|
||||
<ClCompile Include="SFML\src\SFML\System\Utils.cpp" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="SFML\include\SFML\Config.hpp" />
|
||||
<ClInclude Include="SFML\include\SFML\Network.hpp" />
|
||||
<ClInclude Include="SFML\include\SFML\Network\Export.hpp" />
|
||||
<ClInclude Include="SFML\include\SFML\Network\Http.hpp" />
|
||||
<ClInclude Include="SFML\include\SFML\Network\IPAddress.hpp" />
|
||||
<ClInclude Include="SFML\include\SFML\Network\Packet.hpp" />
|
||||
<ClInclude Include="SFML\include\SFML\Network\Socket.hpp" />
|
||||
<ClInclude Include="SFML\include\SFML\Network\SocketHandle.hpp" />
|
||||
<ClInclude Include="SFML\include\SFML\Network\SocketSelector.hpp" />
|
||||
<ClInclude Include="SFML\include\SFML\Network\TcpListener.hpp" />
|
||||
<ClInclude Include="SFML\include\SFML\Network\TcpSocket.hpp" />
|
||||
<ClInclude Include="SFML\include\SFML\Network\UdpSocket.hpp" />
|
||||
<ClInclude Include="SFML\include\SFML\System.hpp" />
|
||||
<ClInclude Include="SFML\include\SFML\System\Err.hpp" />
|
||||
<ClInclude Include="SFML\include\SFML\System\Export.hpp" />
|
||||
<ClInclude Include="SFML\include\SFML\System\NonCopyable.hpp" />
|
||||
<ClInclude Include="SFML\include\SFML\System\String.hpp" />
|
||||
<ClInclude Include="SFML\include\SFML\System\String.inl" />
|
||||
<ClInclude Include="SFML\include\SFML\System\Utf.hpp" />
|
||||
<ClInclude Include="SFML\include\SFML\System\Utf.inl" />
|
||||
<ClInclude Include="SFML\src\SFML\Network\SocketImpl.hpp" />
|
||||
<ClInclude Include="SFML\src\SFML\Network\Win32\SocketImpl.hpp" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
|
||||
<ImportGroup Label="ExtensionTargets">
|
||||
</ImportGroup>
|
||||
</Project>
|
||||
@@ -1,66 +0,0 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project>
|
||||
<Import Project="..\..\..\..\Source\VSProps\Base.Macros.props" />
|
||||
<Import Project="$(VSPropsDir)Base.Targets.props" />
|
||||
<PropertyGroup Label="Globals">
|
||||
<ProjectGuid>{93D73454-2512-424E-9CDA-4BB357FE13DD}</ProjectGuid>
|
||||
</PropertyGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
|
||||
<Import Project="$(VSPropsDir)Configuration.StaticLibrary.props" />
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
|
||||
<ImportGroup Label="ExtensionSettings" />
|
||||
<ImportGroup Label="PropertySheets">
|
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||
<Import Project="$(VSPropsDir)Base.props" />
|
||||
<Import Project="$(VSPropsDir)ClDisableAllWarnings.props" />
|
||||
</ImportGroup>
|
||||
<PropertyGroup Label="UserMacros" />
|
||||
<ItemDefinitionGroup>
|
||||
<ClCompile>
|
||||
<AdditionalIncludeDirectories>..\..\include;..\..\src;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
|
||||
<PreprocessorDefinitions>SFML_STATIC;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
</ClCompile>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="..\..\src\SFML\Network\Http.cpp" />
|
||||
<ClCompile Include="..\..\src\SFML\Network\IPAddress.cpp" />
|
||||
<ClCompile Include="..\..\src\SFML\Network\Packet.cpp" />
|
||||
<ClCompile Include="..\..\src\SFML\Network\Socket.cpp" />
|
||||
<ClCompile Include="..\..\src\SFML\Network\SocketSelector.cpp" />
|
||||
<ClCompile Include="..\..\src\SFML\Network\TcpListener.cpp" />
|
||||
<ClCompile Include="..\..\src\SFML\Network\TcpSocket.cpp" />
|
||||
<ClCompile Include="..\..\src\SFML\Network\UdpSocket.cpp" />
|
||||
<ClCompile Include="..\..\src\SFML\Network\Win32\SocketImpl.cpp" />
|
||||
<ClCompile Include="..\..\src\SFML\System\Err.cpp" />
|
||||
<ClCompile Include="..\..\src\SFML\System\String.cpp" />
|
||||
<ClCompile Include="..\..\src\SFML\System\Time.cpp" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="..\..\include\SFML\Config.hpp" />
|
||||
<ClInclude Include="..\..\include\SFML\Network.hpp" />
|
||||
<ClInclude Include="..\..\include\SFML\Network\Export.hpp" />
|
||||
<ClInclude Include="..\..\include\SFML\Network\Http.hpp" />
|
||||
<ClInclude Include="..\..\include\SFML\Network\IPAddress.hpp" />
|
||||
<ClInclude Include="..\..\include\SFML\Network\Packet.hpp" />
|
||||
<ClInclude Include="..\..\include\SFML\Network\Socket.hpp" />
|
||||
<ClInclude Include="..\..\include\SFML\Network\SocketHandle.hpp" />
|
||||
<ClInclude Include="..\..\include\SFML\Network\SocketSelector.hpp" />
|
||||
<ClInclude Include="..\..\include\SFML\Network\TcpListener.hpp" />
|
||||
<ClInclude Include="..\..\include\SFML\Network\TcpSocket.hpp" />
|
||||
<ClInclude Include="..\..\include\SFML\Network\UdpSocket.hpp" />
|
||||
<ClInclude Include="..\..\include\SFML\System.hpp" />
|
||||
<ClInclude Include="..\..\include\SFML\System\Err.hpp" />
|
||||
<ClInclude Include="..\..\include\SFML\System\Export.hpp" />
|
||||
<ClInclude Include="..\..\include\SFML\System\NonCopyable.hpp" />
|
||||
<ClInclude Include="..\..\include\SFML\System\String.hpp" />
|
||||
<ClInclude Include="..\..\include\SFML\System\String.inl" />
|
||||
<ClInclude Include="..\..\include\SFML\System\Time.hpp" />
|
||||
<ClInclude Include="..\..\include\SFML\System\Utf.hpp" />
|
||||
<ClInclude Include="..\..\include\SFML\System\Utf.inl" />
|
||||
<ClInclude Include="..\..\src\SFML\Network\SocketImpl.hpp" />
|
||||
<ClInclude Include="..\..\src\SFML\Network\Win32\SocketImpl.hpp" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
|
||||
<ImportGroup Label="ExtensionTargets">
|
||||
</ImportGroup>
|
||||
</Project>
|
||||
@@ -1,51 +0,0 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="..\..\src\SFML\Network\Http.cpp" />
|
||||
<ClCompile Include="..\..\src\SFML\Network\IPAddress.cpp" />
|
||||
<ClCompile Include="..\..\src\SFML\Network\Packet.cpp" />
|
||||
<ClCompile Include="..\..\src\SFML\Network\Socket.cpp" />
|
||||
<ClCompile Include="..\..\src\SFML\Network\SocketSelector.cpp" />
|
||||
<ClCompile Include="..\..\src\SFML\Network\TcpListener.cpp" />
|
||||
<ClCompile Include="..\..\src\SFML\Network\TcpSocket.cpp" />
|
||||
<ClCompile Include="..\..\src\SFML\Network\UdpSocket.cpp" />
|
||||
<ClCompile Include="..\..\src\SFML\Network\Win32\SocketImpl.cpp">
|
||||
<Filter>Win32</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\..\src\SFML\System\Err.cpp" />
|
||||
<ClCompile Include="..\..\src\SFML\System\String.cpp" />
|
||||
<ClCompile Include="..\..\src\SFML\System\Time.cpp" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="..\..\include\SFML\Config.hpp" />
|
||||
<ClInclude Include="..\..\include\SFML\Network.hpp" />
|
||||
<ClInclude Include="..\..\include\SFML\Network\Export.hpp" />
|
||||
<ClInclude Include="..\..\include\SFML\Network\Http.hpp" />
|
||||
<ClInclude Include="..\..\include\SFML\Network\IPAddress.hpp" />
|
||||
<ClInclude Include="..\..\include\SFML\Network\Packet.hpp" />
|
||||
<ClInclude Include="..\..\include\SFML\Network\Socket.hpp" />
|
||||
<ClInclude Include="..\..\include\SFML\Network\SocketHandle.hpp" />
|
||||
<ClInclude Include="..\..\include\SFML\Network\SocketSelector.hpp" />
|
||||
<ClInclude Include="..\..\include\SFML\Network\TcpListener.hpp" />
|
||||
<ClInclude Include="..\..\include\SFML\Network\TcpSocket.hpp" />
|
||||
<ClInclude Include="..\..\include\SFML\Network\UdpSocket.hpp" />
|
||||
<ClInclude Include="..\..\include\SFML\System.hpp" />
|
||||
<ClInclude Include="..\..\include\SFML\System\Err.hpp" />
|
||||
<ClInclude Include="..\..\include\SFML\System\Export.hpp" />
|
||||
<ClInclude Include="..\..\include\SFML\System\NonCopyable.hpp" />
|
||||
<ClInclude Include="..\..\include\SFML\System\String.hpp" />
|
||||
<ClInclude Include="..\..\include\SFML\System\String.inl" />
|
||||
<ClInclude Include="..\..\include\SFML\System\Time.hpp" />
|
||||
<ClInclude Include="..\..\include\SFML\System\Utf.hpp" />
|
||||
<ClInclude Include="..\..\include\SFML\System\Utf.inl" />
|
||||
<ClInclude Include="..\..\src\SFML\Network\SocketImpl.hpp" />
|
||||
<ClInclude Include="..\..\src\SFML\Network\Win32\SocketImpl.hpp">
|
||||
<Filter>Win32</Filter>
|
||||
</ClInclude>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Filter Include="Win32">
|
||||
<UniqueIdentifier>{8280ecca-24fc-48a2-b7f5-6aca41826b66}</UniqueIdentifier>
|
||||
</Filter>
|
||||
</ItemGroup>
|
||||
</Project>
|
||||
Vendored
+3
-3
@@ -2,13 +2,13 @@
|
||||
<Project>
|
||||
<ItemDefinitionGroup>
|
||||
<ClCompile>
|
||||
<AdditionalIncludeDirectories>$(ExternalsDir)SFML\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
|
||||
<AdditionalIncludeDirectories>$(ExternalsDir)SFML\SFML\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
|
||||
<PreprocessorDefinitions>SFML_STATIC;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
</ClCompile>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="$(ExternalsDir)SFML\build\vc2010\SFML_Network.vcxproj">
|
||||
<ProjectReference Include="$(ExternalsDir)SFML\SFML.vcxproj">
|
||||
<Project>{93d73454-2512-424e-9cda-4bb357fe13dd}</Project>
|
||||
</ProjectReference>
|
||||
</ItemGroup>
|
||||
</Project>
|
||||
</Project>
|
||||
-236
@@ -1,236 +0,0 @@
|
||||
////////////////////////////////////////////////////////////
|
||||
//
|
||||
// SFML - Simple and Fast Multimedia Library
|
||||
// Copyright (C) 2007-2018 Laurent Gomila (laurent@sfml-dev.org)
|
||||
//
|
||||
// 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.
|
||||
//
|
||||
// Permission is granted to anyone to use this software for any purpose,
|
||||
// including commercial applications, and to alter it and redistribute it freely,
|
||||
// subject to the following restrictions:
|
||||
//
|
||||
// 1. The origin of this software must not be misrepresented;
|
||||
// you must not claim that you wrote the original software.
|
||||
// If you use this software in a product, an acknowledgment
|
||||
// in the product documentation would be appreciated but is not required.
|
||||
//
|
||||
// 2. Altered source versions must be plainly marked as such,
|
||||
// and must not be misrepresented as being the original software.
|
||||
//
|
||||
// 3. This notice may not be removed or altered from any source distribution.
|
||||
//
|
||||
////////////////////////////////////////////////////////////
|
||||
|
||||
#ifndef SFML_CONFIG_HPP
|
||||
#define SFML_CONFIG_HPP
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
// Define the SFML version
|
||||
////////////////////////////////////////////////////////////
|
||||
#define SFML_VERSION_MAJOR 2
|
||||
#define SFML_VERSION_MINOR 5
|
||||
#define SFML_VERSION_PATCH 0
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
// Identify the operating system
|
||||
// see http://nadeausoftware.com/articles/2012/01/c_c_tip_how_use_compiler_predefined_macros_detect_operating_system
|
||||
////////////////////////////////////////////////////////////
|
||||
#if defined(_WIN32)
|
||||
|
||||
// Windows
|
||||
#define SFML_SYSTEM_WINDOWS
|
||||
#ifndef NOMINMAX
|
||||
#define NOMINMAX
|
||||
#endif
|
||||
|
||||
#elif defined(__APPLE__) && defined(__MACH__)
|
||||
|
||||
// Apple platform, see which one it is
|
||||
#include "TargetConditionals.h"
|
||||
|
||||
#if TARGET_OS_IPHONE || TARGET_IPHONE_SIMULATOR
|
||||
|
||||
// iOS
|
||||
#define SFML_SYSTEM_IOS
|
||||
|
||||
#elif TARGET_OS_MAC
|
||||
|
||||
// MacOS
|
||||
#define SFML_SYSTEM_MACOS
|
||||
|
||||
#else
|
||||
|
||||
// Unsupported Apple system
|
||||
#error This Apple operating system is not supported by SFML library
|
||||
|
||||
#endif
|
||||
|
||||
#elif defined(__unix__)
|
||||
|
||||
// UNIX system, see which one it is
|
||||
#if defined(__ANDROID__)
|
||||
|
||||
// Android
|
||||
#define SFML_SYSTEM_ANDROID
|
||||
|
||||
#elif defined(__linux__)
|
||||
|
||||
// Linux
|
||||
#define SFML_SYSTEM_LINUX
|
||||
|
||||
#elif defined(__FreeBSD__) || defined(__FreeBSD_kernel__)
|
||||
|
||||
// FreeBSD
|
||||
#define SFML_SYSTEM_FREEBSD
|
||||
|
||||
#elif defined(__OpenBSD__)
|
||||
|
||||
// OpenBSD
|
||||
#define SFML_SYSTEM_OPENBSD
|
||||
|
||||
#else
|
||||
|
||||
// Unsupported UNIX system
|
||||
#error This UNIX operating system is not supported by SFML library
|
||||
|
||||
#endif
|
||||
|
||||
#else
|
||||
|
||||
// Unsupported system
|
||||
#error This operating system is not supported by SFML library
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
// Define a portable debug macro
|
||||
////////////////////////////////////////////////////////////
|
||||
#if !defined(NDEBUG)
|
||||
|
||||
#define SFML_DEBUG
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
// Define helpers to create portable import / export macros for each module
|
||||
////////////////////////////////////////////////////////////
|
||||
#if !defined(SFML_STATIC)
|
||||
|
||||
#if defined(SFML_SYSTEM_WINDOWS)
|
||||
|
||||
// Windows compilers need specific (and different) keywords for export and import
|
||||
#define SFML_API_EXPORT __declspec(dllexport)
|
||||
#define SFML_API_IMPORT __declspec(dllimport)
|
||||
|
||||
// For Visual C++ compilers, we also need to turn off this annoying C4251 warning
|
||||
#ifdef _MSC_VER
|
||||
|
||||
#pragma warning(disable: 4251)
|
||||
|
||||
#endif
|
||||
|
||||
#else // Linux, FreeBSD, Mac OS X
|
||||
|
||||
#if __GNUC__ >= 4
|
||||
|
||||
// GCC 4 has special keywords for showing/hidding symbols,
|
||||
// the same keyword is used for both importing and exporting
|
||||
#define SFML_API_EXPORT __attribute__ ((__visibility__ ("default")))
|
||||
#define SFML_API_IMPORT __attribute__ ((__visibility__ ("default")))
|
||||
|
||||
#else
|
||||
|
||||
// GCC < 4 has no mechanism to explicitely hide symbols, everything's exported
|
||||
#define SFML_API_EXPORT
|
||||
#define SFML_API_IMPORT
|
||||
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
#else
|
||||
|
||||
// Static build doesn't need import/export macros
|
||||
#define SFML_API_EXPORT
|
||||
#define SFML_API_IMPORT
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
// Cross-platform warning for deprecated functions and classes
|
||||
//
|
||||
// Usage:
|
||||
// class SFML_DEPRECATED MyClass
|
||||
// {
|
||||
// SFML_DEPRECATED void memberFunc();
|
||||
// };
|
||||
//
|
||||
// SFML_DEPRECATED void globalFunc();
|
||||
////////////////////////////////////////////////////////////
|
||||
#if defined(SFML_NO_DEPRECATED_WARNINGS)
|
||||
|
||||
// User explicitly requests to disable deprecation warnings
|
||||
#define SFML_DEPRECATED
|
||||
|
||||
#elif defined(_MSC_VER)
|
||||
|
||||
// Microsoft C++ compiler
|
||||
// Note: On newer MSVC versions, using deprecated functions causes a compiler error. In order to
|
||||
// trigger a warning instead of an error, the compiler flag /sdl- (instead of /sdl) must be specified.
|
||||
#define SFML_DEPRECATED __declspec(deprecated)
|
||||
|
||||
#elif defined(__GNUC__)
|
||||
|
||||
// g++ and Clang
|
||||
#define SFML_DEPRECATED __attribute__ ((deprecated))
|
||||
|
||||
#else
|
||||
|
||||
// Other compilers are not supported, leave class or function as-is.
|
||||
// With a bit of luck, the #pragma directive works, otherwise users get a warning (no error!) for unrecognized #pragma.
|
||||
#pragma message("SFML_DEPRECATED is not supported for your compiler, please contact the SFML team")
|
||||
#define SFML_DEPRECATED
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
// Define portable fixed-size types
|
||||
////////////////////////////////////////////////////////////
|
||||
namespace sf
|
||||
{
|
||||
// All "common" platforms use the same size for char, short and int
|
||||
// (basically there are 3 types for 3 sizes, so no other match is possible),
|
||||
// we can use them without doing any kind of check
|
||||
|
||||
// 8 bits integer types
|
||||
typedef signed char Int8;
|
||||
typedef unsigned char Uint8;
|
||||
|
||||
// 16 bits integer types
|
||||
typedef signed short Int16;
|
||||
typedef unsigned short Uint16;
|
||||
|
||||
// 32 bits integer types
|
||||
typedef signed int Int32;
|
||||
typedef unsigned int Uint32;
|
||||
|
||||
// 64 bits integer types
|
||||
#if defined(_MSC_VER)
|
||||
typedef signed __int64 Int64;
|
||||
typedef unsigned __int64 Uint64;
|
||||
#else
|
||||
typedef signed long long Int64;
|
||||
typedef unsigned long long Uint64;
|
||||
#endif
|
||||
|
||||
} // namespace sf
|
||||
|
||||
|
||||
#endif // SFML_CONFIG_HPP
|
||||
-55
@@ -1,55 +0,0 @@
|
||||
////////////////////////////////////////////////////////////
|
||||
//
|
||||
// SFML - Simple and Fast Multimedia Library
|
||||
// Copyright (C) 2007-2018 Laurent Gomila (laurent@sfml-dev.org)
|
||||
//
|
||||
// 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.
|
||||
//
|
||||
// Permission is granted to anyone to use this software for any purpose,
|
||||
// including commercial applications, and to alter it and redistribute it freely,
|
||||
// subject to the following restrictions:
|
||||
//
|
||||
// 1. The origin of this software must not be misrepresented;
|
||||
// you must not claim that you wrote the original software.
|
||||
// If you use this software in a product, an acknowledgment
|
||||
// in the product documentation would be appreciated but is not required.
|
||||
//
|
||||
// 2. Altered source versions must be plainly marked as such,
|
||||
// and must not be misrepresented as being the original software.
|
||||
//
|
||||
// 3. This notice may not be removed or altered from any source distribution.
|
||||
//
|
||||
////////////////////////////////////////////////////////////
|
||||
|
||||
#ifndef SFML_NETWORK_HPP
|
||||
#define SFML_NETWORK_HPP
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
// Headers
|
||||
////////////////////////////////////////////////////////////
|
||||
|
||||
#include <SFML/System.hpp>
|
||||
//#include <SFML/Network/Ftp.hpp>
|
||||
#include <SFML/Network/Http.hpp>
|
||||
|
||||
// This file is "IpAddress.hpp" upstream
|
||||
#include <SFML/Network/IPAddress.hpp>
|
||||
#include <SFML/Network/Packet.hpp>
|
||||
#include <SFML/Network/Socket.hpp>
|
||||
#include <SFML/Network/SocketHandle.hpp>
|
||||
#include <SFML/Network/SocketSelector.hpp>
|
||||
#include <SFML/Network/TcpListener.hpp>
|
||||
#include <SFML/Network/TcpSocket.hpp>
|
||||
#include <SFML/Network/UdpSocket.hpp>
|
||||
|
||||
|
||||
#endif // SFML_NETWORK_HPP
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \defgroup network Network module
|
||||
///
|
||||
/// Socket-based communication, utilities and higher-level
|
||||
/// network protocols (HTTP, FTP).
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
-48
@@ -1,48 +0,0 @@
|
||||
////////////////////////////////////////////////////////////
|
||||
//
|
||||
// SFML - Simple and Fast Multimedia Library
|
||||
// Copyright (C) 2007-2018 Laurent Gomila (laurent@sfml-dev.org)
|
||||
//
|
||||
// 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.
|
||||
//
|
||||
// Permission is granted to anyone to use this software for any purpose,
|
||||
// including commercial applications, and to alter it and redistribute it freely,
|
||||
// subject to the following restrictions:
|
||||
//
|
||||
// 1. The origin of this software must not be misrepresented;
|
||||
// you must not claim that you wrote the original software.
|
||||
// If you use this software in a product, an acknowledgment
|
||||
// in the product documentation would be appreciated but is not required.
|
||||
//
|
||||
// 2. Altered source versions must be plainly marked as such,
|
||||
// and must not be misrepresented as being the original software.
|
||||
//
|
||||
// 3. This notice may not be removed or altered from any source distribution.
|
||||
//
|
||||
////////////////////////////////////////////////////////////
|
||||
|
||||
#ifndef SFML_NETWORK_EXPORT_HPP
|
||||
#define SFML_NETWORK_EXPORT_HPP
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
// Headers
|
||||
////////////////////////////////////////////////////////////
|
||||
#include <SFML/Config.hpp>
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
// Define portable import / export macros
|
||||
////////////////////////////////////////////////////////////
|
||||
#if defined(SFML_NETWORK_EXPORTS)
|
||||
|
||||
#define SFML_NETWORK_API SFML_API_EXPORT
|
||||
|
||||
#else
|
||||
|
||||
#define SFML_NETWORK_API SFML_API_IMPORT
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
#endif // SFML_NETWORK_EXPORT_HPP
|
||||
-482
@@ -1,482 +0,0 @@
|
||||
////////////////////////////////////////////////////////////
|
||||
//
|
||||
// SFML - Simple and Fast Multimedia Library
|
||||
// Copyright (C) 2007-2018 Laurent Gomila (laurent@sfml-dev.org)
|
||||
//
|
||||
// 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.
|
||||
//
|
||||
// Permission is granted to anyone to use this software for any purpose,
|
||||
// including commercial applications, and to alter it and redistribute it freely,
|
||||
// subject to the following restrictions:
|
||||
//
|
||||
// 1. The origin of this software must not be misrepresented;
|
||||
// you must not claim that you wrote the original software.
|
||||
// If you use this software in a product, an acknowledgment
|
||||
// in the product documentation would be appreciated but is not required.
|
||||
//
|
||||
// 2. Altered source versions must be plainly marked as such,
|
||||
// and must not be misrepresented as being the original software.
|
||||
//
|
||||
// 3. This notice may not be removed or altered from any source distribution.
|
||||
//
|
||||
////////////////////////////////////////////////////////////
|
||||
|
||||
#ifndef SFML_HTTP_HPP
|
||||
#define SFML_HTTP_HPP
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
// Headers
|
||||
////////////////////////////////////////////////////////////
|
||||
#include <SFML/Network/Export.hpp>
|
||||
#include <SFML/Network/IPAddress.hpp>
|
||||
#include <SFML/Network/TcpSocket.hpp>
|
||||
#include <SFML/System/NonCopyable.hpp>
|
||||
#include <SFML/System/Time.hpp>
|
||||
#include <map>
|
||||
#include <string>
|
||||
|
||||
|
||||
namespace sf
|
||||
{
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief A HTTP client
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
class SFML_NETWORK_API Http : NonCopyable
|
||||
{
|
||||
public:
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Define a HTTP request
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
class SFML_NETWORK_API Request
|
||||
{
|
||||
public:
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Enumerate the available HTTP methods for a request
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
enum Method
|
||||
{
|
||||
Get, ///< Request in get mode, standard method to retrieve a page
|
||||
Post, ///< Request in post mode, usually to send data to a page
|
||||
Head, ///< Request a page's header only
|
||||
Put, ///< Request in put mode, useful for a REST API
|
||||
Delete ///< Request in delete mode, useful for a REST API
|
||||
};
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Default constructor
|
||||
///
|
||||
/// This constructor creates a GET request, with the root
|
||||
/// URI ("/") and an empty body.
|
||||
///
|
||||
/// \param uri Target URI
|
||||
/// \param method Method to use for the request
|
||||
/// \param body Content of the request's body
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
Request(const std::string& uri = "/", Method method = Get, const std::string& body = "");
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Set the value of a field
|
||||
///
|
||||
/// The field is created if it doesn't exist. The name of
|
||||
/// the field is case-insensitive.
|
||||
/// By default, a request doesn't contain any field (but the
|
||||
/// mandatory fields are added later by the HTTP client when
|
||||
/// sending the request).
|
||||
///
|
||||
/// \param field Name of the field to set
|
||||
/// \param value Value of the field
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
void setField(const std::string& field, const std::string& value);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Set the request method
|
||||
///
|
||||
/// See the Method enumeration for a complete list of all
|
||||
/// the availale methods.
|
||||
/// The method is Http::Request::Get by default.
|
||||
///
|
||||
/// \param method Method to use for the request
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
void setMethod(Method method);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Set the requested URI
|
||||
///
|
||||
/// The URI is the resource (usually a web page or a file)
|
||||
/// that you want to get or post.
|
||||
/// The URI is "/" (the root page) by default.
|
||||
///
|
||||
/// \param uri URI to request, relative to the host
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
void setUri(const std::string& uri);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Set the HTTP version for the request
|
||||
///
|
||||
/// The HTTP version is 1.0 by default.
|
||||
///
|
||||
/// \param major Major HTTP version number
|
||||
/// \param minor Minor HTTP version number
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
void setHttpVersion(unsigned int major, unsigned int minor);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Set the body of the request
|
||||
///
|
||||
/// The body of a request is optional and only makes sense
|
||||
/// for POST requests. It is ignored for all other methods.
|
||||
/// The body is empty by default.
|
||||
///
|
||||
/// \param body Content of the body
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
void setBody(const std::string& body);
|
||||
|
||||
private:
|
||||
|
||||
friend class Http;
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Prepare the final request to send to the server
|
||||
///
|
||||
/// This is used internally by Http before sending the
|
||||
/// request to the web server.
|
||||
///
|
||||
/// \return String containing the request, ready to be sent
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
std::string prepare() const;
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Check if the request defines a field
|
||||
///
|
||||
/// This function uses case-insensitive comparisons.
|
||||
///
|
||||
/// \param field Name of the field to test
|
||||
///
|
||||
/// \return True if the field exists, false otherwise
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
bool hasField(const std::string& field) const;
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
// Types
|
||||
////////////////////////////////////////////////////////////
|
||||
typedef std::map<std::string, std::string> FieldTable;
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
// Member data
|
||||
////////////////////////////////////////////////////////////
|
||||
FieldTable m_fields; ///< Fields of the header associated to their value
|
||||
Method m_method; ///< Method to use for the request
|
||||
std::string m_uri; ///< Target URI of the request
|
||||
unsigned int m_majorVersion; ///< Major HTTP version
|
||||
unsigned int m_minorVersion; ///< Minor HTTP version
|
||||
std::string m_body; ///< Body of the request
|
||||
};
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Define a HTTP response
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
class SFML_NETWORK_API Response
|
||||
{
|
||||
public:
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Enumerate all the valid status codes for a response
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
enum Status
|
||||
{
|
||||
// 2xx: success
|
||||
Ok = 200, ///< Most common code returned when operation was successful
|
||||
Created = 201, ///< The resource has successfully been created
|
||||
Accepted = 202, ///< The request has been accepted, but will be processed later by the server
|
||||
NoContent = 204, ///< The server didn't send any data in return
|
||||
ResetContent = 205, ///< The server informs the client that it should clear the view (form) that caused the request to be sent
|
||||
PartialContent = 206, ///< The server has sent a part of the resource, as a response to a partial GET request
|
||||
|
||||
// 3xx: redirection
|
||||
MultipleChoices = 300, ///< The requested page can be accessed from several locations
|
||||
MovedPermanently = 301, ///< The requested page has permanently moved to a new location
|
||||
MovedTemporarily = 302, ///< The requested page has temporarily moved to a new location
|
||||
NotModified = 304, ///< For conditional requests, means the requested page hasn't changed and doesn't need to be refreshed
|
||||
|
||||
// 4xx: client error
|
||||
BadRequest = 400, ///< The server couldn't understand the request (syntax error)
|
||||
Unauthorized = 401, ///< The requested page needs an authentication to be accessed
|
||||
Forbidden = 403, ///< The requested page cannot be accessed at all, even with authentication
|
||||
NotFound = 404, ///< The requested page doesn't exist
|
||||
RangeNotSatisfiable = 407, ///< The server can't satisfy the partial GET request (with a "Range" header field)
|
||||
|
||||
// 5xx: server error
|
||||
InternalServerError = 500, ///< The server encountered an unexpected error
|
||||
NotImplemented = 501, ///< The server doesn't implement a requested feature
|
||||
BadGateway = 502, ///< The gateway server has received an error from the source server
|
||||
ServiceNotAvailable = 503, ///< The server is temporarily unavailable (overloaded, in maintenance, ...)
|
||||
GatewayTimeout = 504, ///< The gateway server couldn't receive a response from the source server
|
||||
VersionNotSupported = 505, ///< The server doesn't support the requested HTTP version
|
||||
|
||||
// 10xx: SFML custom codes
|
||||
InvalidResponse = 1000, ///< Response is not a valid HTTP one
|
||||
ConnectionFailed = 1001 ///< Connection with server failed
|
||||
};
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Default constructor
|
||||
///
|
||||
/// Constructs an empty response.
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
Response();
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Get the value of a field
|
||||
///
|
||||
/// If the field \a field is not found in the response header,
|
||||
/// the empty string is returned. This function uses
|
||||
/// case-insensitive comparisons.
|
||||
///
|
||||
/// \param field Name of the field to get
|
||||
///
|
||||
/// \return Value of the field, or empty string if not found
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
const std::string& getField(const std::string& field) const;
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Get the response status code
|
||||
///
|
||||
/// The status code should be the first thing to be checked
|
||||
/// after receiving a response, it defines whether it is a
|
||||
/// success, a failure or anything else (see the Status
|
||||
/// enumeration).
|
||||
///
|
||||
/// \return Status code of the response
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
Status getStatus() const;
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Get the major HTTP version number of the response
|
||||
///
|
||||
/// \return Major HTTP version number
|
||||
///
|
||||
/// \see getMinorHttpVersion
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
unsigned int getMajorHttpVersion() const;
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Get the minor HTTP version number of the response
|
||||
///
|
||||
/// \return Minor HTTP version number
|
||||
///
|
||||
/// \see getMajorHttpVersion
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
unsigned int getMinorHttpVersion() const;
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Get the body of the response
|
||||
///
|
||||
/// The body of a response may contain:
|
||||
/// \li the requested page (for GET requests)
|
||||
/// \li a response from the server (for POST requests)
|
||||
/// \li nothing (for HEAD requests)
|
||||
/// \li an error message (in case of an error)
|
||||
///
|
||||
/// \return The response body
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
const std::string& getBody() const;
|
||||
|
||||
private:
|
||||
|
||||
friend class Http;
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Construct the header from a response string
|
||||
///
|
||||
/// This function is used by Http to build the response
|
||||
/// of a request.
|
||||
///
|
||||
/// \param data Content of the response to parse
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
void parse(const std::string& data);
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Read values passed in the answer header
|
||||
///
|
||||
/// This function is used by Http to extract values passed
|
||||
/// in the response.
|
||||
///
|
||||
/// \param in String stream containing the header values
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
void parseFields(std::istream &in);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
// Types
|
||||
////////////////////////////////////////////////////////////
|
||||
typedef std::map<std::string, std::string> FieldTable;
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
// Member data
|
||||
////////////////////////////////////////////////////////////
|
||||
FieldTable m_fields; ///< Fields of the header
|
||||
Status m_status; ///< Status code
|
||||
unsigned int m_majorVersion; ///< Major HTTP version
|
||||
unsigned int m_minorVersion; ///< Minor HTTP version
|
||||
std::string m_body; ///< Body of the response
|
||||
};
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Default constructor
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
Http();
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Construct the HTTP client with the target host
|
||||
///
|
||||
/// This is equivalent to calling setHost(host, port).
|
||||
/// The port has a default value of 0, which means that the
|
||||
/// HTTP client will use the right port according to the
|
||||
/// protocol used (80 for HTTP). You should leave it like
|
||||
/// this unless you really need a port other than the
|
||||
/// standard one, or use an unknown protocol.
|
||||
///
|
||||
/// \param host Web server to connect to
|
||||
/// \param port Port to use for connection
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
Http(const std::string& host, unsigned short port = 0);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Set the target host
|
||||
///
|
||||
/// This function just stores the host address and port, it
|
||||
/// doesn't actually connect to it until you send a request.
|
||||
/// The port has a default value of 0, which means that the
|
||||
/// HTTP client will use the right port according to the
|
||||
/// protocol used (80 for HTTP). You should leave it like
|
||||
/// this unless you really need a port other than the
|
||||
/// standard one, or use an unknown protocol.
|
||||
///
|
||||
/// \param host Web server to connect to
|
||||
/// \param port Port to use for connection
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
void setHost(const std::string& host, unsigned short port = 0);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Send a HTTP request and return the server's response.
|
||||
///
|
||||
/// You must have a valid host before sending a request (see setHost).
|
||||
/// Any missing mandatory header field in the request will be added
|
||||
/// with an appropriate value.
|
||||
/// Warning: this function waits for the server's response and may
|
||||
/// not return instantly; use a thread if you don't want to block your
|
||||
/// application, or use a timeout to limit the time to wait. A value
|
||||
/// of Time::Zero means that the client will use the system default timeout
|
||||
/// (which is usually pretty long).
|
||||
///
|
||||
/// \param request Request to send
|
||||
/// \param timeout Maximum time to wait
|
||||
///
|
||||
/// \return Server's response
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
Response sendRequest(const Request& request, Time timeout = Time::Zero);
|
||||
|
||||
private:
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
// Member data
|
||||
////////////////////////////////////////////////////////////
|
||||
TcpSocket m_connection; ///< Connection to the host
|
||||
IpAddress m_host; ///< Web host address
|
||||
std::string m_hostName; ///< Web host name
|
||||
unsigned short m_port; ///< Port used for connection with host
|
||||
};
|
||||
|
||||
} // namespace sf
|
||||
|
||||
|
||||
#endif // SFML_HTTP_HPP
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \class sf::Http
|
||||
/// \ingroup network
|
||||
///
|
||||
/// sf::Http is a very simple HTTP client that allows you
|
||||
/// to communicate with a web server. You can retrieve
|
||||
/// web pages, send data to an interactive resource,
|
||||
/// download a remote file, etc. The HTTPS protocol is
|
||||
/// not supported.
|
||||
///
|
||||
/// The HTTP client is split into 3 classes:
|
||||
/// \li sf::Http::Request
|
||||
/// \li sf::Http::Response
|
||||
/// \li sf::Http
|
||||
///
|
||||
/// sf::Http::Request builds the request that will be
|
||||
/// sent to the server. A request is made of:
|
||||
/// \li a method (what you want to do)
|
||||
/// \li a target URI (usually the name of the web page or file)
|
||||
/// \li one or more header fields (options that you can pass to the server)
|
||||
/// \li an optional body (for POST requests)
|
||||
///
|
||||
/// sf::Http::Response parse the response from the web server
|
||||
/// and provides getters to read them. The response contains:
|
||||
/// \li a status code
|
||||
/// \li header fields (that may be answers to the ones that you requested)
|
||||
/// \li a body, which contains the contents of the requested resource
|
||||
///
|
||||
/// sf::Http provides a simple function, SendRequest, to send a
|
||||
/// sf::Http::Request and return the corresponding sf::Http::Response
|
||||
/// from the server.
|
||||
///
|
||||
/// Usage example:
|
||||
/// \code
|
||||
/// // Create a new HTTP client
|
||||
/// sf::Http http;
|
||||
///
|
||||
/// // We'll work on http://www.sfml-dev.org
|
||||
/// http.setHost("http://www.sfml-dev.org");
|
||||
///
|
||||
/// // Prepare a request to get the 'features.php' page
|
||||
/// sf::Http::Request request("features.php");
|
||||
///
|
||||
/// // Send the request
|
||||
/// sf::Http::Response response = http.sendRequest(request);
|
||||
///
|
||||
/// // Check the status code and display the result
|
||||
/// sf::Http::Response::Status status = response.getStatus();
|
||||
/// if (status == sf::Http::Response::Ok)
|
||||
/// {
|
||||
/// std::cout << response.getBody() << std::endl;
|
||||
/// }
|
||||
/// else
|
||||
/// {
|
||||
/// std::cout << "Error " << status << std::endl;
|
||||
/// }
|
||||
/// \endcode
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
-328
@@ -1,328 +0,0 @@
|
||||
////////////////////////////////////////////////////////////
|
||||
//
|
||||
// SFML - Simple and Fast Multimedia Library
|
||||
// Copyright (C) 2007-2018 Laurent Gomila (laurent@sfml-dev.org)
|
||||
//
|
||||
// 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.
|
||||
//
|
||||
// Permission is granted to anyone to use this software for any purpose,
|
||||
// including commercial applications, and to alter it and redistribute it freely,
|
||||
// subject to the following restrictions:
|
||||
//
|
||||
// 1. The origin of this software must not be misrepresented;
|
||||
// you must not claim that you wrote the original software.
|
||||
// If you use this software in a product, an acknowledgment
|
||||
// in the product documentation would be appreciated but is not required.
|
||||
//
|
||||
// 2. Altered source versions must be plainly marked as such,
|
||||
// and must not be misrepresented as being the original software.
|
||||
//
|
||||
// 3. This notice may not be removed or altered from any source distribution.
|
||||
//
|
||||
////////////////////////////////////////////////////////////
|
||||
|
||||
#ifndef SFML_IPADDRESS_HPP
|
||||
#define SFML_IPADDRESS_HPP
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
// Headers
|
||||
////////////////////////////////////////////////////////////
|
||||
#include <SFML/Network/Export.hpp>
|
||||
#include <SFML/System/Time.hpp>
|
||||
#include <istream>
|
||||
#include <ostream>
|
||||
#include <string>
|
||||
|
||||
|
||||
namespace sf
|
||||
{
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Encapsulate an IPv4 network address
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
class SFML_NETWORK_API IpAddress
|
||||
{
|
||||
public:
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Default constructor
|
||||
///
|
||||
/// This constructor creates an empty (invalid) address
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
IpAddress();
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Construct the address from a string
|
||||
///
|
||||
/// Here \a address can be either a decimal address
|
||||
/// (ex: "192.168.1.56") or a network name (ex: "localhost").
|
||||
///
|
||||
/// \param address IP address or network name
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
IpAddress(const std::string& address);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Construct the address from a string
|
||||
///
|
||||
/// Here \a address can be either a decimal address
|
||||
/// (ex: "192.168.1.56") or a network name (ex: "localhost").
|
||||
/// This is equivalent to the constructor taking a std::string
|
||||
/// parameter, it is defined for convenience so that the
|
||||
/// implicit conversions from literal strings to IpAddress work.
|
||||
///
|
||||
/// \param address IP address or network name
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
IpAddress(const char* address);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Construct the address from 4 bytes
|
||||
///
|
||||
/// Calling IpAddress(a, b, c, d) is equivalent to calling
|
||||
/// IpAddress("a.b.c.d"), but safer as it doesn't have to
|
||||
/// parse a string to get the address components.
|
||||
///
|
||||
/// \param byte0 First byte of the address
|
||||
/// \param byte1 Second byte of the address
|
||||
/// \param byte2 Third byte of the address
|
||||
/// \param byte3 Fourth byte of the address
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
IpAddress(Uint8 byte0, Uint8 byte1, Uint8 byte2, Uint8 byte3);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Construct the address from a 32-bits integer
|
||||
///
|
||||
/// This constructor uses the internal representation of
|
||||
/// the address directly. It should be used for optimization
|
||||
/// purposes, and only if you got that representation from
|
||||
/// IpAddress::toInteger().
|
||||
///
|
||||
/// \param address 4 bytes of the address packed into a 32-bits integer
|
||||
///
|
||||
/// \see toInteger
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
explicit IpAddress(Uint32 address);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Get a string representation of the address
|
||||
///
|
||||
/// The returned string is the decimal representation of the
|
||||
/// IP address (like "192.168.1.56"), even if it was constructed
|
||||
/// from a host name.
|
||||
///
|
||||
/// \return String representation of the address
|
||||
///
|
||||
/// \see toInteger
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
std::string toString() const;
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Get an integer representation of the address
|
||||
///
|
||||
/// The returned number is the internal representation of the
|
||||
/// address, and should be used for optimization purposes only
|
||||
/// (like sending the address through a socket).
|
||||
/// The integer produced by this function can then be converted
|
||||
/// back to a sf::IpAddress with the proper constructor.
|
||||
///
|
||||
/// \return 32-bits unsigned integer representation of the address
|
||||
///
|
||||
/// \see toString
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
Uint32 toInteger() const;
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Get the computer's local address
|
||||
///
|
||||
/// The local address is the address of the computer from the
|
||||
/// LAN point of view, i.e. something like 192.168.1.56. It is
|
||||
/// meaningful only for communications over the local network.
|
||||
/// Unlike getPublicAddress, this function is fast and may be
|
||||
/// used safely anywhere.
|
||||
///
|
||||
/// \return Local IP address of the computer
|
||||
///
|
||||
/// \see getPublicAddress
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
static IpAddress getLocalAddress();
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Get the computer's public address
|
||||
///
|
||||
/// The public address is the address of the computer from the
|
||||
/// internet point of view, i.e. something like 89.54.1.169.
|
||||
/// It is necessary for communications over the world wide web.
|
||||
/// The only way to get a public address is to ask it to a
|
||||
/// distant website; as a consequence, this function depends on
|
||||
/// both your network connection and the server, and may be
|
||||
/// very slow. You should use it as few as possible. Because
|
||||
/// this function depends on the network connection and on a distant
|
||||
/// server, you may use a time limit if you don't want your program
|
||||
/// to be possibly stuck waiting in case there is a problem; this
|
||||
/// limit is deactivated by default.
|
||||
///
|
||||
/// \param timeout Maximum time to wait
|
||||
///
|
||||
/// \return Public IP address of the computer
|
||||
///
|
||||
/// \see getLocalAddress
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
static IpAddress getPublicAddress(Time timeout = Time::Zero);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
// Static member data
|
||||
////////////////////////////////////////////////////////////
|
||||
static const IpAddress None; ///< Value representing an empty/invalid address
|
||||
static const IpAddress Any; ///< Value representing any address (0.0.0.0)
|
||||
static const IpAddress LocalHost; ///< The "localhost" address (for connecting a computer to itself locally)
|
||||
static const IpAddress Broadcast; ///< The "broadcast" address (for sending UDP messages to everyone on a local network)
|
||||
|
||||
private:
|
||||
|
||||
friend SFML_NETWORK_API bool operator <(const IpAddress& left, const IpAddress& right);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Resolve the given address string
|
||||
///
|
||||
/// \param address Address string
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
void resolve(const std::string& address);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
// Member data
|
||||
////////////////////////////////////////////////////////////
|
||||
Uint32 m_address; ///< Address stored as an unsigned 32 bits integer
|
||||
bool m_valid; ///< Is the address valid?
|
||||
};
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Overload of == operator to compare two IP addresses
|
||||
///
|
||||
/// \param left Left operand (a IP address)
|
||||
/// \param right Right operand (a IP address)
|
||||
///
|
||||
/// \return True if both addresses are equal
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
SFML_NETWORK_API bool operator ==(const IpAddress& left, const IpAddress& right);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Overload of != operator to compare two IP addresses
|
||||
///
|
||||
/// \param left Left operand (a IP address)
|
||||
/// \param right Right operand (a IP address)
|
||||
///
|
||||
/// \return True if both addresses are different
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
SFML_NETWORK_API bool operator !=(const IpAddress& left, const IpAddress& right);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Overload of < operator to compare two IP addresses
|
||||
///
|
||||
/// \param left Left operand (a IP address)
|
||||
/// \param right Right operand (a IP address)
|
||||
///
|
||||
/// \return True if \a left is lesser than \a right
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
SFML_NETWORK_API bool operator <(const IpAddress& left, const IpAddress& right);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Overload of > operator to compare two IP addresses
|
||||
///
|
||||
/// \param left Left operand (a IP address)
|
||||
/// \param right Right operand (a IP address)
|
||||
///
|
||||
/// \return True if \a left is greater than \a right
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
SFML_NETWORK_API bool operator >(const IpAddress& left, const IpAddress& right);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Overload of <= operator to compare two IP addresses
|
||||
///
|
||||
/// \param left Left operand (a IP address)
|
||||
/// \param right Right operand (a IP address)
|
||||
///
|
||||
/// \return True if \a left is lesser or equal than \a right
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
SFML_NETWORK_API bool operator <=(const IpAddress& left, const IpAddress& right);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Overload of >= operator to compare two IP addresses
|
||||
///
|
||||
/// \param left Left operand (a IP address)
|
||||
/// \param right Right operand (a IP address)
|
||||
///
|
||||
/// \return True if \a left is greater or equal than \a right
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
SFML_NETWORK_API bool operator >=(const IpAddress& left, const IpAddress& right);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Overload of >> operator to extract an IP address from an input stream
|
||||
///
|
||||
/// \param stream Input stream
|
||||
/// \param address IP address to extract
|
||||
///
|
||||
/// \return Reference to the input stream
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
SFML_NETWORK_API std::istream& operator >>(std::istream& stream, IpAddress& address);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Overload of << operator to print an IP address to an output stream
|
||||
///
|
||||
/// \param stream Output stream
|
||||
/// \param address IP address to print
|
||||
///
|
||||
/// \return Reference to the output stream
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
SFML_NETWORK_API std::ostream& operator <<(std::ostream& stream, const IpAddress& address);
|
||||
|
||||
} // namespace sf
|
||||
|
||||
|
||||
#endif // SFML_IPADDRESS_HPP
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \class sf::IpAddress
|
||||
/// \ingroup network
|
||||
///
|
||||
/// sf::IpAddress is a utility class for manipulating network
|
||||
/// addresses. It provides a set a implicit constructors and
|
||||
/// conversion functions to easily build or transform an IP
|
||||
/// address from/to various representations.
|
||||
///
|
||||
/// Usage example:
|
||||
/// \code
|
||||
/// sf::IpAddress a0; // an invalid address
|
||||
/// sf::IpAddress a1 = sf::IpAddress::None; // an invalid address (same as a0)
|
||||
/// sf::IpAddress a2("127.0.0.1"); // the local host address
|
||||
/// sf::IpAddress a3 = sf::IpAddress::Broadcast; // the broadcast address
|
||||
/// sf::IpAddress a4(192, 168, 1, 56); // a local address
|
||||
/// sf::IpAddress a5("my_computer"); // a local address created from a network name
|
||||
/// sf::IpAddress a6("89.54.1.169"); // a distant address
|
||||
/// sf::IpAddress a7("www.google.com"); // a distant address created from a network name
|
||||
/// sf::IpAddress a8 = sf::IpAddress::getLocalAddress(); // my address on the local network
|
||||
/// sf::IpAddress a9 = sf::IpAddress::getPublicAddress(); // my address on the internet
|
||||
/// \endcode
|
||||
///
|
||||
/// Note that sf::IpAddress currently doesn't support IPv6
|
||||
/// nor other types of network addresses.
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
-532
File diff suppressed because it is too large
Load Diff
-219
@@ -1,219 +0,0 @@
|
||||
////////////////////////////////////////////////////////////
|
||||
//
|
||||
// SFML - Simple and Fast Multimedia Library
|
||||
// Copyright (C) 2007-2018 Laurent Gomila (laurent@sfml-dev.org)
|
||||
//
|
||||
// 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.
|
||||
//
|
||||
// Permission is granted to anyone to use this software for any purpose,
|
||||
// including commercial applications, and to alter it and redistribute it freely,
|
||||
// subject to the following restrictions:
|
||||
//
|
||||
// 1. The origin of this software must not be misrepresented;
|
||||
// you must not claim that you wrote the original software.
|
||||
// If you use this software in a product, an acknowledgment
|
||||
// in the product documentation would be appreciated but is not required.
|
||||
//
|
||||
// 2. Altered source versions must be plainly marked as such,
|
||||
// and must not be misrepresented as being the original software.
|
||||
//
|
||||
// 3. This notice may not be removed or altered from any source distribution.
|
||||
//
|
||||
////////////////////////////////////////////////////////////
|
||||
|
||||
#ifndef SFML_SOCKET_HPP
|
||||
#define SFML_SOCKET_HPP
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
// Headers
|
||||
////////////////////////////////////////////////////////////
|
||||
#include <SFML/Network/Export.hpp>
|
||||
#include <SFML/Network/SocketHandle.hpp>
|
||||
#include <SFML/System/NonCopyable.hpp>
|
||||
#include <vector>
|
||||
|
||||
|
||||
namespace sf
|
||||
{
|
||||
class SocketSelector;
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Base class for all the socket types
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
class SFML_NETWORK_API Socket : NonCopyable
|
||||
{
|
||||
public:
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Status codes that may be returned by socket functions
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
enum Status
|
||||
{
|
||||
Done, ///< The socket has sent / received the data
|
||||
NotReady, ///< The socket is not ready to send / receive data yet
|
||||
Partial, ///< The socket sent a part of the data
|
||||
Disconnected, ///< The TCP socket has been disconnected
|
||||
Error ///< An unexpected error happened
|
||||
};
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Some special values used by sockets
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
enum
|
||||
{
|
||||
AnyPort = 0 ///< Special value that tells the system to pick any available port
|
||||
};
|
||||
|
||||
public:
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Destructor
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
virtual ~Socket();
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Set the blocking state of the socket
|
||||
///
|
||||
/// In blocking mode, calls will not return until they have
|
||||
/// completed their task. For example, a call to Receive in
|
||||
/// blocking mode won't return until some data was actually
|
||||
/// received.
|
||||
/// In non-blocking mode, calls will always return immediately,
|
||||
/// using the return code to signal whether there was data
|
||||
/// available or not.
|
||||
/// By default, all sockets are blocking.
|
||||
///
|
||||
/// \param blocking True to set the socket as blocking, false for non-blocking
|
||||
///
|
||||
/// \see isBlocking
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
void setBlocking(bool blocking);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Tell whether the socket is in blocking or non-blocking mode
|
||||
///
|
||||
/// \return True if the socket is blocking, false otherwise
|
||||
///
|
||||
/// \see setBlocking
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
bool isBlocking() const;
|
||||
|
||||
protected:
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Types of protocols that the socket can use
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
enum Type
|
||||
{
|
||||
Tcp, ///< TCP protocol
|
||||
Udp ///< UDP protocol
|
||||
};
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Default constructor
|
||||
///
|
||||
/// This constructor can only be accessed by derived classes.
|
||||
///
|
||||
/// \param type Type of the socket (TCP or UDP)
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
Socket(Type type);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Return the internal handle of the socket
|
||||
///
|
||||
/// The returned handle may be invalid if the socket
|
||||
/// was not created yet (or already destroyed).
|
||||
/// This function can only be accessed by derived classes.
|
||||
///
|
||||
/// \return The internal (OS-specific) handle of the socket
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
SocketHandle getHandle() const;
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Create the internal representation of the socket
|
||||
///
|
||||
/// This function can only be accessed by derived classes.
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
void create();
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Create the internal representation of the socket
|
||||
/// from a socket handle
|
||||
///
|
||||
/// This function can only be accessed by derived classes.
|
||||
///
|
||||
/// \param handle OS-specific handle of the socket to wrap
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
void create(SocketHandle handle);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Close the socket gracefully
|
||||
///
|
||||
/// This function can only be accessed by derived classes.
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
void close();
|
||||
|
||||
private:
|
||||
|
||||
friend class SocketSelector;
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
// Member data
|
||||
////////////////////////////////////////////////////////////
|
||||
Type m_type; ///< Type of the socket (TCP or UDP)
|
||||
SocketHandle m_socket; ///< Socket descriptor
|
||||
bool m_isBlocking; ///< Current blocking mode of the socket
|
||||
};
|
||||
|
||||
} // namespace sf
|
||||
|
||||
|
||||
#endif // SFML_SOCKET_HPP
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \class sf::Socket
|
||||
/// \ingroup network
|
||||
///
|
||||
/// This class mainly defines internal stuff to be used by
|
||||
/// derived classes.
|
||||
///
|
||||
/// The only public features that it defines, and which
|
||||
/// is therefore common to all the socket classes, is the
|
||||
/// blocking state. All sockets can be set as blocking or
|
||||
/// non-blocking.
|
||||
///
|
||||
/// In blocking mode, socket functions will hang until
|
||||
/// the operation completes, which means that the entire
|
||||
/// program (well, in fact the current thread if you use
|
||||
/// multiple ones) will be stuck waiting for your socket
|
||||
/// operation to complete.
|
||||
///
|
||||
/// In non-blocking mode, all the socket functions will
|
||||
/// return immediately. If the socket is not ready to complete
|
||||
/// the requested operation, the function simply returns
|
||||
/// the proper status code (Socket::NotReady).
|
||||
///
|
||||
/// The default mode, which is blocking, is the one that is
|
||||
/// generally used, in combination with threads or selectors.
|
||||
/// The non-blocking mode is rather used in real-time
|
||||
/// applications that run an endless loop that can poll
|
||||
/// the socket often enough, and cannot afford blocking
|
||||
/// this loop.
|
||||
///
|
||||
/// \see sf::TcpListener, sf::TcpSocket, sf::UdpSocket
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
@@ -1,57 +0,0 @@
|
||||
////////////////////////////////////////////////////////////
|
||||
//
|
||||
// SFML - Simple and Fast Multimedia Library
|
||||
// Copyright (C) 2007-2018 Laurent Gomila (laurent@sfml-dev.org)
|
||||
//
|
||||
// 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.
|
||||
//
|
||||
// Permission is granted to anyone to use this software for any purpose,
|
||||
// including commercial applications, and to alter it and redistribute it freely,
|
||||
// subject to the following restrictions:
|
||||
//
|
||||
// 1. The origin of this software must not be misrepresented;
|
||||
// you must not claim that you wrote the original software.
|
||||
// If you use this software in a product, an acknowledgment
|
||||
// in the product documentation would be appreciated but is not required.
|
||||
//
|
||||
// 2. Altered source versions must be plainly marked as such,
|
||||
// and must not be misrepresented as being the original software.
|
||||
//
|
||||
// 3. This notice may not be removed or altered from any source distribution.
|
||||
//
|
||||
////////////////////////////////////////////////////////////
|
||||
|
||||
#ifndef SFML_SOCKETHANDLE_HPP
|
||||
#define SFML_SOCKETHANDLE_HPP
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
// Headers
|
||||
////////////////////////////////////////////////////////////
|
||||
#include <SFML/Config.hpp>
|
||||
|
||||
#if defined(SFML_SYSTEM_WINDOWS)
|
||||
#include <basetsd.h>
|
||||
#endif
|
||||
|
||||
|
||||
namespace sf
|
||||
{
|
||||
////////////////////////////////////////////////////////////
|
||||
// Define the low-level socket handle type, specific to
|
||||
// each platform
|
||||
////////////////////////////////////////////////////////////
|
||||
#if defined(SFML_SYSTEM_WINDOWS)
|
||||
|
||||
typedef UINT_PTR SocketHandle;
|
||||
|
||||
#else
|
||||
|
||||
typedef int SocketHandle;
|
||||
|
||||
#endif
|
||||
|
||||
} // namespace sf
|
||||
|
||||
|
||||
#endif // SFML_SOCKETHANDLE_HPP
|
||||
@@ -1,263 +0,0 @@
|
||||
////////////////////////////////////////////////////////////
|
||||
//
|
||||
// SFML - Simple and Fast Multimedia Library
|
||||
// Copyright (C) 2007-2018 Laurent Gomila (laurent@sfml-dev.org)
|
||||
//
|
||||
// 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.
|
||||
//
|
||||
// Permission is granted to anyone to use this software for any purpose,
|
||||
// including commercial applications, and to alter it and redistribute it freely,
|
||||
// subject to the following restrictions:
|
||||
//
|
||||
// 1. The origin of this software must not be misrepresented;
|
||||
// you must not claim that you wrote the original software.
|
||||
// If you use this software in a product, an acknowledgment
|
||||
// in the product documentation would be appreciated but is not required.
|
||||
//
|
||||
// 2. Altered source versions must be plainly marked as such,
|
||||
// and must not be misrepresented as being the original software.
|
||||
//
|
||||
// 3. This notice may not be removed or altered from any source distribution.
|
||||
//
|
||||
////////////////////////////////////////////////////////////
|
||||
|
||||
#ifndef SFML_SOCKETSELECTOR_HPP
|
||||
#define SFML_SOCKETSELECTOR_HPP
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
// Headers
|
||||
////////////////////////////////////////////////////////////
|
||||
#include <SFML/Network/Export.hpp>
|
||||
#include <SFML/System/Time.hpp>
|
||||
|
||||
|
||||
namespace sf
|
||||
{
|
||||
class Socket;
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Multiplexer that allows to read from multiple sockets
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
class SFML_NETWORK_API SocketSelector
|
||||
{
|
||||
public:
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Default constructor
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
SocketSelector();
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Copy constructor
|
||||
///
|
||||
/// \param copy Instance to copy
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
SocketSelector(const SocketSelector& copy);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Destructor
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
~SocketSelector();
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Add a new socket to the selector
|
||||
///
|
||||
/// This function keeps a weak reference to the socket,
|
||||
/// so you have to make sure that the socket is not destroyed
|
||||
/// while it is stored in the selector.
|
||||
/// This function does nothing if the socket is not valid.
|
||||
///
|
||||
/// \param socket Reference to the socket to add
|
||||
///
|
||||
/// \see remove, clear
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
void add(Socket& socket);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Remove a socket from the selector
|
||||
///
|
||||
/// This function doesn't destroy the socket, it simply
|
||||
/// removes the reference that the selector has to it.
|
||||
///
|
||||
/// \param socket Reference to the socket to remove
|
||||
///
|
||||
/// \see add, clear
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
void remove(Socket& socket);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Remove all the sockets stored in the selector
|
||||
///
|
||||
/// This function doesn't destroy any instance, it simply
|
||||
/// removes all the references that the selector has to
|
||||
/// external sockets.
|
||||
///
|
||||
/// \see add, remove
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
void clear();
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Wait until one or more sockets are ready to receive
|
||||
///
|
||||
/// This function returns as soon as at least one socket has
|
||||
/// some data available to be received. To know which sockets are
|
||||
/// ready, use the isReady function.
|
||||
/// If you use a timeout and no socket is ready before the timeout
|
||||
/// is over, the function returns false.
|
||||
///
|
||||
/// \param timeout Maximum time to wait, (use Time::Zero for infinity)
|
||||
///
|
||||
/// \return True if there are sockets ready, false otherwise
|
||||
///
|
||||
/// \see isReady
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
bool wait(Time timeout = Time::Zero);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Test a socket to know if it is ready to receive data
|
||||
///
|
||||
/// This function must be used after a call to Wait, to know
|
||||
/// which sockets are ready to receive data. If a socket is
|
||||
/// ready, a call to receive will never block because we know
|
||||
/// that there is data available to read.
|
||||
/// Note that if this function returns true for a TcpListener,
|
||||
/// this means that it is ready to accept a new connection.
|
||||
///
|
||||
/// \param socket Socket to test
|
||||
///
|
||||
/// \return True if the socket is ready to read, false otherwise
|
||||
///
|
||||
/// \see isReady
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
bool isReady(Socket& socket) const;
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Overload of assignment operator
|
||||
///
|
||||
/// \param right Instance to assign
|
||||
///
|
||||
/// \return Reference to self
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
SocketSelector& operator =(const SocketSelector& right);
|
||||
|
||||
private:
|
||||
|
||||
struct SocketSelectorImpl;
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
// Member data
|
||||
////////////////////////////////////////////////////////////
|
||||
SocketSelectorImpl* m_impl; ///< Opaque pointer to the implementation (which requires OS-specific types)
|
||||
};
|
||||
|
||||
} // namespace sf
|
||||
|
||||
|
||||
#endif // SFML_SOCKETSELECTOR_HPP
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \class sf::SocketSelector
|
||||
/// \ingroup network
|
||||
///
|
||||
/// Socket selectors provide a way to wait until some data is
|
||||
/// available on a set of sockets, instead of just one. This
|
||||
/// is convenient when you have multiple sockets that may
|
||||
/// possibly receive data, but you don't know which one will
|
||||
/// be ready first. In particular, it avoids to use a thread
|
||||
/// for each socket; with selectors, a single thread can handle
|
||||
/// all the sockets.
|
||||
///
|
||||
/// All types of sockets can be used in a selector:
|
||||
/// \li sf::TcpListener
|
||||
/// \li sf::TcpSocket
|
||||
/// \li sf::UdpSocket
|
||||
///
|
||||
/// A selector doesn't store its own copies of the sockets
|
||||
/// (socket classes are not copyable anyway), it simply keeps
|
||||
/// a reference to the original sockets that you pass to the
|
||||
/// "add" function. Therefore, you can't use the selector as a
|
||||
/// socket container, you must store them outside and make sure
|
||||
/// that they are alive as long as they are used in the selector.
|
||||
///
|
||||
/// Using a selector is simple:
|
||||
/// \li populate the selector with all the sockets that you want to observe
|
||||
/// \li make it wait until there is data available on any of the sockets
|
||||
/// \li test each socket to find out which ones are ready
|
||||
///
|
||||
/// Usage example:
|
||||
/// \code
|
||||
/// // Create a socket to listen to new connections
|
||||
/// sf::TcpListener listener;
|
||||
/// listener.listen(55001);
|
||||
///
|
||||
/// // Create a list to store the future clients
|
||||
/// std::list<sf::TcpSocket*> clients;
|
||||
///
|
||||
/// // Create a selector
|
||||
/// sf::SocketSelector selector;
|
||||
///
|
||||
/// // Add the listener to the selector
|
||||
/// selector.add(listener);
|
||||
///
|
||||
/// // Endless loop that waits for new connections
|
||||
/// while (running)
|
||||
/// {
|
||||
/// // Make the selector wait for data on any socket
|
||||
/// if (selector.wait())
|
||||
/// {
|
||||
/// // Test the listener
|
||||
/// if (selector.isReady(listener))
|
||||
/// {
|
||||
/// // The listener is ready: there is a pending connection
|
||||
/// sf::TcpSocket* client = new sf::TcpSocket;
|
||||
/// if (listener.accept(*client) == sf::Socket::Done)
|
||||
/// {
|
||||
/// // Add the new client to the clients list
|
||||
/// clients.push_back(client);
|
||||
///
|
||||
/// // Add the new client to the selector so that we will
|
||||
/// // be notified when he sends something
|
||||
/// selector.add(*client);
|
||||
/// }
|
||||
/// else
|
||||
/// {
|
||||
/// // Error, we won't get a new connection, delete the socket
|
||||
/// delete client;
|
||||
/// }
|
||||
/// }
|
||||
/// else
|
||||
/// {
|
||||
/// // The listener socket is not ready, test all other sockets (the clients)
|
||||
/// for (std::list<sf::TcpSocket*>::iterator it = clients.begin(); it != clients.end(); ++it)
|
||||
/// {
|
||||
/// sf::TcpSocket& client = **it;
|
||||
/// if (selector.isReady(client))
|
||||
/// {
|
||||
/// // The client has sent some data, we can receive it
|
||||
/// sf::Packet packet;
|
||||
/// if (client.receive(packet) == sf::Socket::Done)
|
||||
/// {
|
||||
/// ...
|
||||
/// }
|
||||
/// }
|
||||
/// }
|
||||
/// }
|
||||
/// }
|
||||
/// }
|
||||
/// \endcode
|
||||
///
|
||||
/// \see sf::Socket
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
-166
@@ -1,166 +0,0 @@
|
||||
////////////////////////////////////////////////////////////
|
||||
//
|
||||
// SFML - Simple and Fast Multimedia Library
|
||||
// Copyright (C) 2007-2018 Laurent Gomila (laurent@sfml-dev.org)
|
||||
//
|
||||
// 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.
|
||||
//
|
||||
// Permission is granted to anyone to use this software for any purpose,
|
||||
// including commercial applications, and to alter it and redistribute it freely,
|
||||
// subject to the following restrictions:
|
||||
//
|
||||
// 1. The origin of this software must not be misrepresented;
|
||||
// you must not claim that you wrote the original software.
|
||||
// If you use this software in a product, an acknowledgment
|
||||
// in the product documentation would be appreciated but is not required.
|
||||
//
|
||||
// 2. Altered source versions must be plainly marked as such,
|
||||
// and must not be misrepresented as being the original software.
|
||||
//
|
||||
// 3. This notice may not be removed or altered from any source distribution.
|
||||
//
|
||||
////////////////////////////////////////////////////////////
|
||||
|
||||
#ifndef SFML_TCPLISTENER_HPP
|
||||
#define SFML_TCPLISTENER_HPP
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
// Headers
|
||||
////////////////////////////////////////////////////////////
|
||||
#include <SFML/Network/Export.hpp>
|
||||
#include <SFML/Network/Socket.hpp>
|
||||
#include <SFML/Network/IPAddress.hpp>
|
||||
|
||||
|
||||
namespace sf
|
||||
{
|
||||
class TcpSocket;
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Socket that listens to new TCP connections
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
class SFML_NETWORK_API TcpListener : public Socket
|
||||
{
|
||||
public:
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Default constructor
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
TcpListener();
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Get the port to which the socket is bound locally
|
||||
///
|
||||
/// If the socket is not listening to a port, this function
|
||||
/// returns 0.
|
||||
///
|
||||
/// \return Port to which the socket is bound
|
||||
///
|
||||
/// \see listen
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
unsigned short getLocalPort() const;
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Start listening for incoming connection attempts
|
||||
///
|
||||
/// This function makes the socket start listening on the
|
||||
/// specified port, waiting for incoming connection attempts.
|
||||
///
|
||||
/// If the socket is already listening on a port when this
|
||||
/// function is called, it will stop listening on the old
|
||||
/// port before starting to listen on the new port.
|
||||
///
|
||||
/// \param port Port to listen on for incoming connection attempts
|
||||
/// \param address Address of the interface to listen on
|
||||
///
|
||||
/// \return Status code
|
||||
///
|
||||
/// \see accept, close
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
Status listen(unsigned short port, const IpAddress& address = IpAddress::Any);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Stop listening and close the socket
|
||||
///
|
||||
/// This function gracefully stops the listener. If the
|
||||
/// socket is not listening, this function has no effect.
|
||||
///
|
||||
/// \see listen
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
void close();
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Accept a new connection
|
||||
///
|
||||
/// If the socket is in blocking mode, this function will
|
||||
/// not return until a connection is actually received.
|
||||
///
|
||||
/// \param socket Socket that will hold the new connection
|
||||
///
|
||||
/// \return Status code
|
||||
///
|
||||
/// \see listen
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
Status accept(TcpSocket& socket);
|
||||
};
|
||||
|
||||
|
||||
} // namespace sf
|
||||
|
||||
|
||||
#endif // SFML_TCPLISTENER_HPP
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \class sf::TcpListener
|
||||
/// \ingroup network
|
||||
///
|
||||
/// A listener socket is a special type of socket that listens to
|
||||
/// a given port and waits for connections on that port.
|
||||
/// This is all it can do.
|
||||
///
|
||||
/// When a new connection is received, you must call accept and
|
||||
/// the listener returns a new instance of sf::TcpSocket that
|
||||
/// is properly initialized and can be used to communicate with
|
||||
/// the new client.
|
||||
///
|
||||
/// Listener sockets are specific to the TCP protocol,
|
||||
/// UDP sockets are connectionless and can therefore communicate
|
||||
/// directly. As a consequence, a listener socket will always
|
||||
/// return the new connections as sf::TcpSocket instances.
|
||||
///
|
||||
/// A listener is automatically closed on destruction, like all
|
||||
/// other types of socket. However if you want to stop listening
|
||||
/// before the socket is destroyed, you can call its close()
|
||||
/// function.
|
||||
///
|
||||
/// Usage example:
|
||||
/// \code
|
||||
/// // Create a listener socket and make it wait for new
|
||||
/// // connections on port 55001
|
||||
/// sf::TcpListener listener;
|
||||
/// listener.listen(55001);
|
||||
///
|
||||
/// // Endless loop that waits for new connections
|
||||
/// while (running)
|
||||
/// {
|
||||
/// sf::TcpSocket client;
|
||||
/// if (listener.accept(client) == sf::Socket::Done)
|
||||
/// {
|
||||
/// // A new client just connected!
|
||||
/// std::cout << "New connection received from " << client.getRemoteAddress() << std::endl;
|
||||
/// doSomethingWith(client);
|
||||
/// }
|
||||
/// }
|
||||
/// \endcode
|
||||
///
|
||||
/// \see sf::TcpSocket, sf::Socket
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
-316
@@ -1,316 +0,0 @@
|
||||
////////////////////////////////////////////////////////////
|
||||
//
|
||||
// SFML - Simple and Fast Multimedia Library
|
||||
// Copyright (C) 2007-2018 Laurent Gomila (laurent@sfml-dev.org)
|
||||
//
|
||||
// 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.
|
||||
//
|
||||
// Permission is granted to anyone to use this software for any purpose,
|
||||
// including commercial applications, and to alter it and redistribute it freely,
|
||||
// subject to the following restrictions:
|
||||
//
|
||||
// 1. The origin of this software must not be misrepresented;
|
||||
// you must not claim that you wrote the original software.
|
||||
// If you use this software in a product, an acknowledgment
|
||||
// in the product documentation would be appreciated but is not required.
|
||||
//
|
||||
// 2. Altered source versions must be plainly marked as such,
|
||||
// and must not be misrepresented as being the original software.
|
||||
//
|
||||
// 3. This notice may not be removed or altered from any source distribution.
|
||||
//
|
||||
////////////////////////////////////////////////////////////
|
||||
|
||||
#ifndef SFML_TCPSOCKET_HPP
|
||||
#define SFML_TCPSOCKET_HPP
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
// Headers
|
||||
////////////////////////////////////////////////////////////
|
||||
#include <SFML/Network/Export.hpp>
|
||||
#include <SFML/Network/Socket.hpp>
|
||||
#include <SFML/System/Time.hpp>
|
||||
|
||||
|
||||
namespace sf
|
||||
{
|
||||
class TcpListener;
|
||||
class IpAddress;
|
||||
class Packet;
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Specialized socket using the TCP protocol
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
class SFML_NETWORK_API TcpSocket : public Socket
|
||||
{
|
||||
public:
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Default constructor
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
TcpSocket();
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Get the port to which the socket is bound locally
|
||||
///
|
||||
/// If the socket is not connected, this function returns 0.
|
||||
///
|
||||
/// \return Port to which the socket is bound
|
||||
///
|
||||
/// \see connect, getRemotePort
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
unsigned short getLocalPort() const;
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Get the address of the connected peer
|
||||
///
|
||||
/// It the socket is not connected, this function returns
|
||||
/// sf::IpAddress::None.
|
||||
///
|
||||
/// \return Address of the remote peer
|
||||
///
|
||||
/// \see getRemotePort
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
IpAddress getRemoteAddress() const;
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Get the port of the connected peer to which
|
||||
/// the socket is connected
|
||||
///
|
||||
/// If the socket is not connected, this function returns 0.
|
||||
///
|
||||
/// \return Remote port to which the socket is connected
|
||||
///
|
||||
/// \see getRemoteAddress
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
unsigned short getRemotePort() const;
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Connect the socket to a remote peer
|
||||
///
|
||||
/// In blocking mode, this function may take a while, especially
|
||||
/// if the remote peer is not reachable. The last parameter allows
|
||||
/// you to stop trying to connect after a given timeout.
|
||||
/// If the socket is already connected, the connection is
|
||||
/// forcibly disconnected before attempting to connect again.
|
||||
///
|
||||
/// \param remoteAddress Address of the remote peer
|
||||
/// \param remotePort Port of the remote peer
|
||||
/// \param timeout Optional maximum time to wait
|
||||
///
|
||||
/// \return Status code
|
||||
///
|
||||
/// \see disconnect
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
Status connect(const IpAddress& remoteAddress, unsigned short remotePort, Time timeout = Time::Zero);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Disconnect the socket from its remote peer
|
||||
///
|
||||
/// This function gracefully closes the connection. If the
|
||||
/// socket is not connected, this function has no effect.
|
||||
///
|
||||
/// \see connect
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
void disconnect();
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Send raw data to the remote peer
|
||||
///
|
||||
/// To be able to handle partial sends over non-blocking
|
||||
/// sockets, use the send(const void*, std::size_t, std::size_t&)
|
||||
/// overload instead.
|
||||
/// This function will fail if the socket is not connected.
|
||||
///
|
||||
/// \param data Pointer to the sequence of bytes to send
|
||||
/// \param size Number of bytes to send
|
||||
///
|
||||
/// \return Status code
|
||||
///
|
||||
/// \see receive
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
Status send(const void* data, std::size_t size);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Send raw data to the remote peer
|
||||
///
|
||||
/// This function will fail if the socket is not connected.
|
||||
///
|
||||
/// \param data Pointer to the sequence of bytes to send
|
||||
/// \param size Number of bytes to send
|
||||
/// \param sent The number of bytes sent will be written here
|
||||
///
|
||||
/// \return Status code
|
||||
///
|
||||
/// \see receive
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
Status send(const void* data, std::size_t size, std::size_t& sent);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Receive raw data from the remote peer
|
||||
///
|
||||
/// In blocking mode, this function will wait until some
|
||||
/// bytes are actually received.
|
||||
/// This function will fail if the socket is not connected.
|
||||
///
|
||||
/// \param data Pointer to the array to fill with the received bytes
|
||||
/// \param size Maximum number of bytes that can be received
|
||||
/// \param received This variable is filled with the actual number of bytes received
|
||||
///
|
||||
/// \return Status code
|
||||
///
|
||||
/// \see send
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
Status receive(void* data, std::size_t size, std::size_t& received);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Send a formatted packet of data to the remote peer
|
||||
///
|
||||
/// In non-blocking mode, if this function returns sf::Socket::Partial,
|
||||
/// you \em must retry sending the same unmodified packet before sending
|
||||
/// anything else in order to guarantee the packet arrives at the remote
|
||||
/// peer uncorrupted.
|
||||
/// This function will fail if the socket is not connected.
|
||||
///
|
||||
/// \param packet Packet to send
|
||||
///
|
||||
/// \return Status code
|
||||
///
|
||||
/// \see receive
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
Status send(Packet& packet);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Receive a formatted packet of data from the remote peer
|
||||
///
|
||||
/// In blocking mode, this function will wait until the whole packet
|
||||
/// has been received.
|
||||
/// This function will fail if the socket is not connected.
|
||||
///
|
||||
/// \param packet Packet to fill with the received data
|
||||
///
|
||||
/// \return Status code
|
||||
///
|
||||
/// \see send
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
Status receive(Packet& packet);
|
||||
|
||||
private:
|
||||
|
||||
friend class TcpListener;
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Structure holding the data of a pending packet
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
struct PendingPacket
|
||||
{
|
||||
PendingPacket();
|
||||
|
||||
Uint32 Size; ///< Data of packet size
|
||||
std::size_t SizeReceived; ///< Number of size bytes received so far
|
||||
std::vector<char> Data; ///< Data of the packet
|
||||
};
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
// Member data
|
||||
////////////////////////////////////////////////////////////
|
||||
PendingPacket m_pendingPacket; ///< Temporary data of the packet currently being received
|
||||
};
|
||||
|
||||
} // namespace sf
|
||||
|
||||
|
||||
#endif // SFML_TCPSOCKET_HPP
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \class sf::TcpSocket
|
||||
/// \ingroup network
|
||||
///
|
||||
/// TCP is a connected protocol, which means that a TCP
|
||||
/// socket can only communicate with the host it is connected
|
||||
/// to. It can't send or receive anything if it is not connected.
|
||||
///
|
||||
/// The TCP protocol is reliable but adds a slight overhead.
|
||||
/// It ensures that your data will always be received in order
|
||||
/// and without errors (no data corrupted, lost or duplicated).
|
||||
///
|
||||
/// When a socket is connected to a remote host, you can
|
||||
/// retrieve informations about this host with the
|
||||
/// getRemoteAddress and getRemotePort functions. You can
|
||||
/// also get the local port to which the socket is bound
|
||||
/// (which is automatically chosen when the socket is connected),
|
||||
/// with the getLocalPort function.
|
||||
///
|
||||
/// Sending and receiving data can use either the low-level
|
||||
/// or the high-level functions. The low-level functions
|
||||
/// process a raw sequence of bytes, and cannot ensure that
|
||||
/// one call to Send will exactly match one call to Receive
|
||||
/// at the other end of the socket.
|
||||
///
|
||||
/// The high-level interface uses packets (see sf::Packet),
|
||||
/// which are easier to use and provide more safety regarding
|
||||
/// the data that is exchanged. You can look at the sf::Packet
|
||||
/// class to get more details about how they work.
|
||||
///
|
||||
/// The socket is automatically disconnected when it is destroyed,
|
||||
/// but if you want to explicitly close the connection while
|
||||
/// the socket instance is still alive, you can call disconnect.
|
||||
///
|
||||
/// Usage example:
|
||||
/// \code
|
||||
/// // ----- The client -----
|
||||
///
|
||||
/// // Create a socket and connect it to 192.168.1.50 on port 55001
|
||||
/// sf::TcpSocket socket;
|
||||
/// socket.connect("192.168.1.50", 55001);
|
||||
///
|
||||
/// // Send a message to the connected host
|
||||
/// std::string message = "Hi, I am a client";
|
||||
/// socket.send(message.c_str(), message.size() + 1);
|
||||
///
|
||||
/// // Receive an answer from the server
|
||||
/// char buffer[1024];
|
||||
/// std::size_t received = 0;
|
||||
/// socket.receive(buffer, sizeof(buffer), received);
|
||||
/// std::cout << "The server said: " << buffer << std::endl;
|
||||
///
|
||||
/// // ----- The server -----
|
||||
///
|
||||
/// // Create a listener to wait for incoming connections on port 55001
|
||||
/// sf::TcpListener listener;
|
||||
/// listener.listen(55001);
|
||||
///
|
||||
/// // Wait for a connection
|
||||
/// sf::TcpSocket socket;
|
||||
/// listener.accept(socket);
|
||||
/// std::cout << "New client connected: " << socket.getRemoteAddress() << std::endl;
|
||||
///
|
||||
/// // Receive a message from the client
|
||||
/// char buffer[1024];
|
||||
/// std::size_t received = 0;
|
||||
/// socket.receive(buffer, sizeof(buffer), received);
|
||||
/// std::cout << "The client said: " << buffer << std::endl;
|
||||
///
|
||||
/// // Send an answer
|
||||
/// std::string message = "Welcome, client";
|
||||
/// socket.send(message.c_str(), message.size() + 1);
|
||||
/// \endcode
|
||||
///
|
||||
/// \see sf::Socket, sf::UdpSocket, sf::Packet
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user