[SDL] Non-blocking calls in SDL_net?

BESTJ at Nationwide.com BESTJ at Nationwide.com
Tue Feb 24 14:19:00 PST 2004


Non-blocking TCP communication is quite common, and does not always 
require polling.  The library I am using uses events (in windows) or 
signals (in Linux) to tell me when new data is available if I want that.

I do, in fact, poll the network, though.  I do it once per game cycle. 
This is the first time I would use the events anyway, and the network poll 
is very efficient.

You can, in fact, use blocking IO and do a select() or poll() to see if 
data is ready on the connections so you don't block on the read.  To go 
into any more detail would be off topic.  I recommend "Unix network 
programming" by W. Richard Stevens.  I do not use the SDL_net library 
because it does not provide these features (Though I may be willing to add 
them if people are interested).

James Best





Bob Pendleton <bob at pendleton.com>

Sent by: sdl-admin at libsdl.org



02/23/2004 03:24 PM
Please respond to sdl

 
T
To:     SDL Mailing List <sdl at libsdl.org>
cc: 

bcc: 
Subject:        Re: [SDL] Non-blocking calls in SDL_net?


On Fri, 2004-02-20 at 04:47, Jorge Garcia wrote:
> Is there any way to make non-blocking calls in SDL_net? It seems that 
> send/receive calls wait until everything is sent or received, and you 
cannot 
> know how many bytes are available for sending/receiving before calling. 
If you 
> use socket sets and check them you are only guaranteed that one byte(?) 
is 
> available and asking for more bytes in a receive call may block the 
thread. 
> AFAIK, some socket implementations allow a non-blocking mode which is 
very handy 
> if you don't want to mess with threads.

Take a look at the net2 library at:http://gameprogrammer.com/game.html.
Even if you don't use the library, the article and code tells you how to
do what you want. And, you don't really want to use non-blocking code.
Non-blocking code makes you poll for input which leads to serious
performance and synchronization problems.

                                 Bob Pendleton

> 
>   Jorge
> 
> 
> 
> 
> _______________________________________________
> SDL mailing list
> SDL at libsdl.org
> http://www.libsdl.org/mailman/listinfo/sdl
-- 
+---------------------------------------+
+ Bob Pendleton: writer and programmer. +
+ email: Bob at Pendleton.com              +
+ web:   www.GameProgrammer.com         +
+---------------------------------------+


_______________________________________________
SDL mailing list
SDL at libsdl.org
http://www.libsdl.org/mailman/listinfo/sdl


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.libsdl.org/pipermail/sdl-libsdl.org/attachments/20040224/2737da75/attachment.htm>


More information about the SDL mailing list