chicken-users
[Top][All Lists]
Advanced

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

Re: [Chicken-users] http-client doesn't handle closed persistent connect


From: Peter Bex
Subject: Re: [Chicken-users] http-client doesn't handle closed persistent connections
Date: Mon, 31 Jan 2011 20:24:46 +0100
User-agent: Mutt/1.4.2.3i

On Mon, Jan 31, 2011 at 09:43:45PM +0900, Daishi Kato wrote:
> > Crap, you're right. I have no idea how to fix this properly right now
> > though.  I'll need to think about it some more.
> 
> How about raising an i/o exception(condition) when
> it detects #!eof in read-response in intarweb.scm?
> It will retry.

Yeah, but that's abusing an error situation.  It will also
(incorrectly, IMO) use up one retry-attempt.

I've checked in a new version that first checks to see whether
a char is ready before trying to peek.  There ought not to be
a character ready in normal circumstances, so trying to read
the EOF object only when there is should fix the situation.

I think the situation before this was that it would try to
peek but there wouldn't be anything there yet, so it would wait
until the connection was dropped and then reported #!eof.

I checked this with a simple program:

(use tcp http-client posix)

(process-fork (lambda ()
                (let*-values (((l) (tcp-listen 8080))
                              ((in out) (tcp-accept l)))
                  (write-char #\x out)
                  (sleep 5)
                  (write-char #\y out)
                  (close-output-port out)
                  (close-input-port in))))

(print "waiting for listener to be established (silly)")
(sleep 1)
(define-values (in out) (tcp-connect "localhost" 8080))
(print "reading:")
(print (read-char in))
(print "peeking:")
(print (if (eof-object? (peek-char in)) "unexpected EOF!" "no EOF yet"))
(print "reading again:")
(print (read-char in))
(print "peeking again:")
(print (if (eof-object? (peek-char in)) "Got EOF" "no EOF yet (this is weird)"))
(print (if (port-closed? in) "closed" "open"))

When run, this prints the following:

waiting for listener to be established (silly)
reading:
x
peeking:      <and here it waits 5 seconds!>
no EOF yet
reading again:
y
peeking again:
Got EOF
open

Cheers,
Peter
-- 
http://sjamaan.ath.cx
--
"The process of preparing programs for a digital computer
 is especially attractive, not only because it can be economically
 and scientifically rewarding, but also because it can be an aesthetic
 experience much like composing poetry or music."
                                                        -- Donald Knuth



reply via email to

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