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
use crate::framed_io::ReaderWriter;
use crate::id_sequence::IdSequence;
use bytesize::ByteSize;
use failure::Error;
use toku_protocol::frames::{Error as ErrorFrame, TokuFrame, Push, Request, Response};
use std::future::Future;
use std::pin::Pin;
use std::time::Duration;
use tokio::net::TcpStream;
#[derive(Debug)]
pub enum DelegatedFrame {
Push(Push),
Request(Request),
Response(Response),
Error(ErrorFrame),
}
#[derive(Debug)]
pub struct Ready {
pub ping_interval: Duration,
pub encoding: &'static str,
}
pub trait Handler: Send + Sync + 'static {
type InternalEvent: Send;
const SEND_GO_AWAY: bool;
fn max_payload_size(&self) -> ByteSize;
fn upgrade(
&self,
tcp_stream: TcpStream,
) -> Pin<Box<dyn Future<Output = Result<TcpStream, Error>> + Send>>;
fn handshake(
&mut self,
reader_writer: ReaderWriter,
) -> Pin<
Box<
dyn Future<Output = Result<(Ready, ReaderWriter), (Error, Option<ReaderWriter>)>>
+ Send,
>,
>;
fn handle_frame(
&mut self,
frame: DelegatedFrame,
encoding: &'static str,
) -> Option<Pin<Box<dyn Future<Output = Result<Response, (Error, u32)>> + Send>>>;
fn handle_internal_event(
&mut self,
event: Self::InternalEvent,
id_sequence: &mut IdSequence,
) -> Option<TokuFrame>;
fn on_ping_received(&mut self);
}
impl From<Push> for DelegatedFrame {
fn from(push: Push) -> DelegatedFrame {
DelegatedFrame::Push(push)
}
}
impl From<Request> for DelegatedFrame {
fn from(request: Request) -> DelegatedFrame {
DelegatedFrame::Request(request)
}
}
impl From<Response> for DelegatedFrame {
fn from(response: Response) -> DelegatedFrame {
DelegatedFrame::Response(response)
}
}
impl From<ErrorFrame> for DelegatedFrame {
fn from(error: ErrorFrame) -> DelegatedFrame {
DelegatedFrame::Error(error)
}
}