PageRenderTime 37ms CodeModel.GetById 34ms app.highlight 1ms RepoModel.GetById 1ms app.codeStats 0ms

/tutorial/net/multiplex_server.e

http://github.com/tybor/Liberty
Specman e | 65 lines | 47 code | 9 blank | 9 comment | 2 complexity | a61c69c71fd1752f767e4e685d13eaec MD5 | raw file
 1class MULTIPLEX_SERVER
 2   --
 3   -- If you try to make a real server using our technology, this class may prove useful. Be sure to have seen
 4   -- the class SOCKETS first.
 5   --
 6
 7insert
 8   SERVER[MULTIPLEX_CONNECTION]
 9      export {} start, start_in_stack
10      end
11
12create {ANY}
13   make
14
15feature {}
16   make
17      local
18         host: HOST; tcp: TCP_ACCESS
19      do
20         -- Start a server on the local machine, listening on port 2001
21         create host.make("localhost")
22         create tcp.make(host, 2001, True)
23         start(tcp)
24      end
25
26   new_connection: MULTIPLEX_CONNECTION
27      do
28         create Result.make(Current)
29      end
30
31   handle_error (error_message: STRING)
32      do
33         if error_message /= Void then
34            std_error.put_string(error_message)
35            std_error.put_new_line
36         else
37            std_error.put_string(once "Could not start the server%N")
38         end
39         die_with_code(1)
40      end
41
42feature {MULTIPLEX_CONNECTION}
43   shutdown
44         -- A connection asked the server to shut down
45      do
46         server.shutdown
47      end
48
49   halt
50         -- A connection asked the server to halt
51      do
52         server.halt
53      end
54
55   connection_done (a_connection: MULTIPLEX_CONNECTION)
56         -- A connection is just finished.
57      do
58         connections := connections - 1
59         if connections = 0 and then server.done then
60            -- and then stack.current_loop /= Void
61            handle_shutdown(server)
62         end
63      end
64
65end -- class MULTIPLEX_SERVER