[−][src]Struct libzmq::Ctx
A owning pointer to a ØMQ context.
A context leeps 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 Behavior
The context will call terminate when dropped which will cause all
blocking calls to fail with InvalidCtx
, then the dropping thread
will block until the following conditions are met:
- All sockets open within the context have been dropped.
- All messages within the context are closed.
To prevent the context drop from blocking infinitely, users should properly
manage Result
returned by function calls.
Thread safety
A ØMQ context is internally thread safe.
Implementations
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; // Creates a new unique context. let ctx = Ctx::new(); // Returns a handle to the context that can be used // to create sockets. let handle = ctx.handle();
pub fn handle(&self) -> CtxHandle
[src]
Returns a handle to the Ctx
.
Sockets can be created using CtxHandle
so that they used the
context aliased by the handle.
use libzmq::{Ctx, Server}; let ctx = Ctx::new(); let handle = ctx.handle(); let server = Server::with_ctx(handle)?;
pub fn global() -> CtxHandle
[src]
Returns a handle 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 context via // its `CtxHandle`. 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 socket_limit(&self) -> i32
[src]
Returns the largest number of sockets that the context will accept.
pub fn shutdown(&self)
[src]
Invalidates all the handles to the ØMQ context.
Context shutdown will cause any blocking operations currently in
progress on sockets using handles associated with the context to fail
with InvalidCtx
.
This is used as a mechanism to stop another blocked thread.
Note that, while this invalidates the context, it does not terminate it.
The context will only get terminated once Ctx
is dropped.
Trait Implementations
impl Debug for Ctx
[src]
impl Default for Ctx
[src]
impl Drop for Ctx
[src]
impl Eq for Ctx
[src]
impl PartialEq<Ctx> for Ctx
[src]
impl StructuralEq for Ctx
[src]
impl StructuralPartialEq for Ctx
[src]
Auto Trait Implementations
impl RefUnwindSafe for Ctx
impl Send for Ctx
impl Sync for Ctx
impl Unpin for Ctx
impl UnwindSafe for Ctx
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
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> From<T> for 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<V, T> VZip<V> for T where
V: MultiLane<T>,
V: MultiLane<T>,