PreviousUpNext

15.4.1210  src/lib/std/src/socket/proto-socket.pkg

## proto-socket.pkg
#
# Provide some utility operations for threadkit sockets.

# Compiled by:
#     src/lib/std/standard.lib



stipulate
    package iom =  io_now_possible_mailop;                      # io_now_possible_mailop        is from   src/lib/src/lib/thread-kit/src/core-thread-kit/io-now-possible-mailop.pkg
    package md  =  maildrop;                                    # maildrop                      is from   src/lib/src/lib/thread-kit/src/core-thread-kit/maildrop.pkg
#   package mop =  mailop;                                      # mailop                        is from   src/lib/src/lib/thread-kit/src/core-thread-kit/mailop.pkg
    package skt =  socket__premicrothread;                      # socket__premicrothread        is from   src/lib/std/socket--premicrothread.pkg
    package tk  =  threadkit;                                   # threadkit                     is from   src/lib/src/lib/thread-kit/src/core-thread-kit/threadkit.pkg
herein

    package proto_socket
    : (weak)
        api {

            Socket_State
              = UNCONNECTED                                     # Initial state.
              | CONNECTING                                      # Waiting for a connect to complete.
              #
              | CONNECTED                                       # Connected. 
              | ACCEPTING                                       # Waiting for an accept to complete. 
              #
              | WAITING_ON_IO                                   # Waiting on an input and/or output operation. 
              | CLOSED
              ;

            Threadkit_Socket (X, Y)
                =
                THREADKIT_SOCKET
                  {
                    state:   md::Maildrop( Socket_State ),
                    #
                    socket:  skt::Socket( X, Y )
                  };

             make_socket:  skt::Socket( X, Y ) -> Threadkit_Socket (X, Y);

             socket_read_now_possible_on' :  Threadkit_Socket( X, Y ) -> tk::Mailop( Void );
             socket_write_now_possible_on':  Threadkit_Socket( X, Y ) -> tk::Mailop( Void );

        }
    {
        include package   threadkit;                                                    # threadkit             is from   src/lib/src/lib/thread-kit/src/core-thread-kit/threadkit.pkg


        Socket_State
          = UNCONNECTED                                                                 # Initial state.
          | CONNECTING                                                                  # Waiting for a connect to complete.
          #     
          | CONNECTED                                                                   # Connected.
          | ACCEPTING                                                                   # Waiting for an accept to complete. 
          #
          | WAITING_ON_IO                                                               # Waiting on an input and/or output operation.
          | CLOSED
          ;

        Threadkit_Socket (X, Y)
            =
            THREADKIT_SOCKET
              {
                state:    Maildrop( Socket_State ),
                #
                socket:   skt::Socket( X, Y )
              };

        fun make_socket  socket                                                         # Given a Mythryl socket, return a threadkit socket. 
            =
            THREADKIT_SOCKET
              {
                state  => make_full_maildrop  UNCONNECTED,                              # make_full_maildrop    is from   src/lib/src/lib/thread-kit/src/core-thread-kit/maildrop.pkg
                socket
              };

        stipulate
            include package   threadkit;                                                # threadkit             is from   src/lib/src/lib/thread-kit/src/core-thread-kit/threadkit.pkg

            fun socket_to_wait_request  { socket, readable, writable, oobdable }
                =
                { io_descriptor =>  skt::io_descriptor  socket,
                  readable,
                  writable,
                  oobdable
                };

        herein

            fun socket_read_now_possible_on'  (THREADKIT_SOCKET { socket, ... } )       # This is used only in   src/lib/std/src/socket/socket.pkg
                =
                iom::io_now_possible_on'
                    (socket_to_wait_request { socket,
                                              readable => TRUE,
                                              writable => FALSE,
                                              oobdable => FALSE
                                            }
                    )
                    ==>
                    ignore;                                                             # (We're ignoring the returned Io_Plea value.)
                                                                                        # ignore is declared  X -> Void   in   src/lib/core/init/built-in.pkg
                                

            fun socket_write_now_possible_on' (THREADKIT_SOCKET { socket, ... } )       # This is used only in   src/lib/std/src/socket/socket.pkg      
                =
                iom::io_now_possible_on'
                    (socket_to_wait_request { socket,
                                              readable => FALSE,
                                              writable => TRUE,
                                              oobdable => TRUE
                                            }
                    )
                    ==>
                    ignore;                                                             # We're ignoring the returned Io_Plea value.

        end;
    };
end;

## COPYRIGHT (c) 1996 AT&T Research.
## Subsequent changes by Jeff Prothero Copyright (c) 2010-2015,
## released per terms of SMLNJ-COPYRIGHT.


Comments and suggestions to: bugs@mythryl.org

PreviousUpNext