Non-blocking calls in SDL_net?

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.

Jorge

what i do is when i sent a some info, i my network clases attach a header,
that tells how many bytes are following… i have only used this on tcp/ip
and it seems to work fine so far.-------------------------------
Fabian “SupaGu” Mathews

From: gdl@ac.uma.es (Jorge Garcia)
Reply-To: sdl at libsdl.org
To: sdl at libsdl.org
Subject: [SDL] Non-blocking calls in SDL_net?
Date: Fri, 20 Feb 2004 10:47:14 +0000 (UTC)

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.

Jorge


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


Add photos to your messages with MSN 8. Get 2 months FREE*.
http://join.msn.com/?page=features/featuredemail

As far as I know that’s impossible if you use TCP. But UDP calls are
non-blocking.
I have used TCP in a separate thread, BTW…

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.

Jorge


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

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 PendletonOn Fri, 2004-02-20 at 04:47, Jorge Garcia wrote:

Jorge


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

±--------------------------------------+

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

Sent by: sdl-admin at libsdl.org

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

TTo: SDL Mailing List
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

±--------------------------------------+


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

It’s rather easy to emulate non blocking
connections… simply create a seperate thread that
reads (blocking), stores the data in a buffer, and
sets variables indicating that the data has been
indeed read/how much/etc…

Non-blocking TCP where you have to wait for large
ammounts of data at the same time I think could also
pose a buffer problem… aka you can’t do your read
until you have all of the 8MB structure they’re
sending, but the OS buffer only holds 4MB. Instant
deadlock.

Just a thought. Personally, I’d implement the
interpretation within the reading thread as well…
aka for a game, assuming you use messages of some sort
to communicate player actions, the read thread could
assemble the messages into appropraite structures, to
be put in a que such as std::que< mygame::net::message

  • .

Just my thoughts.

— BESTJ at Nationwide.com wrote:> 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

Sent by: sdl-admin at libsdl.org

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

T
To: SDL Mailing List
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

±--------------------------------------+


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


Do you Yahoo!?
Yahoo! Mail SpamGuard - Read only the mail you want.
http://antispam.yahoo.com/tools

Thank you very much (all of you who replied). I still don’t know what to do, but
now I have other points of view.

Jorge