<br>When I use (sync (tcp-accept-evt ...)) to accept connections... those ports don't always end up on the (current-custodian) managed list. <br><br>If I used tcp-accept procedure instead of (sync (tcp-accept-evt listener)) everything works as expected.<br>
<br>I'm using PLT Scheme 4.2 and running this example in DrScheme. My OS is 64bit Ubuntu using the 64bit debian plt installer. <br><br>This does reproduce under mzscheme as well.<br><br><br>The output is the pair of ports that are accepted followed by the objects that belong to the (current-custodian) after the accept happens for each accepted connection.<br>
<br><br>This output is when using (sync (tcp-accept-evt listener)).<br>Note: This is the buggy behavior.<br><br> (test #t 1)<br>"listener connected in-port 250545 out-port 250546 custodian objects ()"<br><br>(test #t 3)<br>
"listener connected in-port 250568 out-port 250569 custodian objects ()"<br>"listener connected in-port 250571 out-port 250572 custodian objects ()"<br>"listener connected in-port 250574 out-port 250575 custodian objects ()"<br>
<br>(test #t 5)<br>"listener connected in-port 250597 out-port 250598 custodian objects ()"<br>"listener connected in-port 250599 out-port 250600 custodian objects ()"<br>"listener connected in-port 250601 out-port 250602 custodian objects ((#<output-port:tcp-accepted> . 250602) (#<input-port:tcp-accepted> . 250601))"<br>
"listener connected in-port 250606 out-port 250607 custodian objects ()"<br>"listener connected in-port 250608 out-port 250609 custodian objects ((#<output-port:tcp-accepted> . 250609) (#<input-port:tcp-accepted> . 250608))"<br>
<br>(test #t 10)<br>"listener connected in-port 250632 out-port 250633 custodian objects ()"<br>"listener connected in-port 250634 out-port 250635 custodian objects ()"<br>"listener connected in-port 250636 out-port 250637 custodian objects ((#<output-port:tcp-accepted> . 250637) (#<input-port:tcp-accepted> . 250636))"<br>
"listener connected in-port 250641 out-port 250642 custodian objects ()"<br>"listener connected in-port 250643 out-port 250644 custodian objects ((#<output-port:tcp-accepted> . 250644) (#<input-port:tcp-accepted> . 250643))"<br>
"listener connected in-port 250645 out-port 250646 custodian objects ((#<output-port:tcp-accepted> . 250646) (#<input-port:tcp-accepted> . 250645))"<br>"listener connected in-port 250647 out-port 250648 custodian objects ((#<output-port:tcp-accepted> . 250648) (#<input-port:tcp-accepted> . 250647))"<br>
"listener connected in-port 250649 out-port 250650 custodian objects ((#<output-port:tcp-accepted> . 250650) (#<input-port:tcp-accepted> . 250649))"<br>"listener connected in-port 250651 out-port 250652 custodian objects ((#<output-port:tcp-accepted> . 250652) (#<input-port:tcp-accepted> . 250651))"<br>
"listener connected in-port 250659 out-port 250660 custodian objects ()"<br><br><br><br><br>This output is when using (tcp-accept) instead of the (sync (tcp-accept-evt listener)) <br>Note: This is the behavior that I expect<br>
<br><br>(test #f 1)<br>"listener connected in-port 250709 out-port 250710 custodian objects ((#<output-port:tcp-accepted> . 250710) (#<input-port:tcp-accepted> . 250709))"<br><br>(test #f 3)<br>"listener connected in-port 250732 out-port 250733 custodian objects ((#<output-port:tcp-accepted> . 250733) (#<input-port:tcp-accepted> . 250732))"<br>
"listener connected in-port 250735 out-port 250736 custodian objects ((#<output-port:tcp-accepted> . 250736) (#<input-port:tcp-accepted> . 250735))"<br>"listener connected in-port 250738 out-port 250739 custodian objects ((#<output-port:tcp-accepted> . 250739) (#<input-port:tcp-accepted> . 250738))"<br>
<br>(test #f 5)<br>"listener connected in-port 250761 out-port 250762 custodian objects ((#<output-port:tcp-accepted> . 250762) (#<input-port:tcp-accepted> . 250761))"<br>"listener connected in-port 250763 out-port 250764 custodian objects ((#<output-port:tcp-accepted> . 250764) (#<input-port:tcp-accepted> . 250763))"<br>
"listener connected in-port 250765 out-port 250766 custodian objects ((#<output-port:tcp-accepted> . 250766) (#<input-port:tcp-accepted> . 250765))"<br>"listener connected in-port 250770 out-port 250771 custodian objects ((#<output-port:tcp-accepted> . 250771) (#<input-port:tcp-accepted> . 250770))"<br>
"listener connected in-port 250772 out-port 250773 custodian objects ((#<output-port:tcp-accepted> . 250773) (#<input-port:tcp-accepted> . 250772))"<br><br>(test #f 10)<br>"listener connected in-port 250796 out-port 250797 custodian objects ((#<output-port:tcp-accepted> . 250797) (#<input-port:tcp-accepted> . 250796))"<br>
"listener connected in-port 250798 out-port 250799 custodian objects ((#<output-port:tcp-accepted> . 250799) (#<input-port:tcp-accepted> . 250798))"<br>"listener connected in-port 250800 out-port 250801 custodian objects ((#<output-port:tcp-accepted> . 250801) (#<input-port:tcp-accepted> . 250800))"<br>
"listener connected in-port 250805 out-port 250806 custodian objects ((#<output-port:tcp-accepted> . 250806) (#<input-port:tcp-accepted> . 250805))"<br>"listener connected in-port 250807 out-port 250808 custodian objects ((#<output-port:tcp-accepted> . 250808) (#<input-port:tcp-accepted> . 250807))"<br>
"listener connected in-port 250809 out-port 250810 custodian objects ((#<output-port:tcp-accepted> . 250810) (#<input-port:tcp-accepted> . 250809))"<br>"listener connected in-port 250811 out-port 250812 custodian objects ((#<output-port:tcp-accepted> . 250812) (#<input-port:tcp-accepted> . 250811))"<br>
"listener connected in-port 250813 out-port 250814 custodian objects ((#<output-port:tcp-accepted> . 250814) (#<input-port:tcp-accepted> . 250813))"<br>"listener connected in-port 250815 out-port 250816 custodian objects ((#<output-port:tcp-accepted> . 250816) (#<input-port:tcp-accepted> . 250815))"<br>
"listener connected in-port 250823 out-port 250824 custodian objects ((#<output-port:tcp-accepted> . 250824) (#<input-port:tcp-accepted> . 250823))"<br> <br><br><br>Here is the program listing...<br>
<br><br>#lang scheme<br><br>(define (test use-accept-evt connector-count)<br> (parameterize ([current-custodian (make-custodian)])<br> (define main (current-thread))<br> <br> ;thread that pretty prints any messages it receives in its mailbox<br>
(define printer <br> (thread<br> (lambda ()<br> (let loop ()<br> (pretty-print (thread-receive))<br> (loop)))))<br> <br> ;sends a message to be printed by the printer<br> (define (pr fmt . args)<br>
(thread-send printer (apply format fmt args)))<br> <br> <br> ;makes a thread that will connect to the local tcp listener<br> (define (make-connector)<br> (let ([super (current-custodian)]<br> [cust (make-custodian)])<br>
(parameterize ([current-custodian cust])<br> (thread<br> (lambda ()<br> (tcp-connect "localhost" 5000)<br> (custodian-shutdown-all (current-custodian)))))<br> cust))<br>
<br> ;generats a list of pairs that contain the object its eq-hash-code<br> ;of all objects managed by a given custodian<br> (define (custodian-list-hash custodian super)<br> (map (lambda (obj)<br> (cons obj (eq-hash-code obj)))<br>
(custodian-managed-list custodian super)))<br> <br> <br> ;thread that starts a tcp-listener and accepts incoming requests<br> (define listener <br> (thread<br> (lambda ()<br> (let ([listener (tcp-listen 5000 100 #t)]<br>
[super (current-custodian)])<br> (thread-send main 'listener-ok)<br> (let accept-loop ()<br> (parameterize ([current-custodian (make-custodian super)])<br> (if use-accept-evt<br>
(let ([ports (sync (tcp-accept-evt listener))])<br> (pr "listener connected in-port ~a out-port ~a custodian objects ~a" (eq-hash-code (first ports)) (eq-hash-code (second ports)) (custodian-list-hash (current-custodian) super)))<br>
(let-values ([(in out) (tcp-accept listener)])<br> (pr "listener connected in-port ~a out-port ~a custodian objects ~a" (eq-hash-code in) (eq-hash-code out) (custodian-list-hash (current-custodian) super)))))<br>
(accept-loop))))))<br> <br> ;wait for listener to initialize<br> (thread-receive)<br> <br> ;spawn the connections<br> (let conn-loop ([count connector-count])<br> (unless (= count 0)<br>
(make-connector)<br> (sleep 0)<br> (conn-loop (sub1 count))))<br> <br> ;wait 2 seconds and shutdown everything<br> (sleep 2)<br> (custodian-shutdown-all (current-custodian))))<br><br><br>
<br>bug?<br><br>Thanks<br> -Curt<br>