Use select in Recv().

This commit is contained in:
Bartosz Taudul 2017-09-13 01:53:47 +02:00
parent 953e9c6206
commit 365f2cde23
2 changed files with 16 additions and 8 deletions

View File

@ -119,17 +119,23 @@ int Socket::Send( const void* _buf, int len )
return buf - start; return buf - start;
} }
int Socket::Recv( void* _buf, int len ) int Socket::Recv( void* _buf, int len, const timeval* tv )
{ {
auto buf = (char*)_buf; auto buf = (char*)_buf;
assert( m_sock != -1 );
int size; fd_set fds;
do FD_ZERO( &fds );
FD_SET( m_sock, &fds );
select( m_sock+1, &fds, nullptr, nullptr, tv );
if( FD_ISSET( m_sock, &fds ) )
{ {
size = recv( m_sock, buf, len, 0 ); return recv( m_sock, buf, len, 0 );
}
else
{
return -1;
} }
while( size == -1 );
return size;
} }

View File

@ -3,6 +3,8 @@
#include <memory> #include <memory>
struct timeval;
namespace tracy namespace tracy
{ {
@ -17,7 +19,7 @@ public:
void Close(); void Close();
int Send( const void* buf, int len ); int Send( const void* buf, int len );
int Recv( void* buf, int len ); int Recv( void* buf, int len, const timeval* tv );
Socket( const Socket& ) = delete; Socket( const Socket& ) = delete;
Socket( Socket&& ) = delete; Socket( Socket&& ) = delete;