diff options
author | Paul A. Patience <paul@apatience.com> | 2021-09-11 22:19:18 -0400 |
---|---|---|
committer | Kaz Kylheku <kaz@kylheku.com> | 2021-09-12 10:13:03 -0700 |
commit | 521ab968ee48e4e40a3e1a5ea00851d39e59b4b3 (patch) | |
tree | 560dd8b023d5d7bb2492b2944c46f59d130aafdf /tests/014/socket-misc.tl | |
parent | 68ad6419262bf60874f034c62d29b83ed4bb2a48 (diff) | |
download | txr-521ab968ee48e4e40a3e1a5ea00851d39e59b4b3.tar.gz txr-521ab968ee48e4e40a3e1a5ea00851d39e59b4b3.tar.bz2 txr-521ab968ee48e4e40a3e1a5ea00851d39e59b4b3.zip |
ffi, sockets: add sock-opt and sock-set-opt.
The new sock-opt and sock-set-opt functions are wrappers around
getsockopt and setsockopt, respectively.
All POSIX socket options are registered. Platform-specific
options may be added in the future.
* ffi.c (sock_opt, sock_set_opt): New functions.
(ffi_init): Register sock-opt, sock-set-opt, sol-socket,
ipproto-ip, ipproto-ipv6, ipproto-tcp, ipproto-udp,
so-acceptconn, so-broadcast, so-debug, so-dontroute, so-error,
so-keepalive, so-linger, so-oobinline, so-rcvbuf, so-rcvlowat,
so-rcvtimeo, so-reuseaddr, so-sndbuf, so-sndlowat, so-sndtimeo,
so-type, ipv6-join-group, ipv6-leave-group, ipv6-multicast-hops,
ipv6-multicast-if, ipv6-multicast-loop, ipv6-unicast-hops,
ipv6-v6only, tcp-nodelay.
* lisplib.c (sock_set_entries): Add sock-opt and sock-set-opt.
* stdlib/socket.tl (sock-opt): Define as syntactic place.
* tests/014/socket-misc.tl: New cases, for sock-opt.
(set-and-get): New macro.
* txr.1: Documented. Also, mention that sock-bind enables
so-reuseaddr.
* stdlib/doc-syms.tl: Updated.
Diffstat (limited to 'tests/014/socket-misc.tl')
-rw-r--r-- | tests/014/socket-misc.tl | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/tests/014/socket-misc.tl b/tests/014/socket-misc.tl index de57e465..bd94acac 100644 --- a/tests/014/socket-misc.tl +++ b/tests/014/socket-misc.tl @@ -1,8 +1,20 @@ +(load "../sock-common") (load "../common") +(defmacro set-and-get (:env env place val) + (with-update-expander (getter setter) place env + ^(progn (,setter ,val) (,getter)))) + (with-stream (s (open-socket af-inet (logior sock-dgram sock-nonblock))) (test (sock-listen s) t) (let* ((orig #S(sockaddr-in)) (addr orig)) (rotate addr (sock-peer s)) (vtest (sock-peer s) orig))) + +(with-stream (s (open-socket af-inet sock-stream)) + (test (set-and-get (sock-opt s sol-socket so-reuseaddr) 1) 1) + (test (set-and-get (sock-opt s sol-socket so-reuseaddr (ffi int)) 0) 0) + (whenlet ((addr (bindfree s 1025 65535))) + ;; sock-bind enables so-reuseaddr. + (test (sock-opt s sol-socket so-reuseaddr) 1))) |