summaryrefslogtreecommitdiffstats
path: root/tests/sock-common.tl
diff options
context:
space:
mode:
authorKaz Kylheku <kaz@kylheku.com>2016-03-07 06:44:04 -0800
committerKaz Kylheku <kaz@kylheku.com>2016-03-07 06:44:04 -0800
commit076a7d3009c05cd0418fb2e357fd22ef5cb8d6ec (patch)
treeb2169d1da8f1492cfd3873d4debce7ada396b9e0 /tests/sock-common.tl
parent6b252ddb8818fb7a5e7923c442d1a9022bc07b9d (diff)
downloadtxr-076a7d3009c05cd0418fb2e357fd22ef5cb8d6ec.tar.gz
txr-076a7d3009c05cd0418fb2e357fd22ef5cb8d6ec.tar.bz2
txr-076a7d3009c05cd0418fb2e357fd22ef5cb8d6ec.zip
Basic regression test case for sockets.
* Makefile: suppress --gc-debug for tst/tests/014 directory. * tests/014/socket-basic.tl: New file. * tests/014/socket-basic.expected: New file. * tests/sock-common.tl: New file.
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)))))