From 365f2cde23d31cca311f415a6c33422253769916 Mon Sep 17 00:00:00 2001 From: Bartosz Taudul Date: Wed, 13 Sep 2017 01:53:47 +0200 Subject: [PATCH] Use select in Recv(). --- common/TracySocket.cpp | 20 +++++++++++++------- common/TracySocket.hpp | 4 +++- 2 files changed, 16 insertions(+), 8 deletions(-) diff --git a/common/TracySocket.cpp b/common/TracySocket.cpp index 1122a1f7..f3d8a8d1 100755 --- a/common/TracySocket.cpp +++ b/common/TracySocket.cpp @@ -119,17 +119,23 @@ int Socket::Send( const void* _buf, int len ) return buf - start; } -int Socket::Recv( void* _buf, int len ) +int Socket::Recv( void* _buf, int len, const timeval* tv ) { auto buf = (char*)_buf; - assert( m_sock != -1 ); - int size; - do + + fd_set fds; + 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; } diff --git a/common/TracySocket.hpp b/common/TracySocket.hpp index 099f66cb..e191bae4 100755 --- a/common/TracySocket.hpp +++ b/common/TracySocket.hpp @@ -3,6 +3,8 @@ #include +struct timeval; + namespace tracy { @@ -17,7 +19,7 @@ public: void Close(); 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( Socket&& ) = delete;