Home My Page Projects Code Snippets Project Openings SML/NJ
Summary Activity Forums Tracker Lists Tasks Docs Surveys News SCM Files

SCM Repository

[smlnj] Annotation of /sml/trunk/src/eXene/lib/protocol/xshutdown.sml
ViewVC logotype

Annotation of /sml/trunk/src/eXene/lib/protocol/xshutdown.sml

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2 - (view) (download)

1 : monnier 2 (* xshutdown.sml
2 :     *
3 :     * COPYRIGHT (c) 1990,1991 by John H. Reppy. See COPYRIGHT file for details.
4 :     *
5 :     * This is the shutdown server for eXene. Log open connections and close them on
6 :     * shutdown.
7 :     *)
8 :    
9 :     structure XShutdown : sig
10 :    
11 :     val logConnection : XIo.connection -> unit
12 :     val unlogConnection : XIo.connection -> unit
13 :    
14 :     end = struct
15 :     local
16 :     datatype req
17 :     = LogConn of XIo.connection
18 :     | UnlogConn of XIo.connection
19 :     | Shutdown
20 :    
21 :     val reqCh : req CML.chan = CML.channel()
22 :     val replyCh : unit CML.chan = CML.channel()
23 :    
24 :     fun startServer () = let
25 :     fun loop conns = (case (CML.recv reqCh)
26 :     of LogConn arg => loop (arg::conns)
27 :     | UnlogConn conn => let
28 :     fun remove [] = []
29 :     | remove (c :: r) =
30 :     if XIo.sameConn(c, conn) then r else (c :: (remove r))
31 :     in
32 :     loop (remove conns)
33 :     end
34 :     | Shutdown => (
35 :     TextIO.print(concat[CML.tidToString(CML.getTid()), " ***** shutdown *****\n"]);
36 :     app XIo.closeConn conns;
37 :     CML.send(replyCh, ())))
38 :     in
39 :     CML.spawn (fn () => loop []); ()
40 :     end
41 :    
42 :     fun shutdown () = (CML.send(reqCh, Shutdown); CML.recv replyCh)
43 :    
44 :     val _ = RunCML.logChannel("eXene-shutdown:reqCh", reqCh)
45 :     val _ = RunCML.logChannel("eXene-shutdown:replyCh", replyCh)
46 :     val _ = RunCML.logServer("eXene-shutdown", startServer, shutdown)
47 :    
48 :     in
49 :    
50 :     fun logConnection arg = CML.send(reqCh, LogConn arg)
51 :     fun unlogConnection sock = CML.send(reqCh, UnlogConn sock)
52 :    
53 :     end (* local *)
54 :     end (* XShutdown *)

root@smlnj-gforge.cs.uchicago.edu
ViewVC Help
Powered by ViewVC 1.0.0