diff --git a/include/Nazara/Network/TcpBase.hpp b/include/Nazara/Network/TcpBase.hpp deleted file mode 100644 index 0d7035026..000000000 --- a/include/Nazara/Network/TcpBase.hpp +++ /dev/null @@ -1,42 +0,0 @@ -// Copyright (C) 2015 Jérôme Leclercq -// This file is part of the "Nazara Engine - Network module" -// For conditions of distribution and use, see copyright notice in Config.hpp - -#pragma once - -#ifndef NAZARA_TCPBASE_HPP -#define NAZARA_TCPBASE_HPP - -#include -#include - -namespace Nz -{ - class NAZARA_NETWORK_API TcpBase : public AbstractSocket - { - public: - ~TcpBase() = default; - - inline bool IsLowDelayEnabled() const; - inline bool IsKeepAliveEnabled() const; - - // Slots - NazaraSignal(OnStateChange, const TcpBase* /*socket*/, SocketState /*newState*/); - - protected: - TcpBase(); - TcpBase(TcpBase&& tcpBase); - - virtual void OnOpened() override; - - SocketState m_state; - UInt64 m_keepAliveInterval; - UInt64 m_keepAliveTime; - bool m_isLowDelayEnabled; - bool m_isKeepAliveEnabled; - }; -} - -#include - -#endif // NAZARA_TCPBASE_HPP \ No newline at end of file diff --git a/include/Nazara/Network/TcpBase.inl b/include/Nazara/Network/TcpBase.inl deleted file mode 100644 index 2a1d77d56..000000000 --- a/include/Nazara/Network/TcpBase.inl +++ /dev/null @@ -1,36 +0,0 @@ -// Copyright (C) 2015 Jérôme Leclercq -// This file is part of the "Nazara Engine - Network module" -// For conditions of distribution and use, see copyright notice in Config.hpp - -#include -#include - -namespace Nz -{ - inline TcpBase::TcpBase() : - AbstractSocket(SocketType_TCP) - { - } - - inline TcpBase::TcpBase(TcpBase&& tcpBase) : - AbstractSocket(std::move(tcpBase)), - m_state(tcpBase.m_state), - m_keepAliveInterval(tcpBase.m_keepAliveInterval), - m_keepAliveTime(tcpBase.m_keepAliveTime), - m_isLowDelayEnabled(tcpBase.m_isLowDelayEnabled), - m_isKeepAliveEnabled(tcpBase.m_isKeepAliveEnabled) - { - } - - inline bool TcpBase::IsLowDelayEnabled() const - { - return m_isLowDelayEnabled; - } - - inline bool TcpBase::IsKeepAliveEnabled() const - { - return m_isKeepAliveEnabled; - } -} - -#include diff --git a/include/Nazara/Network/TcpClient.hpp b/include/Nazara/Network/TcpClient.hpp index ce8c6a282..c3b0ccc00 100644 --- a/include/Nazara/Network/TcpClient.hpp +++ b/include/Nazara/Network/TcpClient.hpp @@ -9,17 +9,17 @@ #include #include -#include +#include #include namespace Nz { - class NAZARA_NETWORK_API TcpClient : public TcpBase + class NAZARA_NETWORK_API TcpClient : public AbstractSocket { friend class TcpServer; public: - TcpClient() = default; + inline TcpClient(); inline TcpClient(TcpClient&& tcpClient); ~TcpClient() = default; @@ -33,6 +33,9 @@ namespace Nz inline UInt64 GetKeepAliveTime() const; inline IpAddress GetRemoteAddress() const; + inline bool IsLowDelayEnabled() const; + inline bool IsKeepAliveEnabled() const; + SocketState QueryState(); bool Receive(void* buffer, std::size_t size, std::size_t* received); @@ -46,6 +49,10 @@ namespace Nz void Reset(SocketHandle handle, const IpAddress& peerAddress); IpAddress m_peerAddress; + UInt64 m_keepAliveInterval; + UInt64 m_keepAliveTime; + bool m_isLowDelayEnabled; + bool m_isKeepAliveEnabled; }; } diff --git a/include/Nazara/Network/TcpClient.inl b/include/Nazara/Network/TcpClient.inl index 6b981000b..417902035 100644 --- a/include/Nazara/Network/TcpClient.inl +++ b/include/Nazara/Network/TcpClient.inl @@ -7,9 +7,18 @@ namespace Nz { + inline TcpClient::TcpClient() : + AbstractSocket(SocketType_TCP) + { + } + inline TcpClient::TcpClient(TcpClient&& tcpClient) : - TcpBase(std::move(tcpClient)), - m_peerAddress(std::move(tcpClient.m_peerAddress)) + AbstractSocket(std::move(tcpClient)), + m_peerAddress(std::move(tcpClient.m_peerAddress)), + m_keepAliveInterval(tcpClient.m_keepAliveInterval), + m_keepAliveTime(tcpClient.m_keepAliveTime), + m_isLowDelayEnabled(tcpClient.m_isLowDelayEnabled), + m_isKeepAliveEnabled(tcpClient.m_isKeepAliveEnabled) { } @@ -32,6 +41,16 @@ namespace Nz { return m_peerAddress; } + + inline bool TcpClient::IsLowDelayEnabled() const + { + return m_isLowDelayEnabled; + } + + inline bool TcpClient::IsKeepAliveEnabled() const + { + return m_isKeepAliveEnabled; + } } #include diff --git a/include/Nazara/Network/TcpServer.hpp b/include/Nazara/Network/TcpServer.hpp index 92b8a22a7..da1b48e73 100644 --- a/include/Nazara/Network/TcpServer.hpp +++ b/include/Nazara/Network/TcpServer.hpp @@ -8,17 +8,17 @@ #define NAZARA_TCPSERVER_HPP #include -#include +#include #include namespace Nz { class TcpClient; - class NAZARA_NETWORK_API TcpServer : public TcpBase + class NAZARA_NETWORK_API TcpServer : public AbstractSocket { public: - TcpServer() = default; + inline TcpServer(); inline TcpServer(TcpServer&& tcpServer); ~TcpServer() = default; diff --git a/include/Nazara/Network/TcpServer.inl b/include/Nazara/Network/TcpServer.inl index dfcdab110..905320888 100644 --- a/include/Nazara/Network/TcpServer.inl +++ b/include/Nazara/Network/TcpServer.inl @@ -7,8 +7,13 @@ namespace Nz { + inline TcpServer::TcpServer() : + AbstractSocket(SocketType_TCP) + { + } + inline TcpServer::TcpServer(TcpServer&& tcpServer) : - TcpBase(std::move(tcpServer)), + AbstractSocket(std::move(tcpServer)), m_boundAddress(std::move(tcpServer.m_boundAddress)) { } diff --git a/src/Nazara/Network/TcpBase.cpp b/src/Nazara/Network/TcpBase.cpp deleted file mode 100644 index 3f9f173eb..000000000 --- a/src/Nazara/Network/TcpBase.cpp +++ /dev/null @@ -1,30 +0,0 @@ -// Copyright (C) 2015 Jérôme Leclercq -// This file is part of the "Nazara Engine - Utility module" -// For conditions of distribution and use, see copyright notice in Config.hpp - -#include -#include -#include -#include -#include - -#if defined(NAZARA_PLATFORM_WINDOWS) -#include -#else -#error Missing implementation: Socket -#endif - -namespace Nz -{ - void TcpBase::OnOpened() - { - AbstractSocket::OnOpened(); - - m_isLowDelayEnabled = false; //< Nagle's algorithm, is this enabled everywhere? - m_isKeepAliveEnabled = false; //< default documentation value, OS can change this (TODO: Query OS default value) - m_keepAliveInterval = 1000; //< default documentation value, OS can change this (TODO: Query OS default value) - m_keepAliveTime = 7200000; //< default documentation value, OS can change this (TODO: Query OS default value) - - ChangeState(SocketState_NotConnected); - } -} \ No newline at end of file diff --git a/src/Nazara/Network/TcpClient.cpp b/src/Nazara/Network/TcpClient.cpp index 0c41db30e..8a4c2f453 100644 --- a/src/Nazara/Network/TcpClient.cpp +++ b/src/Nazara/Network/TcpClient.cpp @@ -187,15 +187,19 @@ namespace Nz void TcpClient::OnClose() { - TcpBase::OnClose(); + AbstractSocket::OnClose(); m_peerAddress = IpAddress::Invalid; } void TcpClient::OnOpened() { - TcpBase::OnOpened(); + AbstractSocket::OnOpened(); + m_isLowDelayEnabled = false; //< Nagle's algorithm, is this enabled everywhere? + m_isKeepAliveEnabled = false; //< default documentation value, OS can change this (TODO: Query OS default value) + m_keepAliveInterval = 1000; //< default documentation value, OS can change this (TODO: Query OS default value) + m_keepAliveTime = 7200000; //< default documentation value, OS can change this (TODO: Query OS default value) m_peerAddress = IpAddress::Invalid; } diff --git a/src/Nazara/Network/TcpServer.cpp b/src/Nazara/Network/TcpServer.cpp index 5cc999f1c..2aa42956b 100644 --- a/src/Nazara/Network/TcpServer.cpp +++ b/src/Nazara/Network/TcpServer.cpp @@ -49,14 +49,14 @@ namespace Nz void TcpServer::OnClose() { - TcpBase::OnClose(); + AbstractSocket::OnClose(); m_boundAddress = IpAddress::Invalid; } void TcpServer::OnOpened() { - TcpBase::OnOpened(); + AbstractSocket::OnOpened(); m_boundAddress = IpAddress::Invalid; }