in reply to Re:(wog) Win32::Gui + Threading?
in thread Win32::Gui + Threading?
Unfortunately, Win32::GUI makes watching for the response difficult. Under Tk, one can watch for "fileevents" and thus get notified when data is available on a filehandle (from Tk's main loop.) Win32::GUI does not have a generic filehandle watching mechanism. One could probably emulate it using Win32::GUI::Timer and non-blocking I/O:
Basically, you'd periodically poll the pipe going into your script to see if it has data for you. So regularly, you'd try to sysread from your pipe which has been set non-blocking (so your GUI won't freeze). (update: You'd probably schedule these read attempts with Win32::GUI::Timer, of course.) I reccommend sysread, because you're probably going to need to do your own I/O buffering this case. You probably want a relatively short time interval, something to balance use of CPU with apparent speed. To enable non-blocking I/O, you'd use IO::Handle's blocking method with an argument of 0. To check for data from the socket, you'd read it (with sysread) and see if you got an error (undef return). If you got an error and $! was EAGAIN (see the Errno module), then there is no data on the pipe. If $! wasn't EAGAIN, but there was an error, then you'd probably want to die, because something weird would've happened. If you don't get an error, you can add that to your cache of the results (note that you probably won't get all such data at once). (You probably want to have some way of marking when the end of data is, possibly just prefixing data you send with the length of the data.)
Personally, I'd prefer a solution where Win32::GUI was modified to support watching filehandles.
update: I forewarn that this advice is untested. (Also updated phrasing slightly.)
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Re: Re:(wog) Win32::Gui + Threading?
by Flame (Deacon) on Nov 12, 2001 at 18:24 UTC | |
Re: Re: Re:(wog) Win32::Gui + Threading?
by Flame (Deacon) on Nov 12, 2001 at 18:00 UTC | |
Re: Re: Re:(wog) Win32::Gui + Threading?
by Flame (Deacon) on Nov 13, 2001 at 03:29 UTC | |
by wog (Curate) on Nov 13, 2001 at 03:41 UTC | |
by Flame (Deacon) on Nov 13, 2001 at 03:45 UTC | |
by wog (Curate) on Nov 13, 2001 at 04:08 UTC | |
by Flame (Deacon) on Nov 13, 2001 at 04:53 UTC | |
|