Struct Context

Source
pub struct Context { /* private fields */ }

Implementations§

Source§

impl Context

Source

pub fn new() -> Result<Context, Error>

Create new 0MQ context

Binding of void *zmq_ctx_new ();

The function creates a new ØMQ context.

§Thread safety

A ØMQ context is thread safe and may be shared among as many application threads as necessary, without any additional locking required on the part of the caller.

Examples found in repository?
examples/zguide/hwserver.rs (line 8)
7fn main() {
8    let mut context = zmq::Context::new().unwrap();
9    let mut responder = context.socket(zmq::REP).unwrap();
10    responder.bind("tcp://*:5555").unwrap();
11
12    loop {
13        let mut buffer: Vec<u8> = Vec::with_capacity(10);
14        responder.recv_bytes_into_slice(&mut buffer, 0).unwrap();
15        println!("Received Hello");
16        sleep(Duration::from_secs(1));
17        responder.send_bytes("World".as_bytes(), 0).unwrap();
18    }
19}
More examples
Hide additional examples
examples/zguide/hwclient.rs (line 6)
4fn main() {
5    println!("Connecting to hello world server...");
6    let mut context = zmq::Context::new().unwrap();
7    let mut requester = context.socket(zmq::REQ).unwrap();
8    requester.connect("tcp://localhost:5555").unwrap();
9
10    for request_nbr in 0..10 {
11        let mut buffer: Vec<u8> = Vec::with_capacity(10);
12        println!("Sending Hello {}...", request_nbr);
13        requester.send_bytes("Hello".as_bytes(), 0).unwrap();
14        requester.recv_bytes_into_slice(&mut buffer, 0).unwrap();
15        println!("Received World {}", request_nbr);
16    }
17    requester.close().unwrap();
18    context.shutdown().unwrap();
19}
Source

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

Shutdown a 0MQ context

Binding of int zmq_ctx_shutdown (void *context);

The function will shutdown the ØMQ context context. Context shutdown will cause any blocking operations currently in progress on sockets open within context to return immediately with an error code of ETERM. With the exception of Socket::Close(), any further operations on sockets open within context will fail with an error code of ETERM.

Examples found in repository?
examples/zguide/hwclient.rs (line 18)
4fn main() {
5    println!("Connecting to hello world server...");
6    let mut context = zmq::Context::new().unwrap();
7    let mut requester = context.socket(zmq::REQ).unwrap();
8    requester.connect("tcp://localhost:5555").unwrap();
9
10    for request_nbr in 0..10 {
11        let mut buffer: Vec<u8> = Vec::with_capacity(10);
12        println!("Sending Hello {}...", request_nbr);
13        requester.send_bytes("Hello".as_bytes(), 0).unwrap();
14        requester.recv_bytes_into_slice(&mut buffer, 0).unwrap();
15        println!("Received World {}", request_nbr);
16    }
17    requester.close().unwrap();
18    context.shutdown().unwrap();
19}
Source

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

Source

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

Source

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

Source

pub fn is_ipv6_enabled(&self) -> Result<bool, Error>

Source

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

Source

pub fn set_max_sockets(&mut self, optval: i32) -> Result<(), Error>

Source

pub fn set_thread_priority(&mut self, optval: i32) -> Result<(), Error>

Source

pub fn set_thread_sched_policy(&mut self, optval: i32) -> Result<(), Error>

Source

pub fn set_ipv6(&mut self, optval: i32) -> Result<(), Error>

Source

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

Create 0MQ socket

Binding of void *zmq_socket (void *context, int type);

The type argument specifies the socket type, which determines the semantics of communication over the socket. The newly created socket is initially unbound, and not associated with any endpoints. In order to establish a message flow a socket must first be connected to at least one endpoint with Scoket::Connect, or at least one endpoint must be created for accepting incoming connections with Socket::Bind().

Examples found in repository?
examples/zguide/hwserver.rs (line 9)
7fn main() {
8    let mut context = zmq::Context::new().unwrap();
9    let mut responder = context.socket(zmq::REP).unwrap();
10    responder.bind("tcp://*:5555").unwrap();
11
12    loop {
13        let mut buffer: Vec<u8> = Vec::with_capacity(10);
14        responder.recv_bytes_into_slice(&mut buffer, 0).unwrap();
15        println!("Received Hello");
16        sleep(Duration::from_secs(1));
17        responder.send_bytes("World".as_bytes(), 0).unwrap();
18    }
19}
More examples
Hide additional examples
examples/zguide/hwclient.rs (line 7)
4fn main() {
5    println!("Connecting to hello world server...");
6    let mut context = zmq::Context::new().unwrap();
7    let mut requester = context.socket(zmq::REQ).unwrap();
8    requester.connect("tcp://localhost:5555").unwrap();
9
10    for request_nbr in 0..10 {
11        let mut buffer: Vec<u8> = Vec::with_capacity(10);
12        println!("Sending Hello {}...", request_nbr);
13        requester.send_bytes("Hello".as_bytes(), 0).unwrap();
14        requester.recv_bytes_into_slice(&mut buffer, 0).unwrap();
15        println!("Received World {}", request_nbr);
16    }
17    requester.close().unwrap();
18    context.shutdown().unwrap();
19}

Trait Implementations§

Source§

impl Drop for Context

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

impl Send for Context

Source§

impl Sync for Context

Auto Trait Implementations§

Blanket Implementations§

Source§

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

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

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

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where 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 T
where 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, U> TryFrom<U> for T
where U: Into<T>,

Source§

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

Source§

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.