MCPcopy Create free account
hub / github.com/Axosoft/git-rs / init_dispatch

Function init_dispatch

gitrs_server/src/dispatch/mod.rs:32–76  ·  view source on GitHub ↗
(state: Arc<Mutex<state::Shared>>, socket: TcpStream)

Source from the content-addressed store, hash-verified

30}
31
32pub fn init_dispatch(state: Arc<Mutex<state::Shared>>, socket: TcpStream) {
33 use message::protocol::{Inbound, Outbound};
34 let transport: Transport = Builder::new()
35 // Frame header size + max size addressable size of unsigned 32 bit int
36 .max_frame_length(4 + (u32::max_value() as usize))
37 .new_framed(socket);
38 let connection_state = state::Connection::new(state, transport);
39
40 let connection = send_message(
41 connection_state,
42 Outbound::Hello {
43 version: Version::new(0, 1, 0),
44 },
45 ).and_then(|connection_state| {
46 debug!({
47 println!("wrote hello message");
48 });
49 read_validated_message!(Inbound::Hello, connection_state)
50 })
51 .and_then(|(_, connection_state)| send_message(connection_state, Outbound::GladToMeetYou))
52 .and_then(|connection_state| {
53 loop_fn(connection_state, |connection_state| {
54 read_message(connection_state).and_then(
55 |(response, connection_state)| -> Box<
56 Future<
57 Item = Loop<state::Connection, state::Connection>,
58 Error = (::error::protocol::Error, state::Connection),
59 >
60 + Send,
61 > {
62 if let Inbound::Goodbye = response {
63 Box::new(future::ok(Loop::Break(connection_state)))
64 } else {
65 Box::new(dispatch(connection_state, response).map(Loop::Continue))
66 }
67 },
68 )
69 })
70 })
71 .and_then(|transport| send_message(transport, Outbound::Goodbye { error_code: None }))
72 .and_then(|_| Ok(()))
73 .map_err(|(err, _connection_state)| debug!({ println!("error; err={:?}", err) }));
74
75 tokio::spawn(connection);
76}

Callers 1

mainFunction · 0.85

Calls 3

send_messageFunction · 0.85
read_messageFunction · 0.85
dispatchFunction · 0.70

Tested by

no test coverage detected