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

Re: READ-CHAR-NO-HANG Problem



    Date: Mon, 01 Aug 88 13:17:32 -0700
    From: ssmith@ruffles.nrtc.northrop.com (Stephen P. Smith)
    ....
    Since this doesn't work, is there any other method to LISTEN on
    a collection of streams (which can be files, windows, network links)
    returning the ones that have characters available and/or have
    gone to EOF.
    ....

   Date: Tue, 2 Aug 88 08:33 CDT
   From: "William D. Gooch" <ai.gooch@mcc.com>
   Well, there is PEEK-CHAR.  But you should be aware that there are some
   ....


I was thinking of a primative available to implement the
semantics similiar to BSD Unix's SELECT:

(defun stream-select (set-of-input-streams)
  (declare (values subset-with-input-available
                   subset-that-have-eof-or-errors))
  ...)

Using PEEK-CHAR in the bowels of stream-select implies 
that our process waits until input is available on *one* of the
streams.  But what if another stream has input which becomes
available before that?

That is STREAM-SELECT must do something like the following:

 (flet ((stream-has-eof-or-character? (stream)
          (let ((char (read-char-no-hang stream nil :eof)))
            (when char
              (unless (eq char :eof) (unread-char char stream)))
           char)))
    (flet ((stream-select-wait-fcn (list-of-streams)
              (loop for stream in list-of-streams
                    thereis (stream-has-eof-or-character? stream))))
       (process-wait "Stream Select" #'stream-select-wait-fcn 
                      set-of-input-streams)))
       .....

However, if READ-CHAR-NO-HANG doesn't proper catch eof, how do
you do it?

--Steve