diff --git a/README.md b/README.md index c2501e8..744661e 100644 --- a/README.md +++ b/README.md @@ -53,7 +53,7 @@ The examples are commented to better understand how zmq works. ### Log EAGAIN errno -Sometimes EAGAIN error happens in ZMQ context; typically this is a non-ctritical error that can be ignored. Nonetheless, if you desire to logg or display such error you can compile with the flag ``-d:zmqEAGAIN`` and EAGAIN error will be logged using ``std/logging`` or ``echo`` to stdout if no logger handler is defined. +Sometimes EAGAIN error happens in ZMQ context; typically this is a non-ctritical error that can be ignored. Nonetheless, if you desire to log or display such error, it is possible to enable it using the ``enableLogEagain`` and disable it with ``disableLogEagain``. ### Setting default flag as DONTWAIT diff --git a/zmq/connections.nim b/zmq/connections.nim index 9c093ec..79c9349 100644 --- a/zmq/connections.nim +++ b/zmq/connections.nim @@ -32,13 +32,23 @@ proc zmqError*() {.noinline, noreturn.} = e.msg = &"Error: {e.error}. " & $strerror(e.error) raise e +var shouldLogEagainError = false + +proc enableLogEagain*() = + ## Enable logging EAGAIN error in ZMQ calls + shouldLogEagainError = true + +proc disableLogEagain*() = + ## Disable logging EAGAIN error in ZMQ calls + shouldLogEagainError = false + proc zmqErrorExceptEAGAIN() = var e: ref ZmqError new(e) e.error = errno() let errmsg = $strerror(e.error) if e.error == ZMQ_EAGAIN: - when defined(zmqEAGAIN): + if shouldLogEagainError: if logging.getHandlers().len() > 0: warn(errmsg) else: