Created
April 26, 2016 23:08
-
-
Save sethdusek/690ef4b4b0ac17eab8f5b82374f1980c to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| extern crate mioco; | |
| extern crate time; | |
| extern crate bufstream; | |
| use std::str::FromStr; | |
| use std::net::SocketAddr; | |
| use std::io::prelude::*; | |
| //use std::sync::{Arc, Mutex}; | |
| use std::sync::Arc; | |
| use mioco::sync::Mutex; | |
| //use std::sync::Mutex; | |
| use std::io::BufReader; | |
| use bufstream::BufStream; | |
| use mioco::tcp::TcpStream; | |
| fn _get_time() -> f64 { | |
| let tm = time::get_time(); | |
| tm.sec as f64 + (tm.nsec as f64 / 1000000000.0) | |
| } | |
| fn main() { | |
| mioco::start(|| { | |
| let tcp_stream = TcpStream::connect(&SocketAddr::from_str("127.0.0.1:5555").unwrap()).unwrap(); | |
| let client = Arc::new(Mutex::new(BufStream::new(tcp_stream))); | |
| let mut line = String::new(); | |
| let client_lock = client.clone(); | |
| for line in {(&mut *client_lock.native_lock().lock().unwrap()).lines()} { | |
| let line = line.unwrap(); | |
| println!("liner {}", line); | |
| let mut line_clone = line.clone(); | |
| let mut client_clone = client.clone(); | |
| println!("yielding"); | |
| { | |
| let mut lock = client_lock.native_lock().lock().unwrap(); | |
| lock.write_all(b"hi\n"); | |
| } | |
| println!("never done!"); | |
| }; | |
| }); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment