This commit is contained in:
Quentin 2020-07-09 12:15:00 +02:00
parent 33653804dc
commit 772a87dc24

View file

@ -7,24 +7,27 @@
(raise msg)) (raise msg))
(#t ret))) (#t ret)))
(define (udp-sock fx) (define (udpsock-create fx)
(fx (fx
(check-err (check-err
(socket 'AF_INET 'SOCK_DGRAM 'IPPROTO_IP) (socket 'AF_INET 'SOCK_DGRAM 'IPPROTO_IP)
"Unable to init UDP socket"))) "Unable to init UDP socket")))
(udp-sock (define (udpsock-reuseaddr sock)
(lambda (s)
(alloc (alloc
(ftype-sizeof int) (ftype-sizeof int)
(lambda (activation) (lambda (activation)
(foreign-set! 'int activation 0 1) (foreign-set! 'int activation 0 1)
(check-err (check-err
(setsockopt (setsockopt
s sock
'SOL_SOCKET 'SOL_SOCKET
'SO_REUSEADDR 'SO_REUSEADDR
activation activation
(ftype-sizeof int)) (ftype-sizeof int))
"Unable to set REUSE ADDRESS"))) "Unable to set REUSE ADDRESS"))))
(udpsock-create
(lambda (s)
(udpsock-reuseaddr s)
(printf "~a~%" s))) (printf "~a~%" s)))