PreviousUpNext

15.4.1207  src/lib/std/src/socket/plain-socket–premicrothread.pkg

## plain-socket--premicrothread.pkg

# Compiled by:
#     src/lib/std/src/standard-core.sublib


stipulate
    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 };                                       # socket                                is in     src/c/lib/socket/cfun-list.h
herein

    package   plain_socket__premicrothread
    : (weak)  Plain_Socket__Premicrothread                                                              # Plain_Socket__Premicrothread          is from   src/lib/std/src/socket/plain-socket--premicrothread.api
    {
        (cfun "socket")                                                                                 # socket                                def in    src/c/lib/socket/socket.c
            ->                                                                                          # "c_socket" is probably "create_socket"
            (      c_socket__syscall:   (Int, Int, Int) -> ps::Socket_Fd,                               # (domain, type, protocol) -> Socket_Fd
                   c_socket__ref,
              set__c_socket__ref
            );

        (cfun "socketPair")                                                                             # socketPair                            def in    src/c/lib/socket/socketpair.c
            ->                                                                                          # "c_socket_pair" is probably "create_socket_pair"
            (      c_socket_pair__syscall:    (Int, Int, Int) -> (ps::Socket_Fd, ps::Socket_Fd),        # (domain, type, protocol) -> Socket_Fd
                   c_socket_pair__ref,
              set__c_socket_pair__ref
            );


        fun fd2sock file_descriptor
            =
            file_descriptor;


        #  Create sockets using default protocol 
        #
        fun make_socket ( ps::af::ADDRESS_FAMILY { id => af, ... },
                          ps::typ::SOCKET_TYPE   { id => ty, ... }
                        )
            =
            fd2sock (*c_socket__ref (af, ty, 0));

        fun make_socket_pair ( ps::af::ADDRESS_FAMILY { id => af, ... },
                               ps::typ::SOCKET_TYPE   { id => ty, ... }
                             )
            =
            {   (*c_socket_pair__ref (af, ty, 0))
                    ->
                    (s1, s2);

                ( fd2sock s1,
                  fd2sock s2
                );
            };

        #  Create sockets using the specified protocol 
        #
        fun make_socket' ( ps::af::ADDRESS_FAMILY { id => af, ... },
                           ps::typ::SOCKET_TYPE   { id => ty, ... },
                           protocol
                         )
            =
            fd2sock (*c_socket__ref (af, ty, protocol));


        fun make_socket_pair' ( ps::af::ADDRESS_FAMILY { id => af, ... },
                                ps::typ::SOCKET_TYPE   { id => ty, ... },
                                protocol
                              )
            =
            {   (*c_socket_pair__ref (af, ty, protocol))
                    ->
                    (s1, s2);

                ( 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.


Comments and suggestions to: bugs@mythryl.org

PreviousUpNext