[racket] Doubt about the 'More: Systems Programming with Racket'
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
Hello list.
I was playing around the quoted tutorial, and found a strange behavior
in the following code:
;;code
#lang racket
(require racket/tcp)
(provide serve)
(define (serve port-no)
(define listener (tcp-listen port-no 5 #t))
(define (loop)
(accept-and-handle listener)
(loop))
(define t (thread loop))
(lambda ()
(kill-thread t)
(tcp-close listener)))
(define (accept-and-handle listener)
(define-values (in out) (tcp-accept listener))
(thread
(lambda ()
(handle in out)
(close-input-port in)
(close-output-port out))))
(define (handle in out)
(display (port->string in))) ;; it locks here
;; test
(define-test-suite small-suite
(let*-values ([(stopper) (serve 8080)]
[(tcp-input-port tcp-output-port)
(tcp-connect "127.0.0.1" 8080)])
(display "stuff" tcp-output-port)
(flush-output tcp-output-port)
(sleep 0.1)
(check-equal? (port->string tcp-input-port)
"stuff")
(stopper)))
(run-tests small-suite)
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
The code above works very well if I read the input port with
read-line, but won't budge if I use something like port->string.
Can somebody shed a light on this?
Thanks for the time.
- --
Eduardo Bellani
omnia mutantur, nihil interit.
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.9 (GNU/Linux)
iEYEARECAAYFAk4NIPwACgkQSbLl0kCTjGlixwCfW+3uDxSe/7sz5PW03iMf2XeK
MfsAn0+p95DZGrgpGDzlhMQl1UM0hYze
=yace
-----END PGP SIGNATURE-----