[][src]Struct snarkos_network::message::channel::Channel

pub struct Channel {
    pub address: SocketAddr,
    pub reader: Arc<Mutex<TcpStream>>,
    pub writer: Arc<Mutex<TcpStream>>,
}

A Channel for reading and writing messages to a peer. Storing two streams allows for simultaneous reading/writing. Each stream is protected by an Arc + Mutex to allow for channel cloning.

Fields

address: SocketAddrreader: Arc<Mutex<TcpStream>>writer: Arc<Mutex<TcpStream>>

Implementations

impl Channel[src]

pub async fn new(
    address: SocketAddr,
    reader: Arc<Mutex<TcpStream>>,
    writer: Arc<Mutex<TcpStream>>
) -> Result<Self, ConnectError>
[src]

pub async fn new_write_only(address: SocketAddr) -> Result<Self, ConnectError>[src]

Returns a new channel with a writer only stream.

pub fn new_read_only(reader: TcpStream) -> Result<Self, ConnectError>[src]

Returns a new channel with a reader only stream.

pub fn update_address(&self, address: SocketAddr) -> Self[src]

Returns a new channel with the specified address.

pub fn update_reader(&self, reader: Arc<Mutex<TcpStream>>) -> Self[src]

Returns a new channel with the specified reader stream.

pub async fn update_writer<'_>(
    &'_ self,
    address: SocketAddr
) -> Result<Self, ConnectError>
[src]

Returns a new channel with the specified address and new writer stream.

pub async fn write<M: Message, '_, '_>(
    &'_ self,
    message: &'_ M
) -> Result<(), ConnectError>
[src]

Writes a message header + message.

pub async fn read<'_>(&'_ self) -> Result<(MessageName, Vec<u8>), ConnectError>[src]

Reads a message header + message.

Trait Implementations

impl Clone for Channel[src]

impl Debug for Channel[src]

Auto Trait Implementations

impl !RefUnwindSafe for Channel

impl Send for Channel

impl Sync for Channel

impl Unpin for Channel

impl !UnwindSafe for Channel

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> Same<T> for T

type Output = T

Should always be Self

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.

impl<V, T> VZip<V> for T where
    V: MultiLane<T>,