From 772a87dc24ca28d87fa0a749d4a03ba67fd8a4b7 Mon Sep 17 00:00:00 2001 From: Quentin Date: Thu, 9 Jul 2020 12:15:00 +0200 Subject: [PATCH] Refactor --- examples/udp_server.scm | 31 +++++++++++++++++-------------- 1 file changed, 17 insertions(+), 14 deletions(-) diff --git a/examples/udp_server.scm b/examples/udp_server.scm index 4866507..0ab5afc 100644 --- a/examples/udp_server.scm +++ b/examples/udp_server.scm @@ -7,24 +7,27 @@ (raise msg)) (#t ret))) -(define (udp-sock fx) +(define (udpsock-create fx) (fx (check-err (socket 'AF_INET 'SOCK_DGRAM 'IPPROTO_IP) "Unable to init UDP socket"))) -(udp-sock +(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 (lambda (s) - (alloc - (ftype-sizeof int) - (lambda (activation) - (foreign-set! 'int activation 0 1) - (check-err - (setsockopt - s - 'SOL_SOCKET - 'SO_REUSEADDR - activation - (ftype-sizeof int)) - "Unable to set REUSE ADDRESS"))) + (udpsock-reuseaddr s) (printf "~a~%" s)))