+use std::io;
use std::io::{ MemWriter, Acceptor, Listener, TcpStream, IoResult, IoError, EndOfFile };
use std::io::net::tcp::{ TcpAcceptor, TcpListener };
use packet;
fn raw_packet(timestamp: u64) -> Vec<u8> {
let mut m = MemWriter::new();
match (Packet { t: Command(Packet::random_packet_data([42])), timestamp: timestamp }).write(&mut m) {
- Err(e) => vec!(),
+ Err(_) => vec!(),
_ => m.unwrap()
}
}
|client: &mut Client| -> bool {
println!("Send a valid packet...");
match client.end_point.send_with_result(Command(Packet::random_packet_data([42]))) {
- Ok(Ok(packet@Packet { t: Answer(..), .. })) => true,
+ Ok(Ok(Packet { t: Answer(..), .. })) => true,
other => {
println!("Error: {}", other);
false
let mut raw_packet = raw_packet(client.end_point.current_timestamp);
raw_packet[2] = 0xEE; // Alter the type.
match client.end_point.send_raw_with_result(raw_packet.as_slice()) {
- Ok(Err(packet::IOReadError( IoError { kind: TimedOut, .. }))) => true, // OK: the server should not send any packet.
+ Ok(Err(packet::IOReadError( IoError { kind: io::TimedOut, .. }))) => true, // OK: the server should not send any packet.
other => {
println!("Error: {}", other);
false
client.end_point.current_timestamp += 1;
let raw_packet = raw_packet(0);
match client.end_point.send_raw_with_result(raw_packet.as_slice()) {
- Ok(Err(packet::IOReadError( IoError { kind: TimedOut, .. }))) => true, // OK: the server should not send any packet.
+ Ok(Err(packet::IOReadError( IoError { kind: io::TimedOut, .. }))) => true, // OK: the server should not send any packet.
other => {
println!("Error: {}", other);
false
raw_packet[13] = 0xBE;
raw_packet[14] = 0xEF;
match client.end_point.send_raw_with_result(raw_packet.as_slice()) {
- Ok(Ok(packet@Packet { t: Error(packet::AuthError), .. })) => true,
+ Ok(Ok(Packet { t: Error(packet::AuthError), .. })) => true,
other => {
println!("Error: {}", other);
false
|client: &mut Client| -> bool {
println!("Send a packet with too small data...");
- let mut command = Command(Packet::new_packet_data(0, Vec::from_elem(6, 0x00)));
+ let command = Command(Packet::new_packet_data(0, Vec::from_elem(6, 0x00)));
match client.end_point.send_with_result(command) {
- Ok(Err(packet::IOReadError( IoError { kind: TimedOut, .. }))) => true, // OK: the server should not send any packet.
+ Ok(Err(packet::IOReadError( IoError { kind: io::TimedOut, .. }))) => true, // OK: the server should not send any packet.
other => {
println!("Error: {}", other);
false
|client: &mut Client| -> bool {
println!("Send a packet with too large data...");
- let mut command = Command(Packet::new_packet_data(0, Vec::from_elem(40, 0x00)));
+ let command = Command(Packet::new_packet_data(0, Vec::from_elem(40, 0x00)));
match client.end_point.send_with_result(command) {
- Ok(Err(packet::IOReadError( IoError { kind: TimedOut, .. }))) => true, // OK: the server should not send any packet.
+ Ok(Err(packet::IOReadError( IoError { kind: io::TimedOut, .. }))) => true, // OK: the server should not send any packet.
other => {
println!("Error: {}", other);
false
client.end_point.current_timestamp += 1;
let mut m = MemWriter::new();
let raw_packet = match (Packet { t: Command(Packet::random_packet_data([42])), timestamp: client.end_point.current_timestamp }).write_with_padding_fun(&mut m, |_, _| -> u8 { 0 }) {
- Err(e) => vec!(),
+ Err(_) => vec!(),
_ => m.unwrap()
};
match client.end_point.send_raw_with_result(raw_packet.as_slice()) {
- Ok(Ok(packet@Packet { t: Error(packet::CryptError), .. })) => true,
+ Ok(Ok(Packet { t: Error(packet::CryptError), .. })) => true,
other => {
println!("Error: {}", other);
false