chicken-users
[Top][All Lists]
Advanced

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

Re: [Chicken-users] non-blocking (read)


From: felix winkelmann
Subject: Re: [Chicken-users] non-blocking (read)
Date: Tue, 19 Jul 2005 10:07:23 +0200

On 7/19/05, Daishi Kato <address@hidden> wrote:
> For example, an application would be a server program
> that is controlable by a user through some kind of commands.
> In other words, a server program with CUI.
> Currently I could do it by csi, since it does not block the server thread,
> but what if I would like to compile it into a single executable?
> Would char-ready? help?
> 

How do you communicate with the sever? If it's a sub-process,
you can use `process' (posix unit) which is non-blocking:

% cat slow.sh
#!/bin/sh
echo "hello!"
sleep 1
echo "yes"
sleep 3
echo "no"
% cat listen.scm
;;;; listen.scm

(use posix srfi-18)

(thread-start!
 (lambda ()
   (let loop ((i 1))
     (thread-sleep! 0.5)
     (print "[" i "]") 
     (loop (add1 i)) ) ) )

(define-values (i o _) (process "./slow.sh"))

(port-for-each print (cut read-line i))  ; assumes Chicken 2.0, a
simple loop works as well

(close-input-port i)
(close-output-port o)

% csi -script listen.scm
...


cheers,
felix




reply via email to

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