[racket] Using get-pure-port

From: Shogo Yamazaki (moquo2.718 at gmail.com)
Date: Thu Aug 18 11:45:18 EDT 2011

Hi,

I have a question about using get/post-pure-port.
I'm using Racket v5.1.2.3 and FreeBSD 8.2.
It seems tcp-port is still opened after I used get-pure-port.
How can I close this? The code is below.

(require net/url)

(let ((in (get-pure-port (string->url
"http://www.google.com/intl/en_com/images/srpr/logo3w.png"))))
  (display-to-file (port->bytes in) (build-path (find-system-path
'home-dir) "google-logo1.png"))
  (close-input-port in))

---In console---
% fsat | grep 'racket.*tcp'
myusername    racket       948    5* internet stream tcp ca70b7e0
----------------
(I think fstat is similar with lsof in linux.)

I know that this won't happen when I use tcp-connect as below.

(let-values (((i o) (tcp-connect "www.google.com" 80)))
  (display "GET /intl/en_com/images/srpr/logo3w.png HTTP/1.1\r\n\r\n" o)
  (close-output-port o)
  (display-to-file (second (regexp-split #"\r\n\r\n" (port->bytes i)))
                   (build-path (find-system-path 'home-dir) "google-logo2.png"))
  (close-input-port i))

Although this isn't a big problem when I use the procedure only few times,
after used tens of thousands times it causes crash due to too many open file.
I will appreciate any help.

Shogo Yamazaki


Posted on the users mailing list.