Struct fizyr_rpc::PeerHandle
source · pub struct PeerHandle<Body> { /* private fields */ }
Expand description
Handle to a peer.
The handle can be used to receive incoming requests and stream messages, and to send requests and stream messages.
When the handle is dropped, the peer loop is stopped. Any open requests will also be terminated.
Implementations§
source§impl<Body> PeerHandle<Body>
impl<Body> PeerHandle<Body>
sourcepub fn split(self) -> (PeerReadHandle<Body>, PeerWriteHandle<Body>)
pub fn split(self) -> (PeerReadHandle<Body>, PeerWriteHandle<Body>)
Split the peer in a read handle and a write handle.
Splitting the peer allows you to move both handles into different tasks.
The original handle is consumed, but the peer loop will keep going until all read and write handles are dropped.
sourcepub async fn recv_message(&mut self) -> Result<ReceivedMessage<Body>, Error>
pub async fn recv_message(&mut self) -> Result<ReceivedMessage<Body>, Error>
Receive the next request or stream message from the remote peer.
Errors for invalid incoming messages are also reported by this function. For example: incoming update messages that are not associated with a received request will be reported as an error here.
sourcepub async fn send_request(
&self,
service_id: i32,
body: impl Into<Body>
) -> Result<SentRequestHandle<Body>, Error>
pub async fn send_request( &self, service_id: i32, body: impl Into<Body> ) -> Result<SentRequestHandle<Body>, Error>
Send a new request to the remote peer.
sourcepub async fn send_stream(
&self,
service_id: i32,
body: impl Into<Body>
) -> Result<(), Error>
pub async fn send_stream( &self, service_id: i32, body: impl Into<Body> ) -> Result<(), Error>
Send a stream message to the remote peer.
sourcepub fn close_handle(&self) -> PeerCloseHandle<Body>
pub fn close_handle(&self) -> PeerCloseHandle<Body>
Make a close handle for the peer.
The close handle can be used to close the connection with the remote peer. It can be cloned and moved around independently.