io: fix tcp-abandon-port so that the socket gets closed

This commit is contained in:
Matthew Flatt 2018-10-24 09:45:08 -06:00
parent e8832fbcc7
commit fce5554695
2 changed files with 25 additions and 8 deletions

View File

@ -1696,6 +1696,8 @@
;; The `ffi/file` library - - - - - - - - - - - - - - - - - - -
(define no-op (lambda (x) #f))
(let ()
(define pub-mod (collection-file-path "list.rkt" "racket"))
(define priv-mod (collection-file-path "stx.rkt" "racket/private"))
@ -1724,11 +1726,15 @@
void void))
(define (mk-fun modes)
;; receives path pointer, casts as int, who cares
(get-ffi-obj "scheme_make_integer_value" (ffi-lib #f)
(_fun (path) ::
(path : (_file/guard modes 'me))
-> _scheme)))
;; receives path pointer; the rest doesn't matter
(cast no-op
;; turns `no-op` into a callback:
(_fun _pointer -> _scheme)
;; turns the callback into a callout, which is what we want
;; to test `_file/guard`:
(_fun (path) ::
(path : (_file/guard modes 'me))
-> _scheme)))
(define (fun path modes)
((mk-fun modes) path))

View File

@ -2,6 +2,7 @@
(require "../common/check.rkt"
"../host/rktio.rkt"
"../port/port.rkt"
"../port/close.rkt"
"../port/input-port.rkt"
"../port/output-port.rkt"
"../port/fd-port.rkt"
@ -61,10 +62,20 @@
(define/who (tcp-port? p)
(tcp-data? (port-tcp-data p)))
(define/who (tcp-abandon-port p)
(define/who (tcp-abandon-port given-p)
(define p (cond
[(input-port? given-p)
(->core-input-port given-p)]
[(output-port? given-p)
(->core-output-port given-p)]
[else #f]))
(define data (port-tcp-data p))
(unless (tcp-data? data)
(raise-argument-error who "tcp-port?" p))
(if (input-port? p)
(set-tcp-data-abandon-in?! data #t)
(set-tcp-data-abandon-out?! data #t)))
(begin
(set-tcp-data-abandon-in?! data #t)
(close-port p))
(begin
(set-tcp-data-abandon-out?! data #t)
(close-port p))))