Sockets - pending data with recv(...)
Is there a way to check if there is any data awaiting to be received with recv(...) ?
I don''t want my program to wait for data. I need to check if there is any data to receive as quick as possible.
=================================
Ignorance is the root of all evil
nevermind, I found some code that can poll the sockets. I still have to figure out how it works lol
Here is what i found:
int status;
TIMEVAL timeVal;
timeVal.tv_sec = 0;
timeVal.tv_usec = 0;
fd_set readSet;
readSet.fd_count = 1;
readSet.fd_array[ 0 ] = mySocket;
status = select( mySocket + 1, &readSet, 0, 0, &timeVal );
if ( status > 0 )
{
recv....
}
Here is what i found:
int status;
TIMEVAL timeVal;
timeVal.tv_sec = 0;
timeVal.tv_usec = 0;
fd_set readSet;
readSet.fd_count = 1;
readSet.fd_array[ 0 ] = mySocket;
status = select( mySocket + 1, &readSet, 0, 0, &timeVal );
if ( status > 0 )
{
recv....
}
Yes, what you found there will work. Looks like you might already have this but if not...
http://www.ecst.csuchico.edu/~beej/guide/net/html/
That''s pretty much the best sockets tutorial you will find on the net. Has a good section on non-blocking sockets with select which is what you are looking for. Keep in mind though that polling a socket in this manner will consume clock cycles so be sure to plan for that in your design or figure out another way of doing things. I don''t know what you are doing so i can''t offer any advice there.
Webby
http://www.ecst.csuchico.edu/~beej/guide/net/html/
That''s pretty much the best sockets tutorial you will find on the net. Has a good section on non-blocking sockets with select which is what you are looking for. Keep in mind though that polling a socket in this manner will consume clock cycles so be sure to plan for that in your design or figure out another way of doing things. I don''t know what you are doing so i can''t offer any advice there.
Webby
just a proxy that can handle authentications as well in a secure manner. Thats why i need it to be fast. I don''t care too much for cpu usage - just connection speed
If its a graphical client you can look at WSAAsyncSelect(). select() isn''t too good on Windows for speed if you have lots of sockets to check.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement