tailhook / rotor

The mio-based framework for rust for doing I/O in simple and composable way (ABANDONED)
MIT License
361 stars 25 forks source link

Pass socket to greedy_stream::Protocol::accepted #1

Closed ebarnard closed 8 years ago

ebarnard commented 8 years ago

This allows a protocol to get details of the underlying stream it is connected to.

e.g.

trait IpStream {
    fn peer_addr(&self) -> io::Result<SocketAddr>;
    fn local_addr(&self) -> io::Result<SocketAddr>;
}

impl IpStream for ::mio::tcp::TcpStream {
    fn peer_addr(&self) -> io::Result<SocketAddr> {
        ::mio::tcp::TcpStream::peer_addr(self)
    }

    fn local_addr(&self) -> io::Result<SocketAddr> {
        ::mio::tcp::TcpStream::local_addr(self)
    }
}

impl<T: IpStream, C, H: Handler<C>+Send> Protocol<T, C> for Client<C, H> {
    fn accepted(conn: &T, _ctx: &mut C) -> Self {
        let local_addr = conn.local_addr();
...
tailhook commented 8 years ago

Looks fine. Thanks!