summaryrefslogtreecommitdiffstats
path: root/tests/sock-common.tl
diff options
context:
space:
mode:
Diffstat (limited to 'tests/sock-common.tl')
-rw-r--r--tests/sock-common.tl13
1 files changed, 13 insertions, 0 deletions
diff --git a/tests/sock-common.tl b/tests/sock-common.tl
new file mode 100644
index 00000000..63f31c83
--- /dev/null
+++ b/tests/sock-common.tl
@@ -0,0 +1,13 @@
+(defun local-addr (family port)
+ (caseql family
+ (af-inet (new sockaddr-in addr inaddr-loopback port port))
+ (af-inet6 (new sockaddr-in6 addr in6addr-loopback port port))))
+
+(defun bindfree (sock from to)
+ (for ((port from))
+ ((<= port to) (error "unable to bind socket"))
+ ((inc port))
+ (let ((addr (local-addr (sock-family sock) port)))
+ (when (ignerr (sock-bind sock addr))
+ (sock-listen sock)
+ (return-from bindfree addr)))))