Ti Kan wrote:

Hi all,

Question: Can the XtAppProcessEvent() function be called from a
event or timer callback function?  I.e., simply put, can
an Xt callback function itself have an event handling loop?

I have an app that has a XtAppMainLoop(), but some of the work in
the callback function could take a long time (i.e., network
I/O, etc).  So, is it safe for the callback function itself to do
something like select() on the data being waited on, while itself having
an event loop that looks something like this, so that the app doesn't
appear frozen:

void callback_func(Widget w, XtPointer client_data, XtPointer call_data)
{
        /* ... */

        do {
                FD_ZERO(&efds);
                FD_ZERO(&rfds);
                FD_SET(fd, &rfds);

                to.tv_sec = 0;
                to.tv_usec = 50000;
                ret = select(fd+1, &rfds, NULL, &efds, &to);

                while (XtAppPending(app_context))
                        XtAppProcessEvent(app_context, XtIMAll);
        } while (ret == 0);

        /* ... */
}

Sorry about this somewhat off-topic question, but I haven't been able
to get a definitive answer from the various X docs and manuals.
The XtAppProcessEvent man page seems to imply that this is ok, but
it's not clear that the function is actually safe for recursion at
some level.

I tested this and it seems to work, but some users of my app gets
XIO errors and unexpected async reply errors that I could not reproduce.

Hope someone could shed some light on this.

-Ti

First of all, you dont *need* to do this, you could use XtAppAddInput. Then IO events are handled the same way as others, and you wont have that 50ms delay before X events can be processed.


Next, in general, you *can* have a private events loop in a callback. There should not be any problem *provided* none of the events can trigger the same callback again. Example (good): the callback for a PushButton manages a dialog and has its own loop until the dialog is unmanaged. However, if the callback *is* triggered again, then you could have a wild stack growth.

As for your XIO errors etc..., I dont think that's related. Such problems usually happen in a multi-threaded program, is yours like that?

--
Michel Bardiaux
Peaktime Belgium S.A.  Bd. du Souverain, 191  B-1160 Bruxelles
Tel : +32 2 790.29.41

_______________________________________________
Lesstif mailing list
[EMAIL PROTECTED]
https://terror.hungry.com/mailman/listinfo/lesstif

Reply via email to