This is the mail archive of the guile@sourceware.cygnus.com mailing list for the Guile project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: Input/output problems with closed ports


| Yes. Actually, the situation is the following: I have a select() which
| monitors stdin and some socket p. These 2 ports have each a handler
| (say a repl for stdin). If you receive some special data on
| p, the handler for p closes the socket port. 
| The repl on stdin is still there, with
| object p available, and you want to write safely to p from the repl.
| 
| I can even be more specific: p is a connection to a remote X11 server,
| and the special data is the X event 
| send when someone on the remote side clicks the "Quit" button.
| Writing to p from the repl would be asking for creating a new window.
| The role of "close?" is to be sure if this is legitimate.

I'm not entirely convinced, but there's probably no good reason not to
add the procedure.  You can do it like this anyway:

(define (closed? port)
   (let ((str (with-output-to-string (lambda () (write port)))))
      (string=? (substring str 2 8) "closed")))

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]