1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
//use crate::app::slr;
//use crate::codec::*;
//use crate::dictionary::Dictionary;
//use crate::session;
//use crate::session::EventOutbound;
//use std::marker::PhantomData;
//use std::net::TcpListener;
//use uuid::Uuid;
//struct Acceptor<M, E> {
// id: Uuid,
// dictionary: Dictionary,
// encoder: E,
// phantom: PhantomData<M>,
//}
//
//impl<'a, E> Acceptor<slr::Message, E>
//where
// E: Decoder<'a, slr::Message> + Encoder<slr::Message> + 'a,
//{
// pub fn new(dict: Dictionary, encoder: E) -> Self {
// Acceptor {
// id: Uuid::new_v4(),
// dictionary: dict,
// encoder,
// phantom: PhantomData,
// }
// }
//
// pub async fn listen(mut self, listener: TcpListener) {
// self.handle_connection(listener.incoming().map(|stream| stream.unwrap()))
// .await;
// }
//
// async fn handle_connection<T>(
// self,
// listener: impl Iterator<Item = T>,
// ) where T: std::io::Read + std::io::Write {
// let mut payload = Vec::with_capacity(8192);
// let mut offset = 0;
// let config = session::Configuration::new();
// let mut session_layer = session::Acceptor::new(config);
// for mut socket in listener {
// let payload_size = socket.read(&mut payload).unwrap();
// offset += payload_size;
// let msg = self.encoder.decode(&mut &payload[offset..]).ok().unwrap();
// let event = session::EventInbound::IncomingMessage(msg);
// for pending_event in session_layer.notify(event) {
// match pending_event {
// EventOutbound::Message(msg) => {
// let mut payload = Vec::<u8>::new();
// self.encoder.encode(&mut payload, &msg).ok().unwrap();
// socket.write(&payload).unwrap();
// }
// EventOutbound::Terminate => {
// break;
// }
// }
// }
// }
// }
//}