Skip to content

Commit

Permalink
Network/SocketImpl: Add query methods
Browse files Browse the repository at this point in the history
I'm still not sure I will use them
  • Loading branch information
SirLynix committed Nov 16, 2015
1 parent 1cb2048 commit 41333fe
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 0 deletions.
57 changes: 57 additions & 0 deletions src/Nazara/Network/Win32/SocketImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,44 @@ namespace Nz
return availableBytes;
}

bool SocketImpl::QueryBroadcasting(SocketHandle handle, SocketError* error)
{
BOOL code;
int codeLength = sizeof(code);

if (getsockopt(handle, SOL_SOCKET, SO_BROADCAST, reinterpret_cast<char*>(&code), &codeLength) == SOCKET_ERROR)
{
if (error)
*error = TranslateWSAErrorToSocketError(WSAGetLastError());

return false;
}

if (error)
*error = SocketError_NoError;

return code == TRUE;
}

bool SocketImpl::QueryKeepAlive(SocketHandle handle, SocketError* error)
{
BOOL code;
int codeLength = sizeof(code);

if (getsockopt(handle, SOL_SOCKET, SO_KEEPALIVE, reinterpret_cast<char*>(&code), &codeLength) == SOCKET_ERROR)
{
if (error)
*error = TranslateWSAErrorToSocketError(WSAGetLastError());

return false;
}

if (error)
*error = SocketError_NoError;

return code == TRUE;
}

unsigned int SocketImpl::QueryMaxDatagramSize(SocketHandle handle, SocketError* error)
{
unsigned int code;
Expand All @@ -294,6 +332,25 @@ namespace Nz
return code;
}

bool SocketImpl::QueryNoDelay(SocketHandle handle, SocketError* error)
{
BOOL code;
int codeLength = sizeof(code);

if (getsockopt(handle, IPPROTO_TCP, TCP_NODELAY, reinterpret_cast<char*>(&code), &codeLength) == SOCKET_ERROR)
{
if (error)
*error = TranslateWSAErrorToSocketError(WSAGetLastError());

return false;
}

if (error)
*error = SocketError_NoError;

return code == TRUE;
}

IpAddress SocketImpl::QueryPeerAddress(SocketHandle handle, SocketError* error)
{
NazaraAssert(handle != InvalidHandle, "Invalid handle");
Expand Down
3 changes: 3 additions & 0 deletions src/Nazara/Network/Win32/SocketImpl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,10 @@ namespace Nz
static SocketState Listen(SocketHandle handle, const IpAddress& address, unsigned queueSize, SocketError* error);

static unsigned int QueryAvailableBytes(SocketHandle handle, SocketError* error = nullptr);
static bool QueryBroadcasting(SocketHandle handle, SocketError* error = nullptr);
static bool QueryKeepAlive(SocketHandle handle, SocketError* error = nullptr);
static unsigned int QueryMaxDatagramSize(SocketHandle handle, SocketError* error = nullptr);
static bool QueryNoDelay(SocketHandle handle, SocketError* error = nullptr);
static IpAddress QueryPeerAddress(SocketHandle handle, SocketError* error = nullptr);
static IpAddress QuerySocketAddress(SocketHandle handle, SocketError* error = nullptr);

Expand Down

0 comments on commit 41333fe

Please sign in to comment.