Network/TcpClient: Fix LowDelay

Former-commit-id: 70fc4224ae7f8913e27a3a3cf234500db262f73c
This commit is contained in:
Lynix 2015-11-12 13:19:21 +01:00
parent a26c979d84
commit 81221fbf0b
3 changed files with 22 additions and 2 deletions

View File

@ -75,7 +75,7 @@ namespace Nz
if (m_isLowDelayEnabled != lowDelay) if (m_isLowDelayEnabled != lowDelay)
{ {
SocketImpl::SetBlocking(m_handle, lowDelay, &m_lastError); SocketImpl::SetNoDelay(m_handle, lowDelay, &m_lastError);
m_isLowDelayEnabled = lowDelay; m_isLowDelayEnabled = lowDelay;
} }
} }
@ -238,7 +238,7 @@ namespace Nz
SocketState newState = SocketImpl::Connect(m_handle, m_peerAddress, msTimeout, &m_lastError); SocketState newState = SocketImpl::Connect(m_handle, m_peerAddress, msTimeout, &m_lastError);
NazaraAssert(newState != SocketState_Connecting, "Invalid internal return"); NazaraAssert(newState != SocketState_Connecting, "Invalid internal return");
// Prevent valid peer adddress in non-connected state // Prevent valid peer address in non-connected state
if (newState == SocketState_NotConnected) if (newState == SocketState_NotConnected)
m_peerAddress = IpAddress::Invalid; m_peerAddress = IpAddress::Invalid;

View File

@ -534,6 +534,25 @@ namespace Nz
return true; return true;
} }
bool SocketImpl::SetNoDelay(SocketHandle handle, bool nodelay, SocketError* error)
{
NazaraAssert(handle != InvalidHandle, "Invalid handle");
BOOL option = nodelay;
if (setsockopt(handle, IPPROTO_TCP, TCP_NODELAY, reinterpret_cast<const char*>(&option), sizeof(option)) == SOCKET_ERROR)
{
if (error)
*error = TranslateWSAErrorToSocketError(WSAGetLastError());
return false; //< Error
}
if (error)
*error = SocketError_NoError;
return true;
}
SocketError SocketImpl::TranslateWSAErrorToSocketError(int error) SocketError SocketImpl::TranslateWSAErrorToSocketError(int error)
{ {
switch (error) switch (error)

View File

@ -48,6 +48,7 @@ namespace Nz
static bool SetBlocking(SocketHandle handle, bool blocking, SocketError* error = nullptr); static bool SetBlocking(SocketHandle handle, bool blocking, SocketError* error = nullptr);
static bool SetKeepAlive(SocketHandle handle, bool enabled, UInt64 msTime, UInt64 msInterval, SocketError* error = nullptr); static bool SetKeepAlive(SocketHandle handle, bool enabled, UInt64 msTime, UInt64 msInterval, SocketError* error = nullptr);
static bool SetNoDelay(SocketHandle handle, bool nodelay, SocketError* error = nullptr);
static SocketError TranslateWSAErrorToSocketError(int error); static SocketError TranslateWSAErrorToSocketError(int error);
static int TranslateNetProtocolToAF(NetProtocol protocol); static int TranslateNetProtocolToAF(NetProtocol protocol);