pub fn listen<F>(
		conn: TcpStream,
		pool: CpuPool,
		handler: F,
	) -> (Connection, Box<Future<Item = (), Error = Error>>)
	where
		F: Handler + 'static,
	{
		let (reader, writer) = conn.split();

		// Set Max Read to 12 Mb/s
		let reader = ThrottledReader::new(reader, 12_000_000);
		// Set Max Write to 12 Mb/s
		let writer = ThrottledWriter::new(writer, 12_000_000);

		// prepare the channel that will transmit data to the connection writer
		let (tx, rx) = futures::sync::mpsc::unbounded();

		// same for closing the connection
		let (close_tx, close_rx) = futures::sync::mpsc::channel(1);
		let close_conn = close_rx
			.for_each(|_| Ok(()))
			.map_err(|_| Error::ConnectionClose);

		let me = Connection {
			outbound_chan: tx.clone(),
			close_chan: close_tx,
			sent_bytes: Arc::new(Mutex::new(0)),
			received_bytes: Arc::new(Mutex::new(0)),
			error_count: Mutex::new(0),
		};

		// setup the reading future, getting messages from the peer and processing them
		let read_msg = me.read_msg(tx, reader, handler, pool).map(|_| ());

		// setting the writing future
		// getting messages from our system and sending them out
		let write_msg = me.write_msg(rx, writer).map(|_| ());

		// select between our different futures and return them
		let fut = Box::new(
			close_conn
				.select(read_msg.select(write_msg).map(|_| ()).map_err(|(e, _)| e))
				.map(|_| ())
				.map_err(|(e, _)| e),
		);

		(me, fut)
	}
/// Start listening on the provided connection and wraps it. Does not hang
/// the current thread, instead just returns a future and the Connection
/// itself.
Start listening on the provided connection and wraps it. Does not hang
the current thread, instead just returns a future and the Connection
itself.
Start listening on the provided connection and wraps it . Does not hang the current thread instead just returns a future and the Connection itself .
pub fn listen<F>(
		conn: TcpStream,
		pool: CpuPool,
		handler: F,
	) -> (Connection, Box<Future<Item = (), Error = Error>>)
	where
		F: Handler + 'static,
	{
		let (reader, writer) = conn.split();
		// Set Max Read to 12 Mb/s
		let reader = ThrottledReader::new(reader, 12_000_000);
		// Set Max Write to 12 Mb/s
		let writer = ThrottledWriter::new(writer, 12_000_000);
		// prepare the channel that will transmit data to the connection writer
		let (tx, rx) = futures::sync::mpsc::unbounded();
		// same for closing the connection
		let (close_tx, close_rx) = futures::sync::mpsc::channel(1);
		let close_conn = close_rx
			.for_each(|_| Ok(()))
			.map_err(|_| Error::ConnectionClose);
		let me = Connection {
			outbound_chan: tx.clone(),
			close_chan: close_tx,
			sent_bytes: Arc::new(Mutex::new(0)),
			received_bytes: Arc::new(Mutex::new(0)),
			error_count: Mutex::new(0),
		};
		// setup the reading future, getting messages from the peer and processing them
		let read_msg = me.read_msg(tx, reader, handler, pool).map(|_| ());
		// setting the writing future
		// getting messages from our system and sending them out
		let write_msg = me.write_msg(rx, writer).map(|_| ());
		// select between our different futures and return them
		let fut = Box::new(
			close_conn
				.select(read_msg.select(write_msg).map(|_| ()).map_err(|(e, _)| e))
				.map(|_| ())
				.map_err(|(e, _)| e),
		);
		(me, fut)
	}
pub fn listen < F > ( conn : TcpStream , pool : CpuPool , handler : F , ) -> ( Connection , Box < Future < Item = ( ) , Error = Error > > ) where F : Handler + ' static , { let ( reader , writer ) = conn . split ( ) ; // Set Max Read to 12 Mb/s let reader = ThrottledReader :: new ( reader , 12_000_000 ) ; // Set Max Write to 12 Mb/s let writer = ThrottledWriter :: new ( writer , 12_000_000 ) ; // prepare the channel that will transmit data to the connection writer let ( tx , rx ) = futures :: sync :: mpsc :: unbounded ( ) ; // same for closing the connection let ( close_tx , close_rx ) = futures :: sync :: mpsc :: channel ( 1 ) ; let close_conn = close_rx . for_each ( | _ | Ok ( ( ) ) ) . map_err ( | _ | Error :: ConnectionClose ) ; let me = Connection { outbound_chan : tx . clone ( ) , close_chan : close_tx , sent_bytes : Arc :: new ( Mutex :: new ( 0 ) ) , received_bytes : Arc :: new ( Mutex :: new ( 0 ) ) , error_count : Mutex :: new ( 0 ) , } ; // setup the reading future, getting messages from the peer and processing them let read_msg = me . read_msg ( tx , reader , handler , pool ) . map ( | _ | ( ) ) ; // setting the writing future // getting messages from our system and sending them out let write_msg = me . write_msg ( rx , writer ) . map ( | _ | ( ) ) ; // select between our different futures and return them let fut = Box :: new ( close_conn . select ( read_msg . select ( write_msg ) . map ( | _ | ( ) ) . map_err ( | ( e , _ ) | e ) ) . map ( | _ | ( ) ) . map_err ( | ( e , _ ) | e ) , ) ; ( me , fut ) }
Start listening on the provided connection and wraps it.
Start listening on the provided connection and wraps it .
conn
TcpStream
pool
CpuPool
handler
F