The way those properties work is that functions that use input-ports and
outputs-ports have knowledge about the properties and check if it is a
struct with those properties. There is no prop:udp though. You could
make one (like the following), but you would need to make your own
wrappers of the existing udp-* functions and have them do the coercion
before passing arguments to the existing racket functions.
Cheers,
Sam
--- >8 --- >8 ---
#lang racket/base
(require (prefix-in - racket/udp))
(define-values (prop:udp prop:udp? udp-socket-ref)
(make-struct-type-property
'prop:udp
(lambda (val struct-info)
(cond
[(procedure? val) val]
[(exact-nonnegative-integer? val)
; XXX: check for valid index
(let ([struct-ref (list-ref struct-info 3)])
(lambda (a-struct-value)
(struct-ref a-struct-value val)))]))))
(define (->udp-socket v)
(cond
[(-udp? v) v]
[else
(->udp-socket ((udp-socket-ref v) v))]))
;; Something like this for every udp function
(define (udp-bind! socket hostname-string port-no [reuse? #f])
(-udp-bind! (->udp-socket socket)
hostname-string
port-no
reuse?))
(struct server (socket)
#:property
prop:udp (struct-field-index socket)
#:transparent)
(define (make-server)
(let ([udp (-udp-open-socket)])
(server udp)))