Struct nng::Socket[][src]

pub struct Socket { /* fields omitted */ }

An NNG socket.

All communication between application and remote Scalability Protocol peers is done through sockets. A given socket can have multiple dialers, listeners, and pipes, and may be connected to multiple transports at the same time. However, a given socket will have exactly one protocol associated with it and is responsible for any state machines or other application-specific logic.

See the NNG documentation for more information.

Implementations

impl Socket[src]

pub fn new(t: Protocol) -> Result<Socket>[src]

Creates a new socket which uses the specified protocol.

Errors

pub fn dial(&self, url: &str) -> Result<()>[src]

Initiates a remote connection to a listener.

When the connection is closed, the underlying Dialer will attempt to re-establish the connection.

The first attempt to connect to the address indicated by the provided url is done synchronously, including any necessary name resolution. As a result, a failure, such as if the connection is refused, will be returned immediately and no further action will be taken.

If the connection was closed for a synchronously dialed connection, the dialer will still attempt to redial asynchronously.

Because the dialer is started immediately, it is generally not possible to apply extra configuration. If that is needed, or if one wishes to close the dialer before the socket, applications should consider using the Dialer type directly.

See the NNG documentation for more information.

Errors

pub fn listen(&self, url: &str) -> Result<()>[src]

Initiates and starts a listener on the specified address.

Listeners are used to accept connections initiated by remote dialers. Unlike a dialer, listeners generally can have many connections open concurrently.

The act of “binding” to the address indicated by url is done synchronously, including any necessary name resolution. As a result, a failure, such as if the address is already in use, will be returned immediately.

Because the listener is started immediately, it is generally not possible to apply extra configuration. If that is needed, or if one wishes to close the dialer before the socket, applications should consider using the Listener type directly.

See the NNG documentation for more information.

Errors

pub fn dial_async(&self, url: &str) -> Result<()>[src]

Asynchronously initiates a remote connection to a listener.

When the connection is closed, the underlying Dialer will attempt to re-establish the connection. It will also periodically retry a connection automatically if an attempt to connect asynchronously fails.

Because the dialer is started immediately, it is generally not possible to apply extra configuration. If that is needed, or if one wishes to close the dialer before the socket, applications should consider using the Dialer type directly.

See the NNG documentation for more information.

Errors

pub fn recv(&self) -> Result<Message>[src]

Receives a message from the socket.

The semantics of what receiving a message means vary from protocol to protocol, so examination of the protocol documentation is encouraged. For example, with a req socket a message may only be received after a request has been sent. Furthermore, some protocols may not support receiving data at all, such as pub.

Errors

pub fn send<M: Into<Message>>(&self, msg: M) -> Result<(), (Message, Error)>[src]

Sends a message on the socket.

The semantics of what sending a message means vary from protocol to protocol, so examination of the protocol documentation is encouraged. For example, with a pub socket the data is broadcast so that any peers who have a suitable subscription will be able to receive it. Furthermore, some protocols may not support sending data (such as sub) or may require other conditions. For example, rep sockets cannot normally send data, which are responses to requests, until they have first received a request.

If the message cannot be sent, then it is returned to the caller as a part of the Error.

Errors

pub fn try_recv(&self) -> Result<Message>[src]

Attempts to receives a message from the socket.

The semantics of what receiving a message means vary from protocol to protocol, so examination of the protocol documentation is encouraged. For example, with a req socket a message may only be received after a request has been sent. Furthermore, some protocols may not support receiving data at all, such as pub.

If no message is available, this function will immediately return.

Errors

pub fn try_send<M: Into<Message>>(&self, msg: M) -> Result<(), (Message, Error)>[src]

Attempts to sends a message on the socket.

The semantics of what sending a message means vary from protocol to protocol, so examination of the protocol documentation is encouraged. For example, with a pub socket the data is broadcast so that any peers who have a suitable subscription will be able to receive it. Furthermore, some protocols may not support sending data (such as sub) or may require other conditions. For example, rep sockets cannot normally send data, which are responses to requests, until they have first received a request.

