Skip to content

Commit eede431

Browse files
authored
Merge pull request #311 from kalcutter/context-io-threads
Add `Context` getters and setters for `ZMQ_IO_THREADS`
2 parents d5ada96 + b49cdea commit eede431

File tree

2 files changed

+29
-0
lines changed

2 files changed

+29
-0
lines changed

src/lib.rs

+15
Original file line numberDiff line numberDiff line change
@@ -432,6 +432,21 @@ impl Context {
432432
}
433433
}
434434

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

tests/context.rs

+14
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)