SDL_net's send

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?

Thanks for help!
Matthias

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.On Fri, 11 Aug 2006 10:42:23 +0200, Matthias Weigand 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?

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?

Thanks for help!
Matthias

Yep, that looks like a busy wait. But, it isn’t that much of one. My
experience is that it will rarely ever wait and when it does it will
only go through the loop a few times.

OTOH, based on experience with SDL_Net it is my humble opinion that
there are several features that need to be added. I’d even be willing to
work on it, but I can’t (don’t have the hardware) do anything on the Mac
and fixing SDL_Net only on Linux and Windows just doesn’t cut it.

	Bob PendletonOn Fri, 2006-08-11 at 10:42 +0200, Matthias Weigand wrote:

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