[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Chicken-users] Proposed addition to tcp unit
From: |
F. Wittenberger |
Subject: |
[Chicken-users] Proposed addition to tcp unit |
Date: |
Wed, 09 Jul 2008 14:22:45 +0200 |
Hi all,
I wanted to control tcp connections from chicken, but handle the actual
traffic by an external program.
This appears not quite possible with the tcp unit as it stands.
tcp-accept starts reading from the accepted connection while my
connection handler starves. (Or at worst they will share the traffic in
an unpredictable way.)
To cope with the situation I added "tcp-get-next-client" (which is
incidentally compatible with rscheme's "get-next-client", since that's
the code I'm porting).
Is this a general useful addition? I'd appreciate if it would it make
it into chicken. Will it?
(define (tcp-get-next-client tcpl)
(##sys#check-structure tcpl 'tcp-listener)
(let ((fd (##sys#slot tcpl 1))
(tma (tcp-accept-timeout)))
(let loop ()
(if (eq? 1 (##net#select fd))
(let ((fd (##net#accept fd #f #f)))
(when (eq? -1 fd)
(##sys#update-errno)
(##sys#signal-hook
#:network-error 'tcp-accept (##sys#string-append "could not
accept from listener - " strerror)
tcpl) )
(values fd (##net#getpeername fd)))
(begin
(when tma
(##sys#thread-block-for-timeout!
##sys#current-thread
(fx+ (##sys#fudge 16) tma) ) )
(##sys#thread-block-for-i/o! ##sys#current-thread fd #t)
(yield)
(when (##sys#slot ##sys#current-thread 13)
(##sys#signal-hook
#:network-error
'tcp-accept
"accept operation timed out" fd) )
(loop) ) ) ) ) )
BTW: It works as expected.
/Jörg
- [Chicken-users] Proposed addition to tcp unit,
F. Wittenberger <=