From ce640c2c25b0e16c567553c5774d633c13cbf0ee Mon Sep 17 00:00:00 2001 From: Till Hoeppner Date: Thu, 7 Aug 2014 13:30:21 +0100 Subject: Setup --- src/lib.rs | 3 ++ src/src/.irsc.rs.swp | Bin 0 -> 12288 bytes src/src/irsc.rs | 106 +++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 109 insertions(+) create mode 100644 src/lib.rs create mode 100644 src/src/.irsc.rs.swp create mode 100644 src/src/irsc.rs (limited to 'src') diff --git a/src/lib.rs b/src/lib.rs new file mode 100644 index 0000000..a93251b --- /dev/null +++ b/src/lib.rs @@ -0,0 +1,3 @@ +#[test] +fn it_works() { +} diff --git a/src/src/.irsc.rs.swp b/src/src/.irsc.rs.swp new file mode 100644 index 0000000..da65aeb Binary files /dev/null and b/src/src/.irsc.rs.swp differ diff --git a/src/src/irsc.rs b/src/src/irsc.rs new file mode 100644 index 0000000..704a0f7 --- /dev/null +++ b/src/src/irsc.rs @@ -0,0 +1,106 @@ +use std::io::{ + BufferedReader, + TcpStream, + IoResult +}; +use std::str; +use std::ascii::StrAsciiExt; +use std::simd::f32x4; + +struct Server { + host: String, + port: u16, + stream: Option +} + +impl Server { + + fn new(host: &str, port: u16) -> Server { + Server { + host: String::from_str(host), + port: port, + stream: None + } + } + + fn connect(&mut self) { + self.stream = Some(TcpStream::connect(self.host.as_slice(), self.port).unwrap()); + + let cs = self.stream.clone(); + spawn(proc() { + Server::listen(cs); + }); + } + + #[inline] + fn sendraw(stream: &mut TcpStream, s: &str) { + stream.write_str(s); + stream.flush(); + } + + #[inline] + fn sendrawln(stream: &mut TcpStream, s: &str) { + Server::sendraw(stream, String::with_capacity(s.len() + 2).append(s).append("\r\n").as_slice()); + } + + fn join(self, channel: &str) { + self.stream.map(|mut st| Server::sendrawln(&mut st, format!("JOIN {}", channel).as_slice())); + } + + fn listen(stream: Option) { + let mut abort = false; + let mut stream = match stream { + Some(s) => s, + None => return + }; + if abort {return;} + let mut reader = BufferedReader::new(stream.clone()); + loop { + let line = reader.read_line().unwrap(); + //println!("{}", line); + let mut parts = line.as_slice().split(' ').collect::>(); + println!("{}", parts); + + if parts.len() == 0 { + continue; + } + + // if message has a prefix + let prefix = if parts.get(0).chars().next().unwrap() == ':' { + parts.shift().unwrap() + } else { "" }; + + match (*parts.get(0)).to_ascii_upper().as_slice() { + "PING" => { + Server::sendrawln(&mut stream, format!("PONG {}", parts.get(1)).as_slice()); + continue; + } + _ => {} + } + + } + } + + +} + +fn main() { + let mut furnet = Server::new("irc.furnet.org", 6667); + furnet.connect(); + + std::io::timer::sleep(5000u64); + + furnet.join("#teenagefurs"); + + // create simd vectors + let x = f32x4(1.0, 2.0, 3.0, 4.0); + let y = f32x4(4.0, 3.0, 2.0, 1.0); + + // simd product + let z = x * y; + + // like any struct, the simd vector can be destructured using `let` + let f32x4(a, b, c, d) = z; + + println!("{}", (a, b, c, d)); +} -- cgit v1.2.3