bug-ncurses
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

wgetch_events issue


From: bwgz
Subject: wgetch_events issue
Date: Sun, 22 Apr 2012 23:42:44 -0500

I've been experimenting with a headless system and ncurses has been
nice quick and easy way to create some of my programs. One of the
things I need is the ability include my own input events into ncurses
event loop. Given that I'm using a file descriptor to fetch my input
the wgetch_events function looked like it had a lot of potential. In
the end it gave me what I wanted but I had to change, dare I say fix,
the code.

I pulled the 5.9 release, configured it with "configure
--enable-wgetch-events", and built it. When I ran my test program
wgetch_events didn't catch inputs from the file descriptor I passed to
it. After some debugging I found that the following code at line 391
in lib_twait.c was the problem.

#ifdef NCURSES_WGETCH_EVENTS
    if (evl) {
        evl->result_flags = 0;
        for (n = 0; n < evl->count; ++n) {
            _nc_event *ev = evl->events[n];
            if (ev->type == _NC_EVENT_TIMEOUT_MSEC) {
                long diff = (returntime - starttime);
                if (ev->data.timeout_msec <= diff)
                    ev->data.timeout_msec = 0;
                else
                    ev->data.timeout_msec -= diff;
            }

        }
    }
#endif

If evl is set, which it is if you're sending in your own file
descriptors, then evl->result_flags is always set to 0. That wipes out
how it may have been set earlier. In my case it was being set to
_NC_EVENT_FILE_READABLE earlier in the function. When it hits this
code that gets wiped out. And then down stream when the program gets
back to my code it isn't notified that input actually occurred.

Looking at the code I concluded that lib_twait.c should be setting
evl->result_flags only if one of the "ev's" is of type
_NC_EVENT_TIMEOUT_MSEC. I think the code should look something like
this.

#ifdef NCURSES_WGETCH_EVENTS
    if (evl) {
        for (n = 0; n < evl->count; ++n) {
            _nc_event *ev = evl->events[n];

            if (ev->type == _NC_EVENT_TIMEOUT_MSEC) {
                long diff = (returntime - starttime);
                if (ev->data.timeout_msec <= diff)
                    ev->data.timeout_msec = 0;
                else
                    ev->data.timeout_msec -= diff;

                evl->result_flags |= _NC_EVENT_TIMEOUT_MSEC;
            }

        }
    }
#endif

This code only sets evl->result_flags if in fact a "ev" represents a
time out. And when set the value OR's it into the variable.

My code now runs as expected and I'm able to process input from the
devices associated with the file descriptors I pass into
wgetch_events.

Having made this change I wanted to know if it's something that should
be put into the main code line. If so, please let me know and I'll
post a diff.

... bruce



reply via email to

[Prev in Thread] Current Thread [Next in Thread]