From 2fc594fcc439835db66ba6d78b49a765498123f2 Mon Sep 17 00:00:00 2001 From: Matthew Flatt Date: Thu, 20 Dec 2018 21:31:43 -0700 Subject: [PATCH] cs: make public `udp-bound?` and `udp-connected?` safe --- racket/src/io/network/udp-send.rkt | 2 +- racket/src/io/network/udp-socket.rkt | 24 ++++++++++++++++-------- 2 files changed, 17 insertions(+), 9 deletions(-) diff --git a/racket/src/io/network/udp-send.rkt b/racket/src/io/network/udp-send.rkt index 7c42146f90..86443d5ef9 100644 --- a/racket/src/io/network/udp-send.rkt +++ b/racket/src/io/network/udp-send.rkt @@ -137,7 +137,7 @@ "socket" u)))] [else ;; if the socket is not bound already, send[to] binds it - (set-udp-bound?! u #t) + (set-udp-is-bound?! u #t) (define r (rktio_udp_sendto_in rktio (udp-s u) addr bstr start end)) (cond [(rktio-error? r) diff --git a/racket/src/io/network/udp-socket.rkt b/racket/src/io/network/udp-socket.rkt index 3e33a26854..cd6f336a9b 100644 --- a/racket/src/io/network/udp-socket.rkt +++ b/racket/src/io/network/udp-socket.rkt @@ -22,10 +22,10 @@ udp-default-family udp-s - set-udp-bound?! - set-udp-connected?!) + set-udp-is-bound?! + set-udp-is-connected?!) -(struct udp (s bound? connected?) +(struct udp (s is-bound? is-connected?) #:mutable #:authentic) @@ -61,6 +61,10 @@ ;; ---------------------------------------- +(define/who (udp-bound? u) + (check who udp? u) + (udp-is-bound? u)) + (define/who (udp-bind! u hostname port-no [reuse? #f]) (check who udp? u) (check who string? #:or-false hostname) @@ -74,7 +78,7 @@ #:passive? #t (lambda (addr) (check-udp-closed who u) - (when (udp-bound? u) + (when (udp-is-bound? u) (end-atomic) (raise-arguments-error who "udp socket is already bound" "socket" u)) @@ -85,7 +89,11 @@ (string-append "can't bind" (if reuse? " as reusable" "") "\n address: " (or hostname "") "\n port number: " (number->string port-no)))) - (set-udp-bound?! u #t))))) + (set-udp-is-bound?! u #t))))) + +(define/who (udp-connected? u) + (check who udp? u) + (udp-is-connected? u)) (define/who (udp-connect! u hostname port-no) (check who udp? u) @@ -101,12 +109,12 @@ (cond [(not hostname) (check-udp-closed who u) - (when (udp-connected? u) + (when (udp-is-connected? u) (define d (rktio_udp_disconnect rktio (udp-s u))) (when (rktio-error? d) (end-atomic) (raise-network-error who d "can't disconnect")) - (set-udp-connected?! u #f))] + (set-udp-is-connected?! u #f))] [else (call-with-resolved-address #:who who @@ -121,7 +129,7 @@ (string-append "can't connect" "\n address: " hostname "\n port number: " (number->string port-no)))) - (set-udp-connected?! u #t)))]))) + (set-udp-is-connected?! u #t)))]))) ;; ----------------------------------------