Network/SocketPoller: Wait() now returns the number of active sockets, and optionally the last error
It will also ignore the EINTR error on Linux
This commit is contained in:
@@ -467,7 +467,7 @@ namespace Nz
|
||||
return code;
|
||||
}
|
||||
|
||||
int SocketImpl::Poll(PollSocket* fdarray, std::size_t nfds, int timeout, SocketError* error)
|
||||
unsigned int SocketImpl::Poll(PollSocket* fdarray, std::size_t nfds, int timeout, SocketError* error)
|
||||
{
|
||||
NazaraAssert(fdarray && nfds > 0, "Invalid fdarray");
|
||||
|
||||
@@ -484,10 +484,12 @@ namespace Nz
|
||||
return 0;
|
||||
}
|
||||
|
||||
assert(result >= 0);
|
||||
|
||||
if (error)
|
||||
*error = SocketError_NoError;
|
||||
|
||||
return result;
|
||||
return static_cast<unsigned int>(result);
|
||||
#else
|
||||
NazaraUnused(fdarray);
|
||||
NazaraUnused(nfds);
|
||||
|
||||
@@ -60,7 +60,7 @@ namespace Nz
|
||||
static IpAddress QuerySocketAddress(SocketHandle handle, SocketError* error = nullptr);
|
||||
static std::size_t QuerySendBufferSize(SocketHandle handle, SocketError* error = nullptr);
|
||||
|
||||
static int Poll(PollSocket* fdarray, std::size_t nfds, int timeout, SocketError* error);
|
||||
static unsigned int Poll(PollSocket* fdarray, std::size_t nfds, int timeout, SocketError* error);
|
||||
|
||||
static bool Receive(SocketHandle handle, void* buffer, int length, int* read, SocketError* error);
|
||||
static bool ReceiveFrom(SocketHandle handle, void* buffer, int length, IpAddress* from, int* read, SocketError* error);
|
||||
|
||||
@@ -130,9 +130,9 @@ namespace Nz
|
||||
#endif
|
||||
}
|
||||
|
||||
int SocketPollerImpl::Wait(int msTimeout, SocketError* error)
|
||||
unsigned int SocketPollerImpl::Wait(int msTimeout, SocketError* error)
|
||||
{
|
||||
int activeSockets;
|
||||
unsigned int activeSockets;
|
||||
|
||||
#if NAZARA_NETWORK_POLL_SUPPORT
|
||||
activeSockets = SocketImpl::Poll(m_sockets.data(), m_sockets.size(), static_cast<int>(msTimeout), error);
|
||||
@@ -187,8 +187,8 @@ namespace Nz
|
||||
tv.tv_sec = static_cast<long>(msTimeout / 1000ULL);
|
||||
tv.tv_usec = static_cast<long>((msTimeout % 1000ULL) * 1000ULL);
|
||||
|
||||
activeSockets = ::select(0xDEADBEEF, readSet, writeSet, nullptr, (msTimeout >= 0) ? &tv : nullptr); //< The first argument is ignored on Windows
|
||||
if (activeSockets == SOCKET_ERROR)
|
||||
int selectValue = ::select(0xDEADBEEF, readSet, writeSet, nullptr, (msTimeout >= 0) ? &tv : nullptr); //< The first argument is ignored on Windows
|
||||
if (selectValue == SOCKET_ERROR)
|
||||
{
|
||||
if (error)
|
||||
*error = SocketImpl::TranslateWSAErrorToSocketError(WSAGetLastError());
|
||||
@@ -196,6 +196,9 @@ namespace Nz
|
||||
return 0;
|
||||
}
|
||||
|
||||
assert(selectValue >= 0);
|
||||
activeSockets = static_cast<unsigned int>(selectValue);
|
||||
|
||||
if (error)
|
||||
*error = SocketError_NoError;
|
||||
#endif
|
||||
|
||||
@@ -32,7 +32,7 @@ namespace Nz
|
||||
bool RegisterSocket(SocketHandle socket, SocketPollEventFlags eventFlags);
|
||||
void UnregisterSocket(SocketHandle socket);
|
||||
|
||||
int Wait(int msTimeout, SocketError* error);
|
||||
unsigned int Wait(int msTimeout, SocketError* error);
|
||||
|
||||
private:
|
||||
#if NAZARA_NETWORK_POLL_SUPPORT
|
||||
|
||||
Reference in New Issue
Block a user