extern crate mioco;
extern crate env_logger;

use std::net::SocketAddr;
use std::str::FromStr;
use std::io::Write;
use mioco::mio::tcp::{TcpSocket};

const DEFAULT_LISTEN_ADDR : &'static str = "127.0.0.1:5555";

fn listend_addr() -> SocketAddr {
    FromStr::from_str(DEFAULT_LISTEN_ADDR).unwrap()
}

const RESPONSE: &'static str = "HTTP/1.1 200 OK\r
Content-Length: 14\r
\r
Hello World\r
\r";

fn main() {
    env_logger::init().unwrap();
    let addr = listend_addr();

    let sock = TcpSocket::v4().unwrap();
    sock.bind(&addr).unwrap();
    let sock = sock.listen(1024).unwrap();

    println!("Starting \"cheating\" http server on {:?}", sock.local_addr().unwrap());

    mioco::start(move |mioco| {
        for _ in 0..8 {
            let sock = try!(sock.try_clone());
            mioco.spawn(move |mioco| {
                let sock = mioco.wrap(sock);
                loop {
                    let conn = try!(sock.accept());
                    mioco.spawn(move |mioco| {
                        let mut conn = mioco.wrap(conn);
                        loop {
                            let _ = try!(conn.write(&RESPONSE.as_bytes()));
                        }
                    });
                }
            });
        }
        Ok(())
    });
}

Add "cheating" http server example.
Add "cheating" http server example.

Because I'm a showoff.

% wrk -t8 -c100 -d10s http://localhost:5555
Running 10s test @ http://localhost:5555
  8 threads and 100 connections
  Thread Stats   Avg      Stdev     Max   +/- Stdev
    Latency     5.01s     2.37s    7.98s    69.04%
    Req/Sec   554.67k   582.15k    3.28M    84.58%
  74197525 requests in 10.39s, 3.66GB read
  Socket errors: connect 0, read 142, write 0, timeout 192
Requests/sec: 7143230.20
Transfer/sec:    361.04MB
