mirror of
https://github.com/baldurk/renderdoc.git
synced 2026-07-09 01:00:51 +00:00
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:
@@ -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;
|
||||
|
||||
@@ -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)
|
||||
{
|
||||
|
||||
@@ -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;
|
||||
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user