Add an optional timeout to Socket::AcceptClient

* This is needed since sometimes on tests a localhost socket won't immediately
  be available to accept()
This commit is contained in:
baldurk
2019-01-17 17:51:07 +00:00
parent 5d9d77f361
commit d64ad19f16
6 changed files with 18 additions and 10 deletions
+1 -1
View File
@@ -895,7 +895,7 @@ void RenderDoc::BecomeRemoteServer(const char *listenhost, uint16_t port,
while(!killReplay())
{
Network::Socket *client = sock->AcceptClient(false);
Network::Socket *client = sock->AcceptClient(0);
if(activeClientData && activeClientData->killServer)
break;
+1 -1
View File
@@ -377,7 +377,7 @@ void RenderDoc::TargetControlServerThread(Network::Socket *sock)
while(!RenderDoc::Inst().m_TargetControlThreadShutdown)
{
Network::Socket *client = sock->AcceptClient(false);
Network::Socket *client = sock->AcceptClient(0);
if(client == NULL)
{
+1 -1
View File
@@ -166,7 +166,7 @@ public:
uint32_t GetTimeout() const { return timeoutMS; }
void SetTimeout(uint32_t milliseconds) { timeoutMS = milliseconds; }
Socket *AcceptClient(bool wait);
Socket *AcceptClient(uint32_t timeoutMilliseconds);
uint32_t GetRemoteIP() const;
+7 -3
View File
@@ -100,7 +100,7 @@ bool Socket::Connected() const
return (int)socket != -1;
}
Socket *Socket::AcceptClient(bool wait)
Socket *Socket::AcceptClient(uint32_t timeoutMilliseconds)
{
do
{
@@ -125,8 +125,12 @@ Socket *Socket::AcceptClient(bool wait)
Shutdown();
}
Threading::Sleep(4);
} while(wait);
const uint32_t sleeptime = 4;
Threading::Sleep(sleeptime);
timeoutMilliseconds = RDCMIN(0U, timeoutMilliseconds - sleeptime);
} while(timeoutMilliseconds);
return NULL;
}
+7 -3
View File
@@ -115,7 +115,7 @@ uint32_t Socket::GetRemoteIP() const
return ntohl(addr.sin_addr.s_addr);
}
Socket *Socket::AcceptClient(bool wait)
Socket *Socket::AcceptClient(uint32_t timeoutMilliseconds)
{
do
{
@@ -140,8 +140,12 @@ Socket *Socket::AcceptClient(bool wait)
Shutdown();
}
Threading::Sleep(4);
} while(wait);
const uint32_t sleeptime = 4;
Threading::Sleep(sleeptime);
timeoutMilliseconds = RDCMIN(0U, timeoutMilliseconds - sleeptime);
} while(timeoutMilliseconds);
return NULL;
}
+1 -1
View File
@@ -115,7 +115,7 @@ TEST_CASE("Test stream I/O operations over the network", "[streamio][network]")
REQUIRE(sender);
Network::Socket *receiver = server->AcceptClient(false);
Network::Socket *receiver = server->AcceptClient(50);
REQUIRE(receiver);