[plt-scheme] Reading on TCP ports and #<eof>
At Thu, 19 Jul 2007 11:31:30 +0200, Erich Rast wrote:
> 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
> make-pipe?
A TCP connection should indeed behave like a pipe. As long as the other
end hasn't closed the connection, then reading from the port should block:
> (define l (tcp-listen 6007 5 #t))
> (define-values (r1 w1) (tcp-connect "localhost" 6007))
> (define-values (r2 w2) (tcp-accept l))
> (read r1)
^Cuser break
> (thread (lambda () (sleep 5) (display "x " w2) (flush-output w2)))
#<thread>
> (read r1)
x ; after 5 seconds
Can you say more about the way that TCP connections are created in your
program?
Matthew