Struct tmq::Context

source ·
pub struct Context { /* private fields */ }
Expand description

Handle for a 0MQ context, used to create sockets.

It is thread safe, and can be safely cloned and shared. Each clone references the same underlying C context. Internally, an Arc is used to implement this in a threadsafe way.

Also note that this binding deviates from the C API in that each socket created from a context initially owns a clone of that context. This reference is kept to avoid a potential deadlock situation that would otherwise occur:

Destroying the underlying C context is an operation which blocks waiting for all sockets created from it to be closed first. If one of the sockets belongs to thread issuing the destroy operation, you have established a deadlock.

You can still deadlock yourself (or intentionally close sockets in other threads, see zmq_ctx_destroy(3)) by explicitly calling Context::destroy.

Implementations§

source§

impl Context

source

pub fn new() -> Context

Create a new reference-counted context handle.

source

pub fn get_io_threads(&self) -> Result<i32, Error>

Get the size of the ØMQ thread pool to handle I/O operations.

source

pub fn set_io_threads(&self, value: i32) -> Result<(), Error>

Set the size of the ØMQ thread pool to handle I/O operations.

source

pub fn socket(&self, socket_type: SocketType) -> Result<Socket, Error>

Create a new socket.

Note that the returned socket keeps a an Arc reference to the context it was created from, and will keep that context from being dropped while being live.

source

pub fn destroy(&mut self) -> Result<(), Error>

Try to destroy the context. This is different than the destructor; the destructor will loop when zmq_ctx_term returns EINTR.

Trait Implementations§

source§

impl Clone for Context

source§

fn clone(&self) -> Context

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl Default for Context

source§

fn default() -> Context

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

source§

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

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

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

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere 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, U> Into<U> for Twhere 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<T> ToOwned for Twhere T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

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

§

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 Twhere U: TryFrom<T>,

§

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.