## plain-socket.sml
## COPYRIGHT (c) 1998 Bell Labs, Lucent Technologies.
stipulate
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 package skt = socket__premicrothread; # socket__premicrothread is from
src/lib/std/socket--premicrothread.pkg #
fun cfun fun_name
=
ci::find_c_function { lib_name => "socket", fun_name }; # If this goes production, this should be converted to use find_c_function' -- compare to
src/lib/std/src/socket/plain-socket--premicrothread.pkgherein
package plain_socket__premicrothread
: Plain_Socket__Premicrothread # Plain_Socket__Premicrothread is from
src/lib/std/src/socket/plain-socket--premicrothread.pkg {
c_socket = cfun "socket": (Int, Int, Int) -> s::sockFD;
c_socket_pair = cfun "socketPair": (Int, Int,Int) -> (s::sockFD * s::sockFD);
fun c_socketPair _
=
raise exception DIE "socketPair not implemented by WinSock"
fun fd2sock fd = s::SOCKET { fd = fd, nb = REF FALSE }
# Create sockets using default protocol:
#
fun make_socket (s::af::AF (af, _), s::socket::SOCKET_TYPE (ty, _))
=
fd2sock (c_socket (af, ty, 0))
fun make_socket_pair (s::af::AF (af, _), s::socket::SOCKET_TYPE (ty, _))
=
{
my (s1, s2) = c_socketPair (af, ty, 0)
in
(fd2sock s1, fd2sock s2)
}
# Create sockets using the specified protocol:
#
fun make_socket' (s::af::AF (af, _), s::socket::SOCKET_TYPE (ty, _), prot)
=
d2sock (c_socket (af, ty, prot))
fun make_socket_pair' (s::af::AF (af, _), s::socket::SOCKET_TYPE (ty, _), prot)
=
{ my (s1, s2) = c_socketPair (af, ty, prot)
#
(fd2sock s1, fd2sock s2)
};
};
end;
## COPYRIGHT (c) 1995 AT&T Bell Laboratories.
## Subsequent changes by Jeff Prothero Copyright (c) 2010-2015,
## released per terms of SMLNJ-COPYRIGHT.