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