diff options
author | Kaz Kylheku <kaz@kylheku.com> | 2016-02-26 22:55:54 -0800 |
---|---|---|
committer | Kaz Kylheku <kaz@kylheku.com> | 2016-02-26 22:55:54 -0800 |
commit | 4496c575892fa34ae9aabf4e1c0f7da87f10c4c2 (patch) | |
tree | 5e662b6f6bc1bcc42aa834a7703deaa43f92cec5 /lisplib.c | |
parent | 4f14d3a2ded6137c5dd6449f4ec2d566947c4157 (diff) | |
download | txr-4496c575892fa34ae9aabf4e1c0f7da87f10c4c2.tar.gz txr-4496c575892fa34ae9aabf4e1c0f7da87f10c4c2.tar.bz2 txr-4496c575892fa34ae9aabf4e1c0f7da87f10c4c2.zip |
Adding socket support: unix, ipv4, ipv6.
* socket.c, socket.h: New files.
* Makefile: include new socket.o among objects if have_objects
variable is defined to 'y'.
* configure (have_sockets): New variable. New configure test
for socket-related functionality.
(HAVE_SOCKETS, HAVE_GETADDRINFO): New configuration
preprocessor symbols.
Also, reordering the shell probing so that /usr/xpg4/bin/sh
is the last fallback. On Solaris, it chokes on some code
that is needed for Solaris.
* lisplib.c (sock_set_entries, sock_instantiate): New static
functions.
(lisplib_init): Register new functions as autoload hooks.
* share/txr/stdlib/socket.tl: New file.
* stream.c (socket_error_s): New symbol variable.
(struct stdio_handle): New members, family and type, helping
stdio streams represent sockets too.
(stdio_stream_mark): Mark new members of struct stdio_handle.
(make_stdio_stream_common): Initialize new members.
(make_sock_stream, stream_fd, sock_family, sock_type,
open_socket, open_sockfd): New functions.
(stream_init): Initialize socket_error_s variable. Register
sock-family, sock-type and open-socket intrinsic functions.
Register socket-error subtype.
* stream.h (socket_error_s, make_sock_stream, stream_fd,
sock_family, sock_type, open_socket, open_sockfd):
Declared.
Diffstat (limited to 'lisplib.c')
-rw-r--r-- | lisplib.c | 34 |
1 files changed, 34 insertions, 0 deletions
@@ -36,6 +36,7 @@ #include "gc.h" #include "debug.h" #include "txr.h" +#include "socket.h" #include "lisplib.h" val dl_table; @@ -275,6 +276,36 @@ static val yield_instantiate(val set_fun) return nil; } +#if HAVE_SOCKETS + +static val sock_set_entries(val dlt, val fun) +{ + val name[] = { + lit("sockaddr"), lit("sockaddr-in"), lit("sockaddr-in6"), + lit("sockaddr-un"), lit("addrinfo"), + lit("getaddrinfo"), + lit("af-unspec"), lit("af-unix"), lit("af-inet"), lit("af-inet6"), + lit("sock-stream"), lit("sock-dgram"), + lit("sock-nonblock"), lit("sock-cloexec"), + lit("ai-passive"), lit("ai-canonname"), lit("ai-numerichost"), + lit("ai-v4mapped"), lit("ai-all"), lit("ai-addrconfig"), + lit("ai-numericserv"), + nil + }; + set_dlt_entries(dlt, name, fun); + return nil; +} + +static val sock_instantiate(val set_fun) +{ + funcall1(set_fun, nil); + load(format(nil, lit("~a/socket.tl"), stdlib_path, nao)); + sock_load_init(); + return nil; +} + +#endif + val dlt_register(val dlt, val (*instantiate)(val), val (*set_entries)(val, val)) @@ -298,6 +329,9 @@ void lisplib_init(void) dlt_register(dl_table, except_instantiate, except_set_entries); dlt_register(dl_table, type_instantiate, type_set_entries); dlt_register(dl_table, yield_instantiate, yield_set_entries); +#if HAVE_SOCKETS + dlt_register(dl_table, sock_instantiate, sock_set_entries); +#endif } val lisplib_try_load(val sym) |