# 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
@cdef('char * zstr_recv_nowait (void *socket);', nullable=True, returns_string=True)
def recv_nowait(sock):
    """
    Receive a string off a socket if socket had input waiting
    """
    return C.zstr_recv_nowait(sock)


@cdef('int zstr_send (void *socket, const char *format, ...);')
def send(sock, string):
    """
    Send a formatted string to a socket
    """
    return C.zstr_send(sock, string)


@cdef('int zstr_sendm (void *socket, const char *format, ...);')
def sendm(sock, string):
    """
    Send a formatted string to a socket, with MORE flag
    """
    return C.zstr_sendm(sock, string)


@cdef('int zstr_sendx (void *socket, const char *string, ...);')
def sendx(sock, *strings):
    """
    Send a series of strings (until NULL) as multipart data
    Returns 0 if the strings could be sent OK, or -1 on error.
    """

# 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/zstr.py
from pyczmq._cffi import C, ffi, cdef

@cdef('char * zstr_recv_nowait (void *socket);', nullable=True, returns_string=True)
def recv_nowait(sock):
    """
    Receive a string off a socket if socket had input waiting
    """
    return C.zstr_recv_nowait(sock)


@cdef('int zstr_send (void *socket, const char *format, ...);')
def send(sock, string):
    """
    Send a formatted string to a socket
    """
    return C.zstr_send(sock, string)


@cdef('int zstr_sendm (void *socket, const char *format, ...);')
def sendm(sock, string):
    """
    Send a formatted string to a socket, with MORE flag
    """
    return C.zstr_sendm(sock, string)


@cdef('int zstr_sendx (void *socket, const char *string, ...);')
def sendx(sock, *strings):
    """
    Send a series of strings (until NULL) as multipart data
    Returns 0 if the strings could be sent OK, or -1 on error.
    """

    varargs = [ffi.new('char[]', s) for s in strings] + [ffi.NULL]