use reactor::{Reactor, ShutdownHandle, ReactorConfig};
use tcp::protocol::{ReactorProtocol};
use tcp::{TcpProtocol};
use mio::tcp::{TcpListener};
use std::io::{self};
pub struct TcpReactor<P: TcpProtocol> {
reactor: Reactor<ReactorProtocol<P>>,
}
impl<P: TcpProtocol> TcpReactor<P> {
pub fn new(proto: P, listener: TcpListener) -> io::Result<TcpReactor<P>> {
TcpReactor::with_configuration(proto, listener, ReactorConfig::default())
}
pub fn with_configuration(proto: P, listener: TcpListener, config: ReactorConfig) -> io::Result<TcpReactor<P>> {
let reactor_proto = ReactorProtocol::new(proto, listener);
let reactor = try!(Reactor::with_configuration(reactor_proto, config));
Ok(TcpReactor{
reactor: reactor,
})
}
pub fn run(&mut self) -> io::Result<()> {
self.reactor.run()
}
pub fn shutdown_handle(&self) -> ShutdownHandle {
self.reactor.shutdown_handle()
}
pub fn spin_once(&mut self) -> io::Result<()> {
self.reactor.spin_once()
}
}