Jump to content
  • Advertisement
Sign in to follow this  
smilleme

WinSock 1.1 problem

This topic is 4852 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

Hi there! I use WinSock version 1.1 and I have simply problem. How can I test if some data are on port? Beacouse if I try receive data from server and stream is empty my application freeze for half minute.

Share this post


Link to post
Share on other sites
Advertisement
You can use the select() function with a TIMEVAL of {0, 0} to check if data is on a socket, or you can use non-blocking sockets so the recv() returns immediately.

Share this post


Link to post
Share on other sites
Quote:
Original post by SiCrane
You can use the select() function with a TIMEVAL of {0, 0} to check if data is on a socket, or you can use non-blocking sockets so the recv() returns immediately.


is this code right? If I used it, it returned only true


bool next_data(SOCKET * theSocket)
{
fd_set ready;
struct timeval to;
FD_ZERO(&ready);
FD_SET(*theSocket, &ready);
to.tv_sec = 0;
to.tv_usec = 0;

if (select(*theSocket, &ready, 0, 0, &to) < 0) return false;

return true;
}

Share this post


Link to post
Share on other sites
The return value for select() is 0 if the operation timed out, the number of socket handles that are ready if the operation didn't time out or SOCKET_ERROR if there is a problem. Right now your function doesn't seem to be checking for any of those values.

You can try using FD_ISSET() for your socket that you want to check for data on instead of relying on the return value of select, and then only check the return value against SOCKET_ERROR.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • 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!