Trait pravega_wire_protocol::connection::Connection [−][src]
Connection can send and read data using a TCP connection
Required methods
#[must_use]fn send_async<'life0, 'life1, 'async_trait>(
&'life0 mut self,
payload: &'life1 [u8]
) -> Pin<Box<dyn Future<Output = Result<(), ConnectionError>> + Send + 'async_trait>> where
'life0: 'async_trait,
'life1: 'async_trait,
Self: 'async_trait,
[src]
&'life0 mut self,
payload: &'life1 [u8]
) -> Pin<Box<dyn Future<Output = Result<(), ConnectionError>> + Send + 'async_trait>> where
'life0: 'async_trait,
'life1: 'async_trait,
Self: 'async_trait,
send_async will send a byte array payload to the remote server asynchronously.
Example
use pravega_wire_protocol::connection_factory::{ConnectionFactory, ConnectionFactoryConfig}; use pravega_client_shared::PravegaNodeUri; use pravega_client_config::connection_type::ConnectionType; use tokio::runtime::Runtime; fn main() { let mut rt = Runtime::new().unwrap(); let endpoint = PravegaNodeUri::from("localhost:8080".to_string()); let config = ConnectionFactoryConfig::new(ConnectionType::Tokio); let cf = ConnectionFactory::create(config); let connection_future = cf.establish_connection(endpoint); let mut connection = rt.block_on(connection_future).unwrap(); let mut payload: Vec<u8> = Vec::new(); let fut = connection.send_async(&payload); }
#[must_use]fn read_async<'life0, 'life1, 'async_trait>(
&'life0 mut self,
buf: &'life1 mut [u8]
) -> Pin<Box<dyn Future<Output = Result<(), ConnectionError>> + Send + 'async_trait>> where
'life0: 'async_trait,
'life1: 'async_trait,
Self: 'async_trait,
[src]
&'life0 mut self,
buf: &'life1 mut [u8]
) -> Pin<Box<dyn Future<Output = Result<(), ConnectionError>> + Send + 'async_trait>> where
'life0: 'async_trait,
'life1: 'async_trait,
Self: 'async_trait,
read_async will read exactly the amount of data needed to fill the provided buffer asynchronously.
Example
use pravega_wire_protocol::connection_factory::{ConnectionFactory, ConnectionFactoryConfig}; use pravega_client_shared::PravegaNodeUri; use pravega_client_config::connection_type::ConnectionType; use tokio::runtime::Runtime; fn main() { let mut rt = Runtime::new().unwrap(); let endpoint = PravegaNodeUri::from("localhost:8080".to_string()); let config = ConnectionFactoryConfig::new(ConnectionType::Tokio); let cf = ConnectionFactory::create(config); let connection_future = cf.establish_connection(endpoint); let mut connection = rt.block_on(connection_future).unwrap(); let mut buf = [0; 10]; let fut = connection.read_async(&mut buf); }
fn split(
&mut self
) -> (Box<dyn ConnectionReadHalf>, Box<dyn ConnectionWriteHalf>)
[src]
&mut self
) -> (Box<dyn ConnectionReadHalf>, Box<dyn ConnectionWriteHalf>)
Splits the Connection into a read half and a writer half so they can be owned by different threads.
fn get_endpoint(&self) -> PravegaNodeUri
[src]
Returns the endpoint of this Connection.
fn get_uuid(&self) -> Uuid
[src]
Returns the id of this Connection.
fn is_valid(&self) -> bool
[src]
Checks if this connection is valid. A Connection is considered to be invalid after split so it can be discarded when returning to the connection pol.
Implementors
impl Connection for TlsConnection
[src]
fn send_async<'life0, 'life1, 'async_trait>(
&'life0 mut self,
payload: &'life1 [u8]
) -> Pin<Box<dyn Future<Output = Result<(), ConnectionError>> + Send + 'async_trait>> where
'life0: 'async_trait,
'life1: 'async_trait,
Self: 'async_trait,
[src]
&'life0 mut self,
payload: &'life1 [u8]
) -> Pin<Box<dyn Future<Output = Result<(), ConnectionError>> + Send + 'async_trait>> where
'life0: 'async_trait,
'life1: 'async_trait,
Self: 'async_trait,
fn read_async<'life0, 'life1, 'async_trait>(
&'life0 mut self,
buf: &'life1 mut [u8]
) -> Pin<Box<dyn Future<Output = Result<(), ConnectionError>> + Send + 'async_trait>> where
'life0: 'async_trait,
'life1: 'async_trait,
Self: 'async_trait,
[src]
&'life0 mut self,
buf: &'life1 mut [u8]
) -> Pin<Box<dyn Future<Output = Result<(), ConnectionError>> + Send + 'async_trait>> where
'life0: 'async_trait,
'life1: 'async_trait,
Self: 'async_trait,
fn split(
&mut self
) -> (Box<dyn ConnectionReadHalf>, Box<dyn ConnectionWriteHalf>)
[src]
&mut self
) -> (Box<dyn ConnectionReadHalf>, Box<dyn ConnectionWriteHalf>)
fn get_endpoint(&self) -> PravegaNodeUri
[src]
fn get_uuid(&self) -> Uuid
[src]
fn is_valid(&self) -> bool
[src]
impl Connection for TokioConnection
[src]
fn send_async<'life0, 'life1, 'async_trait>(
&'life0 mut self,
payload: &'life1 [u8]
) -> Pin<Box<dyn Future<Output = Result<(), ConnectionError>> + Send + 'async_trait>> where
'life0: 'async_trait,
'life1: 'async_trait,
Self: 'async_trait,
[src]
&'life0 mut self,
payload: &'life1 [u8]
) -> Pin<Box<dyn Future<Output = Result<(), ConnectionError>> + Send + 'async_trait>> where
'life0: 'async_trait,
'life1: 'async_trait,
Self: 'async_trait,
fn read_async<'life0, 'life1, 'async_trait>(
&'life0 mut self,
buf: &'life1 mut [u8]
) -> Pin<Box<dyn Future<Output = Result<(), ConnectionError>> + Send + 'async_trait>> where
'life0: 'async_trait,
'life1: 'async_trait,
Self: 'async_trait,
[src]
&'life0 mut self,
buf: &'life1 mut [u8]
) -> Pin<Box<dyn Future<Output = Result<(), ConnectionError>> + Send + 'async_trait>> where
'life0: 'async_trait,
'life1: 'async_trait,
Self: 'async_trait,
fn split(
&mut self
) -> (Box<dyn ConnectionReadHalf>, Box<dyn ConnectionWriteHalf>)
[src]
&mut self
) -> (Box<dyn ConnectionReadHalf>, Box<dyn ConnectionWriteHalf>)
fn get_endpoint(&self) -> PravegaNodeUri
[src]
fn get_uuid(&self) -> Uuid
[src]
fn is_valid(&self) -> bool
[src]
impl Connection for MockConnection
[src]
fn send_async<'life0, 'life1, 'async_trait>(
&'life0 mut self,
payload: &'life1 [u8]
) -> Pin<Box<dyn Future<Output = Result<(), ConnectionError>> + Send + 'async_trait>> where
'life0: 'async_trait,
'life1: 'async_trait,
Self: 'async_trait,
[src]
&'life0 mut self,
payload: &'life1 [u8]
) -> Pin<Box<dyn Future<Output = Result<(), ConnectionError>> + Send + 'async_trait>> where
'life0: 'async_trait,
'life1: 'async_trait,
Self: 'async_trait,
fn read_async<'life0, 'life1, 'async_trait>(
&'life0 mut self,
buf: &'life1 mut [u8]
) -> Pin<Box<dyn Future<Output = Result<(), ConnectionError>> + Send + 'async_trait>> where
'life0: 'async_trait,
'life1: 'async_trait,
Self: 'async_trait,
[src]
&'life0 mut self,
buf: &'life1 mut [u8]
) -> Pin<Box<dyn Future<Output = Result<(), ConnectionError>> + Send + 'async_trait>> where
'life0: 'async_trait,
'life1: 'async_trait,
Self: 'async_trait,
fn split(
&mut self
) -> (Box<dyn ConnectionReadHalf>, Box<dyn ConnectionWriteHalf>)
[src]
&mut self
) -> (Box<dyn ConnectionReadHalf>, Box<dyn ConnectionWriteHalf>)