Hi there,<br><br>I am having some trouble quickly establishing and tearing down TCP<br>connections and bindings on the same port. After a couple of<br>iterations my connecting thread reports a successful connection but<br>
the accepting thread does not. This might be a normal artifact of how<br>TCP is implemented on Windows but I do not know enough about TCP to be<br>sure.<br><br>Below is a little sample that illustrates the problem. Iteration on my
<br>Windows XP Professional stops at 2 or 3. I have also attached the<br>output of the sample, which includes interleaved calls to netstat.<br><br>Any ideas?<br><br>Thanks in advance,<br>-pp<br><br>(begin<br> (require (lib "
async-channel.ss")<br> (lib "thread.ss")<br> (lib "process.ss")<br> (lib "setf.ss" "swindle"))<br> <br> (define ch (make-async-channel))<br> <br>
(define (accept port)<br> (run-server port<br> (lambda (in out)<br> (printf "Accepted~n")<br> (async-channel-put ch (current-thread))<br> (sleep 100000))
<br> #f))<br> <br> (define (connect port)<br> (printf "Connecting~n")<br> (tcp-connect "localhost" port)<br> (printf "OK~n"))<br> <br> (define (test port)<br> (let ((th1 (thread (lambda ()
<br> (accept port)))))<br> (connect port)<br> (system "netstat")<br> (printf "Waiting for read thread to start~n")<br> (let ((th2 (async-channel-get ch)))<br>
(printf "OK~n")<br> (kill-thread th1)<br> (kill-thread th2))))<br> <br> (let loop ((n 0))<br> (printf "Test ~a~n" n)<br> (test 41235)<br> (printf "...OK~n")<br>
(loop (+ n 1))))<br><br>-------------------------------------------------------------------------------------<br>Test 0<br>Connecting<br>OK<br>Accepted<br><br>Active Connections<br> Proto Local Address Foreign Address State
<br> TCP Strider:1602 localhost:41235 ESTABLISHED<br> TCP Strider:41235 localhost:1602 ESTABLISHED<br><br>Waiting for read thread to start<br>OK<br>...OK<br><br>Test 1<br>Connecting
<br>OK<br><br>Active Connections<br><br> Proto Local Address Foreign Address State<br> TCP Strider:1602 localhost:41235 CLOSE_WAIT<br> TCP Strider:1603 localhost:41235 ESTABLISHED
<br> TCP Strider:41235 localhost:1602 FIN_WAIT_2<br> TCP Strider:41235 localhost:1603 ESTABLISHED<br><br>Waiting for read thread to start<br><br>