-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Checkpoint: partial implementation. This version crashes the compiler in
Nightly.
- Loading branch information
Showing
2 changed files
with
117 additions
and
1 deletion.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,4 +3,7 @@ name = "tls_interop" | |
version = "0.1.0" | ||
authors = ["EKR <ekr@rtfm.com>"] | ||
|
||
[features] | ||
|
||
[dependencies] | ||
mio = "0.6" |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,116 @@ | ||
extern crate mio; | ||
use mio::*; | ||
use mio::tcp::{TcpListener, TcpStream}; | ||
use std::io::Read; | ||
use std::process::{Child, Command}; | ||
|
||
const SERVER: Token = mio::Token(0); | ||
const A1: Token = mio::Token(0); | ||
const A2: Token = mio::Token(1); | ||
|
||
struct Agent { | ||
name : String, | ||
path : String, | ||
args : Vec<String>, | ||
socket : TcpStream, | ||
child: Child | ||
} | ||
|
||
impl Agent { | ||
fn new(name: String, path: String, args: Vec<String>) -> Result<Agent, i32> { | ||
let addr = "127.0.0.1:13265".parse().unwrap(); | ||
let listener = TcpListener::bind(&addr).unwrap(); | ||
|
||
// Start the subprocess. | ||
let mut command = Command::new(path.clone()); | ||
for arg in args.iter() { | ||
command.arg(arg); | ||
} | ||
|
||
command.arg("-port"); | ||
command.arg(listener.local_addr().unwrap().port().to_string()); | ||
|
||
let mut child = command.spawn().unwrap(); | ||
|
||
// Listen for connect | ||
// Create an poll instance | ||
let poll = Poll::new().unwrap(); | ||
poll.register(&listener, SERVER, Ready::readable(), | ||
PollOpt::edge()).unwrap(); | ||
let mut events = Events::with_capacity(1024); | ||
|
||
poll.poll(&mut events, None).unwrap(); | ||
for event in events.iter() { | ||
match event.token() { | ||
SERVER => { | ||
let sock = listener.accept(); | ||
|
||
println!("Accepted"); | ||
|
||
return Ok(Agent { | ||
name: name, | ||
path: path, | ||
args: args, | ||
child: child, | ||
socket: sock.unwrap().0, | ||
}) | ||
}, | ||
_ => return Err(-1), | ||
} | ||
} | ||
|
||
unreachable!() | ||
} | ||
} | ||
|
||
fn copy_data(from: &Agent, to: &Agent) { | ||
let mut buf = [u8; 1024]; | ||
let size = from.socket.read(buf); | ||
} | ||
|
||
fn shuttle(agents: Vec<Agent>) { | ||
// Listen for connect | ||
// Create an poll instance | ||
let poll = Poll::new().unwrap(); | ||
poll.register(&agents[0].socket, A1, Ready::readable(), | ||
PollOpt::level()).unwrap(); | ||
poll.register(&agents[1].socket, A1, Ready::readable(), | ||
PollOpt::level()).unwrap(); | ||
let mut events = Events::with_capacity(1024); | ||
|
||
poll.poll(&mut events, None).unwrap(); | ||
loop { | ||
for event in events.iter() { | ||
match event.token() { | ||
A1 => { | ||
println!("A0 ready"); | ||
}, | ||
A2 => { | ||
println!("A1 ready"); | ||
}, | ||
_ => unreachable!() | ||
} | ||
} | ||
} | ||
} | ||
|
||
fn main() { | ||
println!("Hello, world!"); | ||
let mut agents: Vec<Agent> = Vec::new(); | ||
|
||
let a1 = Agent::new(String::from("a1"), | ||
String::from("/Users/ekr/dev/boringssl//build/ssl/test/bssl_shim"), | ||
Vec::new()); | ||
agents.push(a1.unwrap()); | ||
|
||
let a2 = Agent::new(String::from("a2"), | ||
String::from("/Users/ekr/dev/boringssl//build/ssl/test/bssl_shim"), | ||
vec![String::from("-server"), | ||
String::from("-key-file"), | ||
String::from("/Users/ekr/dev/boringssl/ssl/test/runner/server.pem"), | ||
String::from("-cert-file"), | ||
String::from("/Users/ekr/dev/boringssl/ssl/test/runner/server.pem")] | ||
); | ||
agents.push(a2.unwrap()); | ||
|
||
shuttle(agents); | ||
} |