If the message cannot be sent (e.g., there are no peers or there is backpressure from the peers) then this function will return immediately. If the message cannot be sent, then it is returned to the caller as a part of the Error.

Errors

pub fn recv_async(&self, aio: &Aio) -> Result<()>[src]

Start a receive operation using the given Aio and return immediately.

Errors

pub fn send_async<M: Into<Message>>(
    &self,
    aio: &Aio,
    msg: M
) -> Result<(), (Message, Error)>
[src]

Start a send operation on the given Aio and return immediately.

Errors

pub fn pipe_notify<F>(&self, callback: F) -> Result<()> where
    F: Fn(Pipe, PipeEvent) + Send + Sync + 'static, 
[src]

Register a callback function to be called whenever a pipe event occurs on the socket.

Only a single callback function can be supplied at a time. Registering a new callback implicitly unregisters any previously registered.

Errors

None specified.

Panics

If the callback function panics, the program will log the panic if possible and then abort. Future Rustc versions will likely do the same for uncaught panics at FFI boundaries, so this library will produce the abort in order to keep things consistent. As such, the user is responsible for either having a callback that never panics or catching and handling the panic within the callback.

pub fn close(&self)[src]

Close the underlying socket.

Messages that have been submitted for sending may be flushed or delivered depending on the transport and the linger option. Further attempts to use the socket (via this handle or any other) after this call returns will result in an error. Threads waiting for operations on the socket when this call is executed may also return with an error.

Closing the socket while data is in transmission will likely lead to loss of that data. There is no automatic linger or flush to ensure that the socket send buffers have completely transmitted. It is recommended to wait a brief period after sending data before calling this function.

This function will be called automatically when all handles have been dropped.

Trait Implementations

impl Clone for Socket[src]

impl Debug for Socket[src]

impl Eq for Socket[src]

impl GetOpt<MaxTtl> for Socket[src]

impl GetOpt<Raw> for Socket[src]

impl GetOpt<RecvBufferSize> for Socket[src]

impl GetOpt<RecvFd> for Socket[src]

impl GetOpt<RecvTimeout> for Socket[src]

impl GetOpt<ResendTime> for Socket[src]

impl GetOpt<SendBufferSize> for Socket[src]

impl GetOpt<SendFd> for Socket[src]

impl GetOpt<SendTimeout> for Socket[src]

impl GetOpt<SocketName> for Socket[src]

impl GetOpt<SurveyTime> for Socket[src]

impl Hash for Socket[src]

impl Ord for Socket[src]

impl PartialEq<Socket> for Socket[src]

impl PartialOrd<Socket> for Socket[src]

impl SetOpt<CaFile> for Socket[src]

impl SetOpt<CertKeyFile> for Socket[src]

impl SetOpt<KeepAlive> for Socket[src]

impl SetOpt<MaxTtl> for Socket[src]

impl SetOpt<NoDelay> for Socket[src]

impl SetOpt<ReconnectMaxTime> for Socket[src]

impl SetOpt<ReconnectMinTime> for Socket[src]

impl SetOpt<RecvBufferSize> for Socket[src]

impl SetOpt<RecvMaxSize> for Socket[src]

impl SetOpt<RecvTimeout> for Socket[src]

impl SetOpt<RequestHeaders> for Socket[src]

impl SetOpt<ResendTime> for Socket[src]

impl SetOpt<ResponseHeaders> for Socket[src]

impl SetOpt<SendBufferSize> for Socket[src]

impl SetOpt<SendTimeout> for Socket[src]

impl SetOpt<SocketName> for Socket[src]

impl SetOpt<Subscribe> for Socket[src]

impl SetOpt<SurveyTime> for Socket[src]

impl SetOpt<Unsubscribe> for Socket[src]

impl TryFrom<Socket> for RawSocket[src]

type Error = CookedSocketError

The type returned in the event of a conversion error.

Auto Trait Implementations

impl RefUnwindSafe for Socket

impl Send for Socket

impl Sync for Socket

impl Unpin for Socket

impl UnwindSafe for Socket

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> Options for T where
    T: HasOpts, 
[src]

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.