Socket read loop.

This commit is contained in:
Bartosz Taudul 2017-09-13 02:08:30 +02:00
parent 407a256e68
commit 3dd744019a
2 changed files with 17 additions and 0 deletions

View File

@ -138,6 +138,21 @@ int Socket::Recv( void* _buf, int len, const timeval* tv )
} }
} }
bool Socket::Read( void* _buf, int len, const timeval* tv, bool(*exitCb)() )
{
auto buf = (char*)_buf;
while( len > 0 )
{
if( exitCb() ) return false;
const auto sz = Recv( buf, len, tv );
len -= sz;
buf += sz;
}
return true;
}
ListenSocket::ListenSocket() ListenSocket::ListenSocket()
: m_sock( -1 ) : m_sock( -1 )

View File

@ -21,6 +21,8 @@ public:
int Send( const void* buf, int len ); int Send( const void* buf, int len );
int Recv( void* buf, int len, const timeval* tv ); int Recv( void* buf, int len, const timeval* tv );
bool Read( void* buf, int len, const timeval* tv, bool(*exitCb)() );
Socket( const Socket& ) = delete; Socket( const Socket& ) = delete;
Socket( Socket&& ) = delete; Socket( Socket&& ) = delete;
Socket& operator=( const Socket& ) = delete; Socket& operator=( const Socket& ) = delete;