Jump to content

  • Log In with Google      Sign In   
  • Create Account

We're offering banner ads on our site from just $5!

1. Details HERE. 2. GDNet+ Subscriptions HERE. 3. Ad upload HERE.


winsock non-blocking sockets w/o using WSAAsynchSelect


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
5 replies to this topic

#1 thedustbustr   Members   -  Reputation: 191

Like
0Likes
Like

Posted 09 October 2007 - 05:23 AM

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.

Sponsor:

#2 thedustbustr   Members   -  Reputation: 191

Like
0Likes
Like

Posted 09 October 2007 - 05:34 AM

The alternative is to put the blocking sockets in their own threads but I want to avoid that if possible.

#3 hplus0603   Moderators   -  Reputation: 5537

Like
0Likes
Like

Posted 09 October 2007 - 05:46 AM

Quote:
I can't use select() because it blocks.


I recommend reading the select() documentation again. Hint: select() takes a "timeout" parameter, which can be set to a very small number (such as 0).

#4 thedustbustr   Members   -  Reputation: 191

Like
0Likes
Like

Posted 09 October 2007 - 05:59 AM

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.


#5 Leandro GR   Members   -  Reputation: 533

Like
0Likes
Like

Posted 09 October 2007 - 06:15 AM

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


#6 DarkRonin   Members   -  Reputation: 613

Like
0Likes
Like

Posted 09 October 2007 - 11:03 PM

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.




Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS