Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

Squat

Sockets - pending data with recv(...)

This topic is 5479 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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

Share this post


Link to post
Share on other sites
Advertisement
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....
}

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!