[−][src]Struct libzmq::Ctx
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 terminate all
blocking calls, which will return 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, value: i32)
[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, value: i32)
[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, value: i32)
[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 no_linger(&self) -> bool
[src]
A value of true
indicates that all new sockets are given a
linger timeout of zero.
pub fn set_no_linger(&self, enabled: bool)
[src]
When set to true
, all new sockets are given a linger timeout
of zero.
Default
The default value is false
.
Usage Example
use libzmq::Ctx; let ctx = Ctx::new(); assert_eq!(ctx.no_linger(), false); ctx.set_no_linger(true); assert_eq!(ctx.no_linger(), true);
pub fn terminate(&self) -> Result<(), String>
[src]
Terminate the context.
This will deadlock your program if you are not carefull. You should
probably we using shutdown
instead.
Any blocking operations currently in progress on
sockets open within this context shall return immediately with a
CtxTerminated
error. Any additional operations of
these sockets will also return a CtxTerminated
error.
This allows blocked threads to properly exit. Otherwise, a thread blocked
on a send
call would lose its unsent message(s).
The terminate
call will then block until all the sockets within
the context are closed and either all the outgoing messages are sent or
their linger period has expired.
Read more here
.
Error
Returns the error msg.
pub fn shutdown(&self) -> Result<(), String>
[src]
Shutdown the ØMQ context context.
Context shutdown will cause any blocking operations currently in
progress on sockets open within context to return immediately with CtxTerminated
.
Any further operations on sockets open within context shall fail with
with CtxTerminated
.
Error
Returns the error msg.
Trait Implementations
impl PartialEq<Ctx> for Ctx
[src]
impl<'a> From<&'a Ctx> for Ctx
[src]
impl Clone for Ctx
[src]
fn clone(&self) -> Ctx
[src]
fn clone_from(&mut self, source: &Self)
1.0.0[src]
Performs copy-assignment from source
. Read more
impl Default for Ctx
[src]
impl Eq for Ctx
[src]
impl Debug for Ctx
[src]
Auto Trait Implementations
Blanket Implementations
impl<T> From<T> for T
[src]
impl<T> ToOwned for T where
T: Clone,
[src]
T: Clone,
type Owned = T
The resulting type after obtaining ownership.
fn to_owned(&self) -> T
[src]
fn clone_into(&self, target: &mut T)
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>
[src]
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,