pub struct Socket(/* private fields */);
Expand description
Generic socket type
Implementations§
Source§impl Socket
impl Socket
Sourcepub fn close(&self) -> bool
pub fn close(&self) -> bool
Closes socket.
Returns true
if operation had effect
Otherwise, if socket is already closed, returns false
Sourcepub fn listen(&self, url: String<'_>) -> Result<(), ErrorCode>
pub fn listen(&self, url: String<'_>) -> Result<(), ErrorCode>
Binds socket to the specified url
, starting to listen for incoming messages.
Sourcepub fn listen_with<T: Options<Listener>>(
&self,
url: String<'_>,
options: &T,
) -> Result<(), ErrorCode>
pub fn listen_with<T: Options<Listener>>( &self, url: String<'_>, options: &T, ) -> Result<(), ErrorCode>
Binds socket to the specified url
, starting to listen for incoming messages.
Allows to provide custom options to initialize listener with. Mostly useful to set optional TLS config
Sourcepub fn connect(&self, url: String<'_>) -> Result<(), ErrorCode>
pub fn connect(&self, url: String<'_>) -> Result<(), ErrorCode>
Connects to the remote peer via url
.
Sourcepub fn connect_with<T: Options<Dialer>>(
&self,
url: String<'_>,
options: ConnectOptions<T>,
) -> Result<(), ErrorCode>
pub fn connect_with<T: Options<Dialer>>( &self, url: String<'_>, options: ConnectOptions<T>, ) -> Result<(), ErrorCode>
Connects to the remote peer via url
, with custom options settings
Sourcepub fn set_opt<T: Options<Self>>(&self, opts: T) -> Result<(), ErrorCode>
pub fn set_opt<T: Options<Self>>(&self, opts: T) -> Result<(), ErrorCode>
Sets options on the socket
It is user responsibility to use options that are valid for the protocol of use
Sourcepub fn try_recv<'a>(
&self,
out: impl Into<BufMut<'a>>,
) -> Result<&'a [u8], ErrorCode>
pub fn try_recv<'a>( &self, out: impl Into<BufMut<'a>>, ) -> Result<&'a [u8], ErrorCode>
Attempts to receive message, writing it in out
buffer if it is of sufficient size,
returning immediately if no message is available
If underlying protocol doesn’t support receiving messages, this shall return error always
Returns written bytes on success
Returns would block error if no message is available.
Sourcepub fn recv<'a>(
&self,
out: impl Into<BufMut<'a>>,
) -> Result<&'a [u8], ErrorCode>
pub fn recv<'a>( &self, out: impl Into<BufMut<'a>>, ) -> Result<&'a [u8], ErrorCode>
Receives message, writing it in out
buffer if it is of sufficient size, waiting forever if none is available.
If underlying protocol doesn’t support receiving messages, this shall return error always
Returns written bytes on success
Sourcepub fn recv_msg(&self) -> Result<Message, ErrorCode>
pub fn recv_msg(&self) -> Result<Message, ErrorCode>
Receives pending message, waiting forever if none is available.
If underlying protocol doesn’t support receiving messages, this shall return error always
Sourcepub fn try_recv_msg(&self) -> Result<Option<Message>, ErrorCode>
pub fn try_recv_msg(&self) -> Result<Option<Message>, ErrorCode>
Receives pending message, waiting forever if none is available.
If underlying protocol doesn’t support receiving messages, this shall return error always
Returns None if no message is available.
Sourcepub fn recv_msg_async(&self) -> Result<FutureResp, ErrorCode>
pub fn recv_msg_async(&self) -> Result<FutureResp, ErrorCode>
Creates new future that attempts to receive message from the socket.
Sourcepub fn send(&self, msg: Buf<'_>) -> Result<(), ErrorCode>
pub fn send(&self, msg: Buf<'_>) -> Result<(), ErrorCode>
Encodes bytes into message and send it over the socket.
Internally message shall be encoded and sent over