Advertisement

Data pending... please read

Started by July 30, 2003 01:17 AM
3 comments, last by ShmeeBegek 21 years, 6 months ago
I am trying to avoid multithreading in my program (no, I can''t use any WINAPI sync stuff) and it would be very convenient to be able to find out how many bytes are pending, or just if there are any pending or not. Does anyone know how to do this with Winsock? Really I just need to know IF there are any pending, but how many is good aswell. Thanks, ~SPH
AIM ME: aGaBoOgAmOnGeR
DWORD YourSocketClass::BytesPending() const
{
DWORD dwPending = 0;
if( m_hSocket != INVALID_SOCKET )
ioctlsocket( m_hSocket, FIONREAD, &dwPending );//this is the interesting line
return( dwPending );
};
Darkhaven Beta-test stage coming soon.
Advertisement

Thanks, but I eventually found that I could use the select function to do it, is there an advantage to using ioctlsocket ?

~SPH

AIM ME: aGaBoOgAmOnGeR
quote:
Thanks, but I eventually found that I could use the select function to do it, is there an advantage to using ioctlsocket ?

Yes, the ioctl can be used for a single specific socket with less overhead compared to using select() for a single socket. When using select, keep in mind that it is implemented differently on Windows than on other systems. This could lead to performance problems in porting to different platforms.

Ah thanks, I''ll change my code to use ioclsocket instead .

Thanks, ~SPH

AIM ME: aGaBoOgAmOnGeR

This topic is closed to new replies.

Advertisement