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
extern crate bincode;
extern crate byteorder;
#[macro_use]
extern crate log;
extern crate rustc_serialize;
extern crate term_painter as term;
pub mod auth;
pub mod conn;
pub mod logger;
pub mod net;
pub mod parse;
pub mod query;
pub mod storage;
use std::net::{Ipv4Addr, SocketAddrV4};
#[derive(Debug)]
pub struct Config {
pub address: Ipv4Addr,
pub port: u16,
pub dir: String
}
pub fn listen(config: Config) {
use std::net::TcpListener;
use std::thread;
let sock_addr = SocketAddrV4::new(config.address, config.port);
let listener = TcpListener::bind(sock_addr).unwrap();
for stream in listener.incoming() {
match stream {
Ok(stream) => {
thread::spawn(move|| {
conn::handle(stream)
});
},
Err(e) => {
warn!("Failed to accept incoming connection: {:?}", e);
},
}
}
}