Struct glommio::net::AcceptedTcpStream
source · pub struct AcceptedTcpStream { /* private fields */ }
Expand description
An Accepted Tcp connection that can be moved to a different executor
This is useful in situations where the load balancing provided by the
Operating System through ReusePort is not desirable. The user can accept the
connection in one executor through shared_accept
which returns an
AcceptedTcpStream.
Once the AcceptedTcpStream
arrives at its destination it can then be made
active with bind_to_executor
Implementations§
source§impl AcceptedTcpStream
impl AcceptedTcpStream
sourcepub fn peer_addr(&self) -> Result<SocketAddr, ()>
pub fn peer_addr(&self) -> Result<SocketAddr, ()>
Returns the socket address of the remote peer
sourcepub fn bind_to_executor(self) -> TcpStream
pub fn bind_to_executor(self) -> TcpStream
Binds this AcceptedTcpStream
to the current executor
This returns a TcpStream
that can then be used normally
§Examples
use glommio::{
channels::shared_channel,
net::TcpListener,
LocalExecutor,
LocalExecutorBuilder,
};
let ex = LocalExecutor::default();
ex.run(async move {
let (sender, receiver) = shared_channel::new_bounded(1);
let sender = sender.connect().await;
let listener = TcpListener::bind("127.0.0.1:0").unwrap();
let accepted = listener.shared_accept().await.unwrap();
sender.try_send(accepted).unwrap();
let ex1 = LocalExecutorBuilder::default()
.spawn(move || async move {
let receiver = receiver.connect().await;
let accepted = receiver.recv().await.unwrap();
let _ = accepted.bind_to_executor();
})
.unwrap();
ex1.join().unwrap();
});
Trait Implementations§
source§impl Clone for AcceptedTcpStream
impl Clone for AcceptedTcpStream
source§fn clone(&self) -> AcceptedTcpStream
fn clone(&self) -> AcceptedTcpStream
Returns a copy of the value. Read more
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source
. Read moresource§impl Debug for AcceptedTcpStream
impl Debug for AcceptedTcpStream
impl Copy for AcceptedTcpStream
Auto Trait Implementations§
impl Freeze for AcceptedTcpStream
impl RefUnwindSafe for AcceptedTcpStream
impl Send for AcceptedTcpStream
impl Sync for AcceptedTcpStream
impl Unpin for AcceptedTcpStream
impl UnwindSafe for AcceptedTcpStream
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more