## internet-socket--premicrothread.pkg
# Compiled by:
#
src/lib/std/src/standard-core.sublibstipulate
package sg = socket_guts; # socket_guts is from
src/lib/std/src/socket/socket-guts.pkg package gs = plain_socket__premicrothread; # plain_socket__premicrothread is from
src/lib/std/src/socket/plain-socket--premicrothread.pkg package ps = proto_socket__premicrothread; # proto_socket__premicrothread is from
src/lib/std/src/socket/proto-socket--premicrothread.pkg package ci = mythryl_callable_c_library_interface; # mythryl_callable_c_library_interface is from
src/lib/std/src/unsafe/mythryl-callable-c-library-interface.pkg #
fun cfun fun_name
=
ci::find_c_function'' { lib_name => "socket", fun_name };
herein
package internet_socket__premicrothread
: (weak) Internet_Socket__Premicrothread # Internet_Socket__Premicrothread is from
src/lib/std/src/socket/internet-socket--premicrothread.api {
Inet = INET; # Witness type for sockets.
Socket(X) = ps::Socket( Inet, X );
Stream_Socket(X) = Socket( sg::Stream(X) );
Datagram_Socket = Socket( sg::Datagram );
Socket_Address = ps::Socket_Address( Inet );
inet_af = null_or::the (sg::af::from_string "INET");
(cfun "toInetAddr") # toInetAddr def in src/c/lib/socket/to-inetaddr.c
->
( to_inet_addr__syscall: (ps::Internet_Address, Int) -> ps::Internet_Address,
to_inet_addr__ref,
set__to_inet_addr__ref
);
(cfun "fromInetAddr") # fromInetAddr def in src/c/lib/socket/from-inetaddr.c
->
( from_inet_addr__syscall: ps::Internet_Address -> (ps::Internet_Address, Int),
from_inet_addr__ref,
set__from_inet_addr__ref
);
(cfun "inetany") # inetany def in src/c/lib/socket/inetany.c
->
( inet_any__syscall: Int -> ps::Internet_Address,
inet_any__ref,
set__inet_any__ref
);
fun to_address (ina, port)
=
ps::ADDRESS (*to_inet_addr__ref (dns_host_lookupinternal::un_internet_address ina, port));
fun from_address (ps::ADDRESS address)
=
{ (*from_inet_addr__ref address)
->
(a, port);
(dns_host_lookupinternal::internet_address a, port);
};
fun any port
=
ps::ADDRESS (*inet_any__ref port);
# plain_socket__premicrothread is from
src/lib/std/src/socket/plain-socket--premicrothread.pkg package udp {
#
fun make_socket () = gs::make_socket (inet_af, sg::typ::datagram );
fun make_socket' proto = gs::make_socket' (inet_af, sg::typ::datagram, proto);
};
(cfun "get_or_set_socket_nodelay_option") # "get_or_set_socket_nodelay_option" def in src/c/lib/socket/get-or-set-socket-nodelay-option.c
->
( ctl_delay__syscall: (Int, Null_Or(Bool)) -> Bool,
ctl_delay__ref,
set__ctl_delay__ref
);
package tcp {
#
fun make_socket () = gs::make_socket (inet_af, sg::typ::stream );
fun make_socket' proto = gs::make_socket' (inet_af, sg::typ::stream, proto);
# tcp control options
fun get_nodelay socket_file_descriptor
=
*ctl_delay__ref (socket_file_descriptor, NULL);
fun set_nodelay (socket_file_descriptor, flag)
=
ignore (*ctl_delay__ref (socket_file_descriptor, THE flag));
};
to_string = ps::to_string;
(cfun "setPrintIfFd") # setPrintIfFd is in src/c/lib/socket/setprintiffd.c
->
( set_printif_fd__syscall: Int -> Void,
set_printif_fd__ref,
set__set_printif_fd__ref
);
fun set_printif_fd fd
=
*set_printif_fd__ref fd;
#
# Enable socket I/O debug fprintfs to given
# fd -- see src/c/lib/socket/setprintiffd.c
# (There might be a better package to put this in...?)
};
end;
## COPYRIGHT (c) 1995 AT&T Bell Laboratories.
## Subsequent changes by Jeff Prothero Copyright (c) 2010-2015,
## released per terms of SMLNJ-COPYRIGHT.