[plt-scheme] weak tcp-fu or bug?

From: Matthew Flatt (mflatt at cs.utah.edu)
Date: Mon Apr 17 13:32:47 EDT 2006

At Thu, 13 Apr 2006 18:48:42 +0100, "pedro pinto" wrote:
>   (define (test port)
>     (let ((th1 (thread (lambda ()
>                          (accept port)))))
>       (connect port)

FWIW, you have a race condition here. I ran into that on my first try.

>         (kill-thread th1)

This is the main problem. Killing the thread does not disconnect the
TCP listener that is created by `run-server'. I recommend that you
create a custodian for t1, and then shut down the custodian instead.

On platforms other than Windows, `tcp-listen' reports an error on the
second call to `run-server', because a process can't open multiple
listeners at the same port number.

Under Windows, apparently it's ok for a process to open multiple
listeners at the same port number. But it's not clear to me how
connections get accepted among the multiple the listeners; it may be
random. Your program stops when a connection for client N is accepted
by the listener for server M for M < N (even though there's no thread
to process the listener's accepts).

Matthew



Posted on the users mailing list.