checkrc.pxd 873 B

123456789101112131415161718192021222324252627
  1. from libc.errno cimport EINTR, EAGAIN
  2. from cpython cimport PyErr_CheckSignals
  3. from .libzmq cimport zmq_errno, ZMQ_ETERM
  4. cdef inline int _check_rc(int rc) except -1:
  5. """internal utility for checking zmq return condition
  6. and raising the appropriate Exception class
  7. """
  8. cdef int errno = zmq_errno()
  9. PyErr_CheckSignals()
  10. if rc == -1: # if rc < -1, it's a bug in libzmq. Should we warn?
  11. if errno == EINTR:
  12. from zmq.error import InterruptedSystemCall
  13. raise InterruptedSystemCall(errno)
  14. elif errno == EAGAIN:
  15. from zmq.error import Again
  16. raise Again(errno)
  17. elif errno == ZMQ_ETERM:
  18. from zmq.error import ContextTerminated
  19. raise ContextTerminated(errno)
  20. else:
  21. from zmq.error import ZMQError
  22. raise ZMQError(errno)
  23. return 0