PageRenderTime 12ms CodeModel.GetById 5ms app.highlight 1ms RepoModel.GetById 4ms app.codeStats 0ms

/tutorial/storable/example3/repository_connection.e

http://github.com/tybor/Liberty
Specman e | 55 lines | 44 code | 7 blank | 4 comment | 2 complexity | 447942ec321cbb0c1e5937c8f125db53 MD5 | raw file
 1class REPOSITORY_CONNECTION
 2--
 3-- Handle one connection to the REPOSITORY_SERVER.
 4--
 5inherit
 6	CONNECTION
 7		redefine
 8			set_io
 9		end
10
11create {REPOSITORY_SERVER}
12	make
13
14feature {LOOP_ITEM}
15	continue is
16		do
17			server.update_from_stream(ios)
18			if not ios.is_connected then
19				if ios.error /= Void then
20					std_error.put_line(ios.error)
21				end
22				std_error.put_line(once "Client disconnected")
23			end
24		end
25
26feature {SERVER}
27	set_io (a_io: like ios) is
28		do
29			Precursor(a_io)
30			a_io.when_disconnect(agent handle_disconnect)
31			-- Start by sending the repository
32			std_error.put_line(once "Sending repository")
33			server.write_to_stream(a_io)
34			a_io.flush
35			std_error.put_line(once "Repository sent")
36		end
37
38feature {}
39	server: REPOSITORY_SERVER
40
41	handle_disconnect (a_io: like ios) is
42		require
43			a_io = ios
44			done
45		do
46			server.connection_done(Current)
47		end
48
49	make (a_server: like server) is
50		do
51			std_error.put_line(once "New connection")
52			server := a_server
53		end
54
55end