schemelib/examples/udp_server.scm

34 lines
677 B
Scheme
Raw Normal View History

2020-07-09 08:03:55 +00:00
(load "../bindings/libc.scm")
(define (check-err ret msg)
(cond
((< ret 0)
(perror msg)
(raise msg))
(#t ret)))
2020-07-09 10:15:00 +00:00
(define (udpsock-create fx)
2020-07-09 08:03:55 +00:00
(fx
(check-err
2020-07-09 10:12:38 +00:00
(socket 'AF_INET 'SOCK_DGRAM 'IPPROTO_IP)
2020-07-09 08:03:55 +00:00
"Unable to init UDP socket")))
2020-07-09 10:15:00 +00:00
(define (udpsock-reuseaddr sock)
(alloc
(ftype-sizeof int)
(lambda (activation)
(foreign-set! 'int activation 0 1)
(check-err
(setsockopt
sock
'SOL_SOCKET
'SO_REUSEADDR
activation
(ftype-sizeof int))
"Unable to set REUSE ADDRESS"))))
(udpsock-create
2020-07-09 08:03:55 +00:00
(lambda (s)
2020-07-09 10:15:00 +00:00
(udpsock-reuseaddr s)
2020-07-09 08:03:55 +00:00
(printf "~a~%" s)))