Network: Add SocketPoller class

Former-commit-id: 86b9266d904551d19e7ec8e8d6bbe5f137e8d29f [formerly 34575937d84f796cfe36a5ab97ea1f787c1506ba] [formerly 6c8c621523800958ad38eef118fcb3687c34b367 [formerly a1f1330fbe6f990a21bbe6dccfe727edec0e2b44]]
Former-commit-id: 6635c463a753f744b835267181b51ed89620b627 [formerly 14e84c7155cd669ac20a5492e67704059a442925]
Former-commit-id: 7becccdf2d8aac7cdf526d855215d7d144be284c
This commit is contained in:
Lynix
2016-09-22 18:16:39 +02:00
parent 0a656ca398
commit 9452b98f49
13 changed files with 667 additions and 0 deletions

View File

@@ -415,6 +415,34 @@ namespace Nz
return IpAddressImpl::FromSockAddr(reinterpret_cast<sockaddr*>(nameBuffer.data()));
}
int SocketImpl::Poll(PollSocket* fdarray, std::size_t nfds, int timeout, SocketError* error)
{
NazaraAssert(fdarray && nfds > 0, "Invalid fdarray");
#if NAZARA_NETWORK_POLL_SUPPORT
static_assert(sizeof(PollSocket) == sizeof(WSAPOLLFD), "PollSocket size must match WSAPOLLFD size");
int result = WSAPoll(reinterpret_cast<WSAPOLLFD*>(fdarray), static_cast<ULONG>(nfds), timeout);
if (result == SOCKET_ERROR)
{
int errorCode = WSAGetLastError();
if (error)
*error = TranslateWSAErrorToSocketError(errorCode);
return 0;
}
if (error)
*error = SocketError_NoError;
return result;
#else
if (error)
*error = SocketError_NotSupported;
return 0;
#endif
}
bool SocketImpl::Receive(SocketHandle handle, void* buffer, int length, int* read, SocketError* error)
{