mirror of
https://github.com/baldurk/renderdoc.git
synced 2026-09-24 14:45:53 +00:00
Add non-blocking recv function to Socket class
This commit is contained in:
@@ -147,6 +147,7 @@ public:
|
||||
|
||||
bool SendDataBlocking(const void *buf, uint32_t length);
|
||||
bool RecvDataBlocking(void *data, uint32_t length);
|
||||
bool RecvDataNonBlocking(void *data, uint32_t &length);
|
||||
|
||||
private:
|
||||
ptrdiff_t socket;
|
||||
|
||||
@@ -183,6 +183,38 @@ bool Socket::IsRecvDataWaiting()
|
||||
return ret > 0;
|
||||
}
|
||||
|
||||
bool Socket::RecvDataNonBlocking(void *buf, uint32_t &length)
|
||||
{
|
||||
if(length == 0)
|
||||
return true;
|
||||
|
||||
// socket is already blocking, don't have to change anything
|
||||
int ret = recv(socket, (char *)buf, length, 0);
|
||||
|
||||
if(ret > 0)
|
||||
{
|
||||
length = (uint32_t)ret;
|
||||
}
|
||||
else
|
||||
{
|
||||
length = 0;
|
||||
int err = errno;
|
||||
|
||||
if(err == EWOULDBLOCK || err == EAGAIN)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
RDCWARN("recv: %d", err);
|
||||
Shutdown();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool Socket::RecvDataBlocking(void *buf, uint32_t length)
|
||||
{
|
||||
if(length == 0)
|
||||
|
||||
@@ -184,6 +184,38 @@ bool Socket::IsRecvDataWaiting()
|
||||
return ret > 0;
|
||||
}
|
||||
|
||||
bool Socket::RecvDataNonBlocking(void *buf, uint32_t &length)
|
||||
{
|
||||
if(length == 0)
|
||||
return true;
|
||||
|
||||
// socket is already blocking, don't have to change anything
|
||||
int ret = recv(socket, (char *)buf, length, 0);
|
||||
|
||||
if(ret > 0)
|
||||
{
|
||||
length = (uint32_t)ret;
|
||||
}
|
||||
else
|
||||
{
|
||||
length = 0;
|
||||
int err = WSAGetLastError();
|
||||
|
||||
if(err == WSAEWOULDBLOCK)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
RDCWARN("recv: %d", err);
|
||||
Shutdown();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool Socket::RecvDataBlocking(void *buf, uint32_t length)
|
||||
{
|
||||
if(length == 0)
|
||||
|
||||
Reference in New Issue
Block a user