(!OT) implemetation problem - help!

Hi

I want to write program that is interface between network protocol (rfb)
and SLD library. I don’t know how to mantain connection and receive SDL
events at the same time.

Program should wait for network data and still be able to dispatch events
from the library. It seems that SDL is not flexible enough…

Polling is not acceptable. Program should do nothing when it has nothing
to do.

Have I overlook something or it’s SDL design bug?

JB

Hello Jan,

You could use a separate thread to collect net input. If you're

blocked in a socket read, this won’t affect other events (only the
thread reading socket is blocked). It will ad 2 lines of code to your
program.

                      Franck.

Jan Bobrowski wrote:>

Hi

I want to write program that is interface between network protocol (rfb)
and SLD library. I don’t know how to mantain connection and receive SDL
events at the same time.

Program should wait for network data and still be able to dispatch events
from the library. It seems that SDL is not flexible enough…

Polling is not acceptable. Program should do nothing when it has nothing
to do.

Have I overlook something or it’s SDL design bug?

JB

Hello Jan,

You could use a separate thread to collect net input. If you're

blocked in a socket read, this won’t affect other events (only the
thread reading socket is blocked). It will ad 2 lines of code to your
program.

                      Franck.

OK. But how can I notify main thread that there’s something to do.
Main thread will likely sleep waiting for next SDL event. According
to SDL docs I can’t do anything (SDL funcs) in a separate thread
(in this case thread that collects net input).

JBOn Tue, 15 Feb 2000, Franck Guillaud wrote:

OK. But how can I notify main thread that there’s something to do.
Main thread will likely sleep waiting for next SDL event. According
to SDL docs I can’t do anything (SDL funcs) in a separate thread
(in this case thread that collects net input).

You can post messages to the main thread, using SDL_PushEvent()

From the SDL 1.1 WhatsNew file:

    Added user-defined event type:
            typedef struct {
                    Uint8 type;
                    int code;
                    void *data1;
                    void *data2;
            } SDL_UserEvent;
    This structure is in the "user" member of an SDL_Event.

    Added a function to push events into the event queue:
            SDL_PushEvent()

    Example of using the new SDL user-defined events:
    {
            SDL_Event event;

            event.type = SDL_USEREVENT;
            event.user.code = my_event_code;
            event.user.data1 = significant_data;
            event.user.data2 = 0;
            SDL_PushEvent(&event);
    }

See ya!
-Sam Lantinga (slouken at devolution.com)

Lead Programmer, Loki Entertainment Software–
“Any sufficiently advanced bug is indistinguishable from a feature”
– Rich Kulawiec

You could use a separate thread to collect net input. If you're

blocked in a socket read, this won’t affect other events (only the
thread reading socket is blocked). It will ad 2 lines of code to your
program.

                      Franck.

OK. But how can I notify main thread that there’s something to do.
Main thread will likely sleep waiting for next SDL event. According
to SDL docs I can’t do anything (SDL funcs) in a separate thread
(in this case thread that collects net input).

You could run two seperate threads (apart from the main one), one for
the SDL events, one for the network events, and then have your own event
queue which is updated by both of these, and this is then in turn
handled
by your main program. You’d have to be careful about putting some
mutex’s in there however, to make sure you always have a consistent
queue.

Andre

You could run two seperate threads (apart from the main one), one for
the SDL events, one for the network events, and then have your own event
queue which is updated by both of these, and this is then in turn
handled
by your main program. You’d have to be careful about putting some
mutex’s in there however, to make sure you always have a consistent
queue.

The SDL event queue is thread-safe.

-Sam Lantinga				(slouken at devolution.com)

Lead Programmer, Loki Entertainment Software–
“Any sufficiently advanced bug is indistinguishable from a feature”
– Rich Kulawiec

OK. But how can I notify main thread that there’s something to do.
Main thread will likely sleep waiting for next SDL event. According
to SDL docs I can’t do anything (SDL funcs) in a separate thread
(in this case thread that collects net input).

You can post messages to the main thread, using SDL_PushEvent()
See ya!
-Sam Lantinga (slouken at devolution.com)

Thank you. It solves problem on SDL 1.1+. I’ve asked about stable
version, however.

JBOn Tue, 15 Feb 2000, Sam Lantinga wrote: