Implement checking if there's data to read on the socket.

This commit is contained in:
Bartosz Taudul 2017-09-14 01:12:27 +02:00
parent d999f35dfa
commit b1fcf88cf4
2 changed files with 14 additions and 0 deletions

View File

@ -162,6 +162,19 @@ bool Socket::Read( void* _buf, int len, const timeval* tv, bool(*exitCb)() )
return true; return true;
} }
bool Socket::HasData()
{
struct timeval tv;
memset( &tv, 0, sizeof( tv ) );
fd_set fds;
FD_ZERO( &fds );
FD_SET( m_sock, &fds );
select( m_sock+1, &fds, nullptr, nullptr, &tv );
return FD_ISSET( m_sock, &fds );
}
ListenSocket::ListenSocket() ListenSocket::ListenSocket()
: m_sock( -1 ) : m_sock( -1 )

View File

@ -22,6 +22,7 @@ public:
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)() ); bool Read( void* buf, int len, const timeval* tv, bool(*exitCb)() );
bool HasData();
Socket( const Socket& ) = delete; Socket( const Socket& ) = delete;
Socket( Socket&& ) = delete; Socket( Socket&& ) = delete;