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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
#![deny(missing_docs)]
#![doc(test(attr(allow(unused_variables), deny(warnings))))]
#[macro_use]
extern crate lazy_static;
extern crate tokio_io;
extern crate tokio_service;
extern crate tokio_proto;
extern crate futures;
extern crate bytes;
pub mod escape;
mod codec;
mod protocol;
mod error_codes;
mod command;
mod transaction;
use tokio_service::Service;
use futures::{future, Future, BoxFuture};
use std::io;
use tokio_proto::TcpServer;
use std::net::{IpAddr, SocketAddr, Ipv4Addr};
use protocol::DbgpProto;
lazy_static! {
static ref DEFAULT_IP_ADDR: Ipv4Addr = {
Ipv4Addr::new(127,0,0,1)
};
}
static DEFAULT_PORT: u16 = 9000;
enum BreakReason {
Ok,
Error,
Aborted,
Exception,
}
enum SessionStatus {
Starting,
Stopping,
Stopped,
Running,
Break(BreakReason),
}
pub struct Session {
address: SocketAddr,
status: Option<SessionStatus>,
}
impl Session {
pub fn new() -> Session {
Session {
address: SocketAddr::new(IpAddr::V4(*DEFAULT_IP_ADDR), DEFAULT_PORT),
status: None,
}
}
pub fn address(mut self, addr: IpAddr) -> Self {
self.address.set_ip(addr);
self
}
pub fn port(mut self, port: u16) -> Self {
self.address.set_port(port);
self
}
pub fn run(self) {
let server = TcpServer::new(DbgpProto, self.address);
server.serve(|| Ok(Echo));
}
}
pub struct Echo;
impl Service for Echo {
type Request = String;
type Response = String;
type Error = io::Error;
type Future = BoxFuture<Self::Response, Self::Error>;
fn call(&self, req: Self::Request) -> Self::Future {
future::ok(req).boxed()
}
}