[General]: Cleanup the code (#713)
This commit is contained in:
parent
022be7ff90
commit
62133aa505
@ -5,38 +5,37 @@ namespace Components
|
|||||||
{
|
{
|
||||||
namespace FrameTime
|
namespace FrameTime
|
||||||
{
|
{
|
||||||
void NetSleep(int mSec)
|
void NetSleep(int ms)
|
||||||
{
|
{
|
||||||
if (mSec < 0) mSec = 0;
|
if (ms < 0) ms = 0;
|
||||||
|
|
||||||
fd_set fdr;
|
fd_set fdr;
|
||||||
FD_ZERO(&fdr);
|
FD_ZERO(&fdr);
|
||||||
|
|
||||||
auto highestFd = INVALID_SOCKET;
|
auto maxfd = INVALID_SOCKET;
|
||||||
if (*Game::ip_socket != INVALID_SOCKET)
|
if (*Game::ip_socket != INVALID_SOCKET)
|
||||||
{
|
{
|
||||||
FD_SET(*Game::ip_socket, &fdr);
|
FD_SET(*Game::ip_socket, &fdr);
|
||||||
highestFd = *Game::ip_socket;
|
maxfd = *Game::ip_socket;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (highestFd == INVALID_SOCKET)
|
if (maxfd == INVALID_SOCKET)
|
||||||
{
|
{
|
||||||
// windows ain't happy when select is called without valid FDs
|
// On Windows, select fails if no sockets
|
||||||
std::this_thread::sleep_for(std::chrono::milliseconds(mSec));
|
Game::Sys_Sleep(ms);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
timeval timeout;
|
timeval tv = { ms / 1000, (ms % 1000) * 1000 };
|
||||||
timeout.tv_sec = mSec / 1000;
|
const auto result = ::select(maxfd + 1, &fdr, nullptr, nullptr, &tv);
|
||||||
timeout.tv_usec = (mSec % 1000) * 1000;
|
|
||||||
|
|
||||||
const auto retVal = ::select(highestFd + 1, &fdr, nullptr, nullptr, &timeout);
|
if (result == SOCKET_ERROR)
|
||||||
|
|
||||||
if (retVal == SOCKET_ERROR)
|
|
||||||
{
|
{
|
||||||
Logger::Warning(Game::CON_CHANNEL_SYSTEM, "WinAPI: select failed: {}\n", Game::NET_ErrorString());
|
Logger::Warning(Game::CON_CHANNEL_SYSTEM, "WinAPI: select failed: {}\n", Game::NET_ErrorString());
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
else if (retVal > 0)
|
|
||||||
|
if (result > 0)
|
||||||
{
|
{
|
||||||
if (Dedicated::IsRunning())
|
if (Dedicated::IsRunning())
|
||||||
{
|
{
|
||||||
|
Loading…
Reference in New Issue
Block a user