hi,

On Wed, Jul 09, 2008 at 02:22:45PM +0200, Jörg F. Wittenberger wrote:
> 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?

i cannot decide this, but i have a question:

your code looks just like tcp-accept (from chicken 3.1.0) except that
you return (values fd (##net#getpeername fd)) and tcp-accept returns
(##net#io-ports fd).

i don't understand why wrapping the fd in scheme ports should read
anything from the fd if the ports are not used in any way besides
getting the fd out (which doesn't seem to be possible right now -
perhaps also a useful addition :)

otoh... ##net#io-ports makes the fd non-blocking and closes them at
some point so you are probably right, a lower-level function should be
available that just returns the plain fd. (and tcp-accept should then
just be (##net#io-ports (tcp-get-next-client-or-something tcpl))

i'd prefer tcp-accept* or tcp-accept/fd over tcp-get-next-client.

bye,
hans.



> 
> (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 mailing list
> Chicken-users@nongnu.org
> http://lists.nongnu.org/mailman/listinfo/chicken-users


_______________________________________________
Chicken-users mailing list
Chicken-users@nongnu.org
http://lists.nongnu.org/mailman/listinfo/chicken-users

Reply via email to