Sign in to follow this  

winsock non-blocking sockets w/o using WSAAsynchSelect

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

possible? I need a non blocking socket, and I do NOT want to receive socket events in my message pump. I can't use select() because it blocks. I'll spin in my mainloop, checking every frame to see if the socket has data. I can't find any information about how to do this.

Share this post


Link to post
Share on other sites
The docs said that setting the select timeout to 0 meant that it would block. Setting the timeout to a small nonzero value seems wasteful.

MSDN:
Quote:
timeout

Maximum time for select to wait, provided in the form of a TIMEVAL structure. Set the timeout parameter to null for blocking operations.

Share this post


Link to post
Share on other sites
Quote:
Original post by thedustbustr
The docs said that setting the select timeout to 0 meant that it would block. Setting the timeout to a small nonzero value seems wasteful.

MSDN:
Quote:
timeout

Maximum time for select to wait, provided in the form of a TIMEVAL structure. Set the timeout parameter to null for blocking operations.


No, the docs said that setting the select timeout to NULL meant that it would block.

This parameter is a pointer to a TIMEVAL struct, so just pass a TIMEVAL struct with both fields set to 0

MSDN Remarks:
Quote:

If TIMEVAL is initialized to {0, 0}, select will return immediately

Share this post


Link to post
Share on other sites
Hey thedustbustr,

If you do this in your code it turns off blocking.

u_long iMode = 1;
ioctlsocket(socket,FIONBIO,&iMode);

And then just have a loop like you said. This is how I do it and it works awesome for me.

I believe this is exactly what you are asking for in your first post.

Also, I normally use a timer within my loop to delay playing with the sockets. Because if your game runs at 1000fps you'll be eating up bandwidth big time. I would check every 10th of a second or so, depending on what you are doing in your app.

Hope this helps. Let me know if you need more info if this is the way you want to go.

Share this post


Link to post
Share on other sites

This topic is 3722 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.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this