-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.rs
61 lines (53 loc) · 1.49 KB
/
main.rs
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
use client;
use proto;
use proto::HeaderType;
use proto::Message;
use std::default::Default;
use std::io::Read;
use std::net::TcpStream;
fn main() {
let s = TcpStream::connect("localhost:9999").unwrap();
let stx = s.try_clone().unwrap();
let mut client = client::Client::new(stx);
let mut version: proto::TRVersion = Default::default();
version.header = proto::Header {
htype: Some(HeaderType::Tversion),
htag: 0,
};
version.msize = 65536;
version.version = "9P2000".to_string();
let rversion = client.get_response(version);
match rversion {
Some(Message::RVersion(x)) => {
client.msize = x.msize;
}
_ => panic!("version mismatch"),
}
let attach = proto::TAttach {
header: proto::Header {
htype: Some(proto::HeaderType::Tattach),
htag: 0,
},
fid: 0,
afid: !0u32,
uname: "kyle".to_string(),
aname: "".to_string(),
};
match client.get_response(attach) {
Some(Message::RAttach(_x)) => {}
_ => panic!("cloud not attach"),
}
let fpath = "/static".to_string();
let mut r = match client.open(fpath.clone(), proto::Mode::Oread) {
Some(r) => r,
_ => panic!("Nope; cant open file"),
};
let mut buffer = String::new();
match r.read_to_string(&mut buffer) {
Ok(c) => {
println!("{}", buffer)
}
_ => panic!("Nope; cant read"),
}
println!("done !");
}