


## 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.pkgherein
package plain_socket
: Plain_Socket
{
package s = Socket
fun socket_fn fun_name
=
ci::find_c_function { lib_name => "socket", fun_name };
my c_socket: (Int * Int * Int) -> s::sockFD
= socket_fn "socket"
/* my c_socketPair: (Int * Int * Int) -> (s::sockFD * s::sockFD)
= socket_fn "socketPair"*/
fun c_socketPair _
=
raise exception FAIL "socketPair not implemented by WinSock"
fun fd2sock fd = s::SOCKET { fd = fd, nb = REF FALSE }
# Create sockets using default protocol:
#
fun socket (s::af::AF (af, _), s::socket::SOCKET_TYPE (ty, _))
=
fd2sock (c_socket (af, ty, 0))
fun socketPair (s::af::AF (af, _), s::socket::SOCKET_TYPE (ty, _)) = let
my (s1, s2) = c_socketPair (af, ty, 0)
in
(fd2sock s1, fd2sock s2)
end
# Create sockets using the specified protocol:
#
fun socket' (s::af::AF (af, _), s::socket::SOCKET_TYPE (ty, _), prot)
=
d2sock (c_socket (af, ty, prot))
fun socketPair' (s::af::AF (af, _), s::socket::SOCKET_TYPE (ty, _), prot) = let
my (s1, s2) = c_socketPair (af, ty, prot)
in
(fd2sock s1, fd2sock s2)
end
};
end;
## COPYRIGHT (c) 1995 AT&T Bell Laboratories.
## Subsequent changes by Jeff Prothero Copyright (c) 2010-2012,
## released under Gnu Public Licence version 3.


