Struct glommio::net::AcceptedTcpStream [−][src]
pub struct AcceptedTcpStream { /* fields omitted */ }
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
Returns the socket address of the remote peer
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::new()
.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
Auto Trait Implementations
impl RefUnwindSafe for AcceptedTcpStream
impl Send for AcceptedTcpStream
impl Sync for AcceptedTcpStream
impl Unpin for AcceptedTcpStream
impl UnwindSafe for AcceptedTcpStream
Blanket Implementations
Mutably borrows from an owned value. Read more
Instruments this type with the provided Span
, returning an
Instrumented
wrapper. Read more
Attaches the provided Subscriber
to this type, returning a
WithDispatch
wrapper. Read more
Attaches the current default Subscriber
to this type, returning a
WithDispatch
wrapper. Read more