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