[plt-scheme] Reading on TCP ports and #<eof>

From: Erich Rast (erich at snafu.de)
Date: Thu Jul 19 05:31:30 EDT 2007


I try to read expressions from a TCP port in a loop like this one:

  (define (connection-start-client-listen connection)
      (lambda ()
        (let loop ((in (read (connection-in-port connection))))
          (info "~a ~s" (connection-name connection) in)
          (if (is-reply? in)
              (handle-reply connection (car in))
              (info "illegal reply: '~s'" in))
          (loop (read (connection-in-port connection)))))))

When (connection-in-port connection) yields a port obtained from a  
make-pipe, this works well. However, when the port is a TCP-port, it  
seems that the call to read doesn't block, but instead returns #<eof>  
each time it is called. The loop becomes rather busy and my info  
procedure continuously outputs "illegal reply: #<eof" when the server  
the client has connected to doesn't send anything.

How do I block the thread until some value different from #<eof> is  
read? Why is a tcp port behaving differently from one produced by  



Posted on the users mailing list.