Skip to content

Commit

Permalink
Merge pull request #311 from kalcutter/context-io-threads
Browse files Browse the repository at this point in the history
Add `Context` getters and setters for `ZMQ_IO_THREADS`
  • Loading branch information
erickt committed Jul 30, 2020
2 parents d5ada96 + b49cdea commit eede431
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
15 changes: 15 additions & 0 deletions src/lib.rs
Expand Up @@ -432,6 +432,21 @@ impl Context {
}
}

/// Get the size of the ØMQ thread pool to handle I/O operations.
pub fn get_io_threads(&self) -> Result<i32> {
let rc =
zmq_try!(unsafe { zmq_sys::zmq_ctx_get(self.raw.ctx, zmq_sys::ZMQ_IO_THREADS as _) });
Ok(rc as i32)
}

/// Set the size of the ØMQ thread pool to handle I/O operations.
pub fn set_io_threads(&self, value: i32) -> Result<()> {
zmq_try!(unsafe {
zmq_sys::zmq_ctx_set(self.raw.ctx, zmq_sys::ZMQ_IO_THREADS as _, value as i32)
});
Ok(())
}

/// Create a new socket.
///
/// Note that the returned socket keeps a an `Arc` reference to
Expand Down
14 changes: 14 additions & 0 deletions tests/context.rs
@@ -0,0 +1,14 @@
#[test]
fn context_io_threads() {
let ctx = zmq::Context::new();

assert_eq!(ctx.get_io_threads().unwrap(), zmq_sys::ZMQ_IO_THREADS_DFLT as i32);

ctx.set_io_threads(0).unwrap();
assert_eq!(ctx.get_io_threads().unwrap(), 0);

ctx.set_io_threads(7).unwrap();
assert_eq!(ctx.get_io_threads().unwrap(), 7);

assert!(ctx.set_io_threads(-1).is_err());
}

0 comments on commit eede431

Please sign in to comment.