[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[ww-tedit-dev] implementation: timed WaitEvent under X Window
From: |
petar marinov |
Subject: |
[ww-tedit-dev] implementation: timed WaitEvent under X Window |
Date: |
Tue, 16 Aug 2005 20:59:46 -0700 |
User-agent: |
Mozilla Thunderbird 0.9 (Windows/20041103) |
For a GUI to work appropriately most of the time a non-blocking function
that extracts events must be present in the interface library. X
Window's interface library offers XNextEvent(), XPeekEvent() and
XPending(). This means that non-blocking extraction would involve a loop
of peek and delay but it effectively lacks a timed non-blocking event
function!
I resorted again to the advantage of the free software and peeked into
the sources of FTE [2]. There I found that select() might be employed
for monitoring any incoming activity. X works on top of sockets, xlib's
ConnectionNumber() returns the ID of the socket. It all seems natural
but the X programming book [1] didn't mention any of that, it would have
been impossible to implement this by solely following the documentation.
code could be as simple as:
if (XPending(pdisp))
return TRUE;
FD_ZERO(&rset);
connection = ConnectionNumber(pdisp);
FD_SET(connection, &rset);
tv.tv_sec = 0;
tv.tv_usec = SLEEP_TIME;
n = select(connection + 1, &rset, NULL, NULL, &tv);
---
Most of the development of the X version of WW I've been doing in
cygwin. On the same machine I also have ZoneAlarm installed. X uses
sockets to communicate with the clients and it shows -- ZoneAlarm's
traffic indicator reflects that.
I noticed that when I start WW the traffic indicator jumps to its
fullest while any other X program is most of the time using very little
of socket's bandwidth.
I checked on my wait-event() function (x_kbd.c). The SLEEP_TIME value
was to be most likely the disturbing factor. It was set to 20ms. The
main event loop relies on wait-event() and the only X function that is
invoked in the interim is XPending(). I wouldn't expect that this one
would generate a socket traffic. It is that or something else but when
select() times out that soon the ZoneAlarm's indicator blows the roof.
I experimented with values for SLEEP_TIME. Once I move it above 30ms
ZoneAlarm goes back to normal. I left it at 50ms.
-petar
[1] http://www.amazon.com/exec/obidos/tg/detail/-/1565920023
[2] http://fte.sourceforge.net/
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [ww-tedit-dev] implementation: timed WaitEvent under X Window,
petar marinov <=