PreviousUpNext

15.4.1674  src/lib/x-kit/xclient/src/wire/socket-closer-imp-old.pkg

## socket-closer-imp-old.pkg
#
# Track sockets open to X-servers
# and close them all at application exit.

# Compiled by:
#     src/lib/x-kit/xclient/xclient-internals.sublib


stipulate
    include package   threadkit;                                # threadkit             is from   src/lib/src/lib/thread-kit/src/core-thread-kit/threadkit.pkg
    #
    package xok = xsocket_old;                                  # xsocket_old           is from   src/lib/x-kit/xclient/src/wire/xsocket-old.pkg
herein


    package   socket_closer_imp_old
    : (weak)  Socket_Closer_Imp_Old                             # Socket_Closer_Imp_Old is from   src/lib/x-kit/xclient/src/wire/socket-closer-imp-old.api
    {
# my _ = printf "Linkpass/AAA    -- socket-closer-imp-old.pkg\n";
        stipulate
            Plea_Mail
              = NOTE_XSOCKET    xok::Xsocket
              | FORGET_XSOCKET  xok::Xsocket
              | SHUTDOWN
              ;

# my _ = printf "Linkpass/BBB make plea_slot   -- socket-closer-imp-old.pkg\n";
            my plea_slot:  Mailslot( Plea_Mail ) =  make_mailslot ();
# my _ = printf "Linkpass/CCC make reply_slot   -- socket-closer-imp-old.pkg\n";
            my reply_slot: Mailslot( Void      ) =  make_mailslot ();

            fun start_imp ()
                =
                {
# printf "start_imp/AAA  -- socket-closer-imp-old.pkg\n";
                    make_thread "socket_closer_imp"  {. loop []; };
# printf "start_imp/ZZZ  -- socket-closer-imp-old.pkg\n";

                    ();
                }
                where
                    fun loop xsockets
                        =
{
# printf "loop/TOP    -- socket-closer-imp-old.pkg\n";
                        case (take_from_mailslot  plea_slot)
                            #
                            NOTE_XSOCKET arg
                                =>
{
# printf "loop/NOTE_XSOCKET    -- socket-closer-imp-old.pkg\n";
                                loop (arg ! xsockets);
};

                            FORGET_XSOCKET xsocket
                                =>
{
# printf "loop/FORGET_XSOCKET    -- socket-closer-imp-old.pkg\n";
                                loop (remove xsockets)
                                where
                                    fun remove [] => [];
                                        #
                                        remove (c ! r)
                                            =>
                                            xok::same_xsocket (c, xsocket)
                                                ##
                                                ??   r
                                                ::   c ! (remove r);
                                    end;
                                end;
};

                            SHUTDOWN
                                =>
                                {
# printf "loop/SHUTDOWN    -- socket-closer-imp-old.pkg\n";
                                                        {   thread = get_current_microthread (); 
                                                            logger::log_if xlogger::lib_logging 0 {. cat [get_thread's_id_as_string thread, " ***** shutdown *****"]; };
                                                        };

                                    apply  xok::close_xsocket  xsockets;

                                    put_in_mailslot (reply_slot, ());
                                };
                         esac;
};
                end;

            fun shutdown ()
                =
                {
# printf "shutdown/AAA    -- socket-closer-imp-old.pkg\n";
                    put_in_mailslot (plea_slot, SHUTDOWN);
                    take_from_mailslot  reply_slot;
                };

# my _ = printf "Linkpass/DDD:  thread_scheduler_control::note_mailslot(''x-kit-shutdown: plea_slot'', plea_slot);    -- socket-closer-imp-old.pkg\n";
                                                                                                my _ = 
            note_mailslot("x-kit-shutdown: plea_slot", plea_slot);

# my _ = printf "Linkpass/EEE:  thread_scheduler_control::note_mailslot(''x-kit-shutdown: reply_slot'', reply_slot);   -- socket-closer-imp-old.pkg\n";
                                                                                                my _ = 
            note_mailslot("x-kit-shutdown: reply_slot", reply_slot);

# my _ = printf "Linkpass/FFF:  thread_scheduler_control::note_imp { name => ''x-kit-shutdown'', at_startup => start_imp, at_shutdown => shutdown };   -- socket-closer-imp-old.pkg\n";
                                                                                                my _ = 
            note_imp { name => "x-kit-shutdown", at_startup => start_imp, at_shutdown => shutdown };

# my _ = printf "Linkpass/GGG   -- socket-closer-imp-old.pkg\n";
        herein

#           fun   note_xsocket arg    =  put_in_mailslot (plea_slot,   NOTE_XSOCKET arg   );
            fun forget_xsocket socket =  put_in_mailslot (plea_slot, FORGET_XSOCKET socket);

            fun note_xsocket  arg
                =
                {
# printf "note_xsocket/AAA    -- socket-closer-imp-old.pkg\n";
result =
                    put_in_mailslot (plea_slot,   NOTE_XSOCKET arg   );
# printf "note_xsocket/ZZZ    -- socket-closer-imp-old.pkg\n";
result;
                };

        end;
# my _ = printf "Linkpass/ZZZ   -- socket-closer-imp-old.pkg\n";

    };                                          # package socket_closer_imp 
end;                                            # stipulate

## COPYRIGHT (c) 1990, 1991 by John H. Reppy.  See SMLNJ-COPYRIGHT file for details.
## Subsequent changes by Jeff Prothero Copyright (c) 2010-2015,
## released per terms of SMLNJ-COPYRIGHT.


Comments and suggestions to: bugs@mythryl.org

PreviousUpNext