# Path: pyczmq/_cffi.py
# C = ffi.dlopen('czmq')
# Z = ffi.dlopen('zmq')
# def ptop(typ, val):
# def cdef(decl, returns_string=False, nullable=False):
#     def wrap(f):
#         def inner_f(*args):


from pyczmq._cffi import C, ffi, cdef
doesn't wrap the 0MQ socket type, to avoid breaking all libzmq
socket-related calls.
"""

# This port range is defined by IANA for dynamic or private ports
# We use this when choosing a port for dynamic binding.
DYNFROM = 49152
DYNTO = 65535


@cdef('void zsocket_destroy (zctx_t *self, void *socket);')
def destroy(ctx, socket):
    """Destroy a socket within our CZMQ context.

    'pyczmq.zsocket.new' automatically registers this destructor with
    the garbage collector, so this is normally not necessary to use,
    unless you need to destroy sockets created by some other means
    (like a call directly to 'pyczmq.C.zsocket_new')
    """
    C.zsocket_destroy(ctx, socket)


@cdef('void * zsocket_new (zctx_t *self, int type);')
def new(ctx, typ):
    """
    Create a new socket within our CZMQ context, replaces zmq_socket.
    Use this to get automatic management of the socket at shutdown.
    Note: SUB sockets do not automatically subscribe to everything;
    you must set filters explicitly.
    """

# Path: pyczmq/_cffi.py
# C = ffi.dlopen('czmq')
# Z = ffi.dlopen('zmq')
# def ptop(typ, val):
# def cdef(decl, returns_string=False, nullable=False):
#     def wrap(f):
#         def inner_f(*args):


# Path: pyczmq/zsocket.py
from pyczmq._cffi import C, ffi, cdef

doesn't wrap the 0MQ socket type, to avoid breaking all libzmq
socket-related calls.
"""

# This port range is defined by IANA for dynamic or private ports
# We use this when choosing a port for dynamic binding.
DYNFROM = 49152
DYNTO = 65535


@cdef('void zsocket_destroy (zctx_t *self, void *socket);')
def destroy(ctx, socket):
    """Destroy a socket within our CZMQ context.

    'pyczmq.zsocket.new' automatically registers this destructor with
    the garbage collector, so this is normally not necessary to use,
    unless you need to destroy sockets created by some other means
    (like a call directly to 'pyczmq.C.zsocket_new')
    """
    C.zsocket_destroy(ctx, socket)


@cdef('void * zsocket_new (zctx_t *self, int type);')
def new(ctx, typ):
    """
    Create a new socket within our CZMQ context, replaces zmq_socket.
    Use this to get automatic management of the socket at shutdown.
    Note: SUB sockets do not automatically subscribe to everything;
    you must set filters explicitly.
    """

    return ffi.gc(C.zsocket_new(ctx, typ), lambda s: destroy(ctx, s))