aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorTill Hoeppner2014-08-07 13:30:21 +0100
committerTill Hoeppner2014-08-07 13:30:21 +0100
commitce640c2c25b0e16c567553c5774d633c13cbf0ee (patch)
tree5bf8f3c73fe4933f55044d42eb431ebe6767ae1a /src
downloadirsc-ce640c2c25b0e16c567553c5774d633c13cbf0ee.tar.gz
irsc-ce640c2c25b0e16c567553c5774d633c13cbf0ee.tar.xz
irsc-ce640c2c25b0e16c567553c5774d633c13cbf0ee.zip
Setup
Diffstat (limited to 'src')
-rw-r--r--src/lib.rs3
-rw-r--r--src/src/.irsc.rs.swpbin0 -> 12288 bytes
-rw-r--r--src/src/irsc.rs106
3 files changed, 109 insertions, 0 deletions
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
--- /dev/null
+++ b/src/src/.irsc.rs.swp
Binary files 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<TcpStream>
+}
+
+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<TcpStream>) {
+ 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::<Vec<&str>>();
+ 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));
+}