diff --git a/common/TracySocket.cpp b/common/TracySocket.cpp index 8256f93d..07ed3cab 100644 --- a/common/TracySocket.cpp +++ b/common/TracySocket.cpp @@ -351,6 +351,24 @@ int Socket::Recv( void* _buf, int len, int timeout ) } } +int Socket::ReadUpTo( void* _buf, int len, int timeout ) +{ + const auto sock = m_sock.load( std::memory_order_relaxed ); + auto buf = (char*)_buf; + + int rd = 0; + while( len > 0 ) + { + const auto res = recv( sock, buf, len, 0 ); + if( res == 0 ) break; + if( res == -1 ) return -1; + len -= res; + rd += res; + buf += res; + } + return rd; +} + bool Socket::Read( void* buf, int len, int timeout ) { auto cbuf = (char*)buf; diff --git a/common/TracySocket.hpp b/common/TracySocket.hpp index 60c90f2c..bb4bd3f9 100644 --- a/common/TracySocket.hpp +++ b/common/TracySocket.hpp @@ -30,6 +30,7 @@ public: int Send( const void* buf, int len ); int GetSendBufSize(); + int ReadUpTo( void* buf, int len, int timeout ); bool Read( void* buf, int len, int timeout ); template