[][src]Struct libzmq::Ctx

pub struct Ctx { /* fields omitted */ }

Keeps the list of sockets and manages the async I/O thread and internal queries.

Each context also has an associated AuthServer which handles socket authentification.

Drop

The context will call terminate when dropped which will cause all blocking calls to fail with CtxTerminated, then block until the following conditions are met:

  • All sockets open within context have been dropped.
  • All messages sent by the application with have either been physically transferred to a network peer, or the socket's linger period has expired.

Thread safety

A ØMQ context is internally thread safe.

Multiple Contexts

Multiple contexts are allowed but are considered exotic.

Methods

impl Ctx[src]

pub fn new() -> Self[src]

Create a new ØMQ context.

For almost all use cases, using and configuring the global context will be enought.

See zmq_ctx_new.

Usage Example

use libzmq::Ctx;

let ctx = Ctx::new();
let cloned = ctx.clone();

assert_eq!(ctx, cloned);
assert_ne!(ctx, Ctx::new());

pub fn global() -> &'static Ctx[src]

Returns a reference to the global context.

This is a singleton used by sockets created via their respective ::new() method. It merely exists for convenience and is no different from a context obtained via Ctx::new().

Usage Example

use libzmq::{Ctx, Client};

// A socket created via `new` will use the global `Ctx`.
let client = Client::new()?;
assert_eq!(client.ctx(), Ctx::global());

pub fn io_threads(&self) -> i32[src]

Returns the size of the ØMQ thread pool for this context.

pub fn set_io_threads(&self, nb_threads: i32) -> Result<(), Error>[src]

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

"The general rule of thumb is to allow one I/O thread per gigabyte of data in or out per second." - Pieter Hintjens

Default

The default value is 1.

Usage Example

use libzmq::Ctx;

let ctx = Ctx::new();
assert_eq!(ctx.io_threads(), 1);

// Lets say our app exclusively uses the inproc transport
// for messaging. Then we dont need any I/O threads.
ctx.set_io_threads(0)?;
assert_eq!(ctx.io_threads(), 0);

pub fn max_sockets(&self) -> i32[src]

Returns the maximum number of sockets allowed for this context.

pub fn set_max_sockets(&self, max: i32) -> Result<(), Error>[src]

Sets the maximum number of sockets allowed on the context.

Default

The default value is 1023.

Usage Example

use libzmq::Ctx;

let ctx = Ctx::new();
assert_eq!(ctx.max_sockets(), 1023);

ctx.set_max_sockets(420)?;
assert_eq!(ctx.max_sockets(), 420);

pub fn max_msg_size(&self) -> i32[src]

Returns the maximum size of a message allowed for this context.

pub fn set_max_msg_size(&self, size: i32) -> Result<(), Error>[src]

Sets the maximum allowed size of a message sent in the context.

Default

The default value is i32::max_value().

Usage Example

use libzmq::Ctx;

let ctx = Ctx::new();
assert_eq!(ctx.max_msg_size(), i32::max_value());

ctx.set_max_msg_size(i32::max_value() - 1)?;
assert_eq!(ctx.max_msg_size(), i32::max_value() - 1);

pub fn socket_limit(&self) -> i32[src]

Returns the largest number of sockets that the context will accept.

pub fn shutdown(&self)[src]

Shutdown the ØMQ context context.

Context shutdown will cause any blocking operations currently in progress on sockets open within context to fail immediately with CtxTerminated.

Any further operations on sockets open within context shall fail with with CtxTerminated.

Trait Implementations

impl Eq for Ctx[src]

impl PartialEq<Ctx> for Ctx[src]

impl Clone for Ctx[src]

fn clone_from(&mut self, source: &Self)1.0.0[src]

Performs copy-assignment from source. Read more

impl<'a> From<&'a Ctx> for Ctx[src]

impl Default for Ctx[src]

impl Debug for Ctx[src]

Auto Trait Implementations

impl Send for Ctx

impl Sync for Ctx

Blanket Implementations

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

type Owned = T

The resulting type after obtaining ownership.

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

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

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<T> BorrowMut<T> for T where
    T: ?Sized
[src]

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

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