I appology,
but I have use fileevent in the past in just one way and couldn't
imagine another usefull application. So here are my answers to your
questions:
Erick Gallesio wrote:
>
> > Ralf Berger writes
>
> > I have a problem with the implementation of 'when-port-readable'.
> > It allow asynchron reading whenever the file is readable.
> > This new implementation of 'fileevent' seems to interrupt the main
> > flow of controll. The old 'fileevent' don't do that. The old
> > 'fileevent' was dispatched together with other Tk-Events. So you
> > could synchronize with 'tkwait'.
> >
> I'm afraid that I don't understand what you call synchronize here.
> Can you send an example of what you want to do? I don't understand how you
> could use tkwait with files.
I use 'fileevent' for reading results from an application. This
application
gets commands via stdin and put the results on stdout.
My code looks like:
(define (ecco-start . arglist)
(let ((e-program (get-keyword :program arglist "prog"))
(e-handler (get-keyword :handler arglist ecco-handler)))
;; create and run the ecco-process.
(set! ecco-process (run-process e-program :input :pipe :output
:pipe))
;; establish fileevent-handler.
(fileevent (process-output ecco-process)
'readable
e-handler)))
(define (ecco-handler)
(let ((x (read-line (process-output ecco-process))))
(if (not (eof-object? x))
;; then
(begin
(eval-string (tcl->scheme x))))))
If I send a command to the application I do that by putting a string on
the
process-input. The result comes as a tcl-command, which I convert to
scheme. (This commands put some data in some variables.)
After sending the command the execution of scheme code goes ahead (with
no
interrupt!). During the execution I decide to receive the data from the
process and initiate a 'tkwait :variable x' to synchronize with the
other
program. This Code-Part looks like:
(define (wait-for-id)
(if (process-alive? ecco-process)
;; then
(tkwait 'variable 'sema-new-id)
;; else
(begin (newline)
(display "Ecco-Process no more running!")
(newline)
(flush)))
(set! sema-new-id #f)
ecco-new-id)
This allways work for stk-3.0b2. With stk-3.1.1 I get allways a
starvation.
I think (don't know) the problem is: 'when-port-readable' interrupts
the scheme code. So the sema-Variable is already set before tkwait is
called!
> > I have read the documentation carefully but perhaps I miss something.
> > So my questions are:
> >
> > How can I synchronize now?
> >
> Perhaps you can do a tkwait in your handler or have a handler which just
> do a (after 'idle code-for-the-real-handler))
>
> But, since I have not understood the problem, this probably don't answer your
> problem.
>
Thanks, I will try it.
Sincerely,
Ralf
--
Fraunhofer IPK | Wir sitzen alle in einem Boot.
Dipl.-Inform. Ralf Berger | Jeder in seinem!
Pascalstr. 8-9 |
10587 Berlin |
Received on Tue Oct 22 1996 - 17:28:45 CEST