[SDL] SDL_net's send
Rasmus Toftdahl Olesen
halfdan at halfdans.net
Fri Aug 11 03:39:15 PDT 2006
On Fri, 11 Aug 2006 10:42:23 +0200, Matthias Weigand <weigole at gmx.de> wrote:
> Hi,
>
> don't know if this is the right place to ask questions concerning
> SDL_net, but I'll give it a try.
>
>
> The Berkley Socket API defines the send operation in a different way
> than SDL_net does (for TCP sockets). The Socket API's send returns the
> number of bytes sent and may return less than the specified buffer size,
> which is no error. SDL_net cares about that, since it says, that there's
> an error if less bytes were returned by SDLNet_TCP_Send.
>
> The current implementation in SDL_net looks like this:
>
> do {
> len = OTSnd(sock->channel, (void *)data, left, 0);
> if (len == kOTFlowErr)
> len = 0;
> if ( len > 0 ) {
> sent += len;
> left -= len;
> data += len;
> }
> // Do we need to ?
> // ( masahiro minami<elsur at aaa.letter.co.jp> )
> // (TODO)
> //WaitNextEvent(everyEvent, &macEvent, 1, NULL);
> //AsyncTCPPopEvent(sock);
> } while ( (left > 0) && (len > 0) );
>
>
> I think it does busy waiting and will consume a lot of CPU time during a
> send operation, if the buffer exceeds the intermediate system buffer.
> Is this still subject to change? Is it even possible to not busy wait?
Yes, it certainly does busy-waiting, so unless you want to use threads you have to rely on well-behaved network-operation.
I am using the Netxx library instead, it wraps the berkeley socket API (and the Winsock API on Win32) in some nice C++ classes, the author, Peter Jones, has stopped developing it, but i maintain an arch/bazaar1 repository with my own version. So far the only change i've made is to use the autotools system rather than the Jam system that Netxx previously used:
http://dev.infonet.dk/~rto/arch/
I even made debian packages for it, if you are on such a system:
http://dev.infonet.dk/debian
Just my 5 euro cents.
More information about the SDL
mailing list