Skip to content

Commit b49cdea

Browse files
committed
Add Context getters and setters for ZMQ_IO_THREADS
Fixes #206
1 parent 2b9bb43 commit b49cdea

File tree

2 files changed

+29
-0
lines changed

2 files changed

+29
-0
lines changed

src/lib.rs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -428,6 +428,21 @@ impl Context {
428428
}
429429
}
430430

431+
/// Get the size of the ØMQ thread pool to handle I/O operations.
432+
pub fn get_io_threads(&self) -> Result<i32> {
433+
let rc =
434+
zmq_try!(unsafe { zmq_sys::zmq_ctx_get(self.raw.ctx, zmq_sys::ZMQ_IO_THREADS as _) });
435+
Ok(rc as i32)
436+
}
437+
438+
/// Set the size of the ØMQ thread pool to handle I/O operations.
439+
pub fn set_io_threads(&self, value: i32) -> Result<()> {
440+
zmq_try!(unsafe {
441+
zmq_sys::zmq_ctx_set(self.raw.ctx, zmq_sys::ZMQ_IO_THREADS as _, value as i32)
442+
});
443+
Ok(())
444+
}
445+
431446
/// Create a new socket.
432447
///
433448
/// Note that the returned socket keeps a an `Arc` reference to

tests/context.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#[test]
2+
fn context_io_threads() {
3+
let ctx = zmq::Context::new();
4+
5+
assert_eq!(ctx.get_io_threads().unwrap(), zmq_sys::ZMQ_IO_THREADS_DFLT as i32);
6+
7+
ctx.set_io_threads(0).unwrap();
8+
assert_eq!(ctx.get_io_threads().unwrap(), 0);
9+
10+
ctx.set_io_threads(7).unwrap();
11+
assert_eq!(ctx.get_io_threads().unwrap(), 7);
12+
13+
assert!(ctx.set_io_threads(-1).is_err());
14+
}

0 commit comments

Comments
 (0)