Struct Socket

Source
pub struct Socket(/* private fields */);
Expand description

Generic socket type

Implementations§

Source§

impl Socket

Source

pub fn pair0() -> Result<Self, ErrorCode>

Creates new version 0 pair socket

Source

pub fn pair1() -> Result<Self, ErrorCode>

Creates new version 1 pair socket

Source

pub fn pub0() -> Result<Self, ErrorCode>

Creates new version 0 publisher socket

Source

pub fn sub0() -> Result<Self, ErrorCode>

Creates new version 0 subscriber socket

Source

pub fn req0() -> Result<Self, ErrorCode>

Creates new version 0 request socket

Source

pub fn rep0() -> Result<Self, ErrorCode>

Creates new version 0 reply socket

Source

pub fn close(&self) -> bool

Closes socket.

Returns true if operation had effect Otherwise, if socket is already closed, returns false

Source

pub fn listen(&self, url: String<'_>) -> Result<(), ErrorCode>

Binds socket to the specified url, starting to listen for incoming messages.

Source

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

Source

pub fn connect(&self, url: String<'_>) -> Result<(), ErrorCode>

Connects to the remote peer via url.

Source

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

Source

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

Source

pub fn get_prop<T: Property<Self>>(&self) -> Result<T, ErrorCode>

Get property of the socket

Source

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.

Source

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

Source

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

Source

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.

Source

pub fn recv_msg_async(&self) -> Result<FutureResp, ErrorCode>

Creates new future that attempts to receive message from the socket.

Source

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

Source

pub fn send_msg(&self, msg: Message) -> Result<(), (Message, ErrorCode)>

Sends message over the socket.

If successful takes ownership of message. Otherwise returns message with error code.

Source

pub fn send_msg_async(&self, msg: Message) -> Result<FutureReq, ErrorCode>

Sends message over the socket asynchronously.

If successful takes ownership of message. Otherwise returns message with error code.

Trait Implementations§

Source§

impl Debug for Socket

Source§

fn fmt(&self, fmt: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Deref for Socket

Source§

type Target = nng_socket_s

The resulting type after dereferencing.
Source§

fn deref(&self) -> &Self::Target

Dereferences the value.
Source§

impl DerefMut for Socket

Source§

fn deref_mut(&mut self) -> &mut Self::Target

Mutably dereferences the value.
Source§

impl Drop for Socket

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

impl Options<Socket> for MaxTtl

Source§

fn apply(&self, target: &Socket) -> Result<(), ErrorCode>

Applies options to the target, returning error if any happens
Source§

impl Options<Socket> for Reconnect

Source§

fn apply(&self, target: &Socket) -> Result<(), ErrorCode>

Applies options to the target, returning error if any happens
Source§

impl Options<Socket> for RecvBuf

Source§

fn apply(&self, target: &Socket) -> Result<(), ErrorCode>

Applies options to the target, returning error if any happens
Source§

impl Options<Socket> for RecvMaxSize

Source§

fn apply(&self, target: &Socket) -> Result<(), ErrorCode>

Applies options to the target, returning error if any happens
Source§

impl Options<Socket> for RecvTimeout

Source§

fn apply(&self, target: &Socket) -> Result<(), ErrorCode>

Applies options to the target, returning error if any happens
Source§

impl Options<Socket> for Req

Source§

fn apply(&self, target: &Socket) -> Result<(), ErrorCode>

Applies options to the target, returning error if any happens
Source§

impl Options<Socket> for SendBuf

Source§

fn apply(&self, target: &Socket) -> Result<(), ErrorCode>

Applies options to the target, returning error if any happens
Source§

impl Options<Socket> for SendTimeout

Source§

fn apply(&self, target: &Socket) -> Result<(), ErrorCode>

Applies options to the target, returning error if any happens
Source§

impl Options<Socket> for SocketName

Source§

fn apply(&self, target: &Socket) -> Result<(), ErrorCode>

Applies options to the target, returning error if any happens
Source§

impl Options<Socket> for Subscribe<'_>

Source§

fn apply(&self, target: &Socket) -> Result<(), ErrorCode>

Applies options to the target, returning error if any happens
Source§

impl Options<Socket> for Unsubscribe<'_>

Source§

fn apply(&self, target: &Socket) -> Result<(), ErrorCode>

Applies options to the target, returning error if any happens
Source§

impl Property<Socket> for PeerName

Source§

fn get(target: &Socket) -> Result<Self, ErrorCode>

Gets instance of self from the `target
Source§

impl Property<Socket> for SocketName

Source§

fn get(target: &Socket) -> Result<Self, ErrorCode>

Gets instance of self from the `target

Auto Trait Implementations§

§

impl Freeze for Socket

§

impl RefUnwindSafe for Socket

§

impl Send for Socket

§

impl Sync for Socket

§

impl Unpin for Socket

§

impl UnwindSafe for Socket

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<P, T> Receiver for P
where P: Deref<Target = T> + ?Sized, T: ?Sized,

Source§

type Target = T

🔬This is a nightly-only experimental API. (arbitrary_self_types)
The target type on which the method may be called.
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

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

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more