Archived

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

Cybertron

Non-blocking winsock questions

Recommended Posts

Could I use the iocrtl function to check for data instead of select??? That is all select does and makes the code cumbersome using those FD lists Also will recv still block if there is no data available?

Share this post


Link to post
Share on other sites
Isn''t ioctl() used to set socket properties?

And uhhhhh, non-blocking sockets won''t block on recv. That''s the whole point. It returns 10035 (WSAEWOULDBLOCK).

Share this post


Link to post
Share on other sites
It can also get the number of bytes available to read. I use this already to make sure I have enough data to read a whole packet

The only thing I am doing for a non blocking server is using select, could I check for data myself instead of using those awful FD lists?

Share this post


Link to post
Share on other sites
Peeking like that won't work as soon as you have packets of different sizes, so I wouldn't use peeking at all. It basically tells you how many bytes are in the incoming buffer, right? Bite the bullet and read in data as a stream (because it is a stream to begin with) and organize it into packets as it comes in. When there's enough data (according to your packet header), you have a complete packet. Takes more work to implement that, but it's infinitely more flexible.

As for select, well I'm using non-blocking sockets too and the only use I have for select is to check how the non-blocking connect() returned.

[edited by - foofightr on August 14, 2003 9:06:05 PM]

Share this post


Link to post
Share on other sites
What do you mean ''as a stream''? I wait for enough data for the packet header then read the data as it comes in

This isn''t for a game too, its like a proxy server

Share this post


Link to post
Share on other sites
What kind of proxy server is it? HTTP? SOCKS? Or just a connection bouncer (which forwards ALL data from one source IP and source port to one other IP and port)? Just curious.

Share this post


Link to post
Share on other sites