Skip to content

Commit

Permalink
Move eagain logging to run-time switch instead of compile-time switch
Browse files Browse the repository at this point in the history
  • Loading branch information
Clonkk committed May 12, 2024
1 parent 75e85c3 commit 7c60860
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
12 changes: 11 additions & 1 deletion zmq/connections.nim
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down

0 comments on commit 7c60860

Please sign in to comment.