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


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


@cdef("int zstr_recvx (void *socket, char **string_p, ...);")
def recvx(sock, string_p):
    """
    Receive a series of strings (until NULL) from multipart data
    Each string is allocated and filled with string data; if there
    are not enough frames, unallocated strings are set to NULL.
    Returns -1 if the message could not be read, else returns the
    number of strings filled, zero or more.
    """
    return C.zstr_recvx(sock, string_p)


cdef("int zstr_test (bool verbose);")
Exemple #2
0
  - Automatically configures sockets with a ZMQ_LINGER timeout you can
    define, and which defaults to zero. The default behavior of zctx
    is therefore like 0MQ/2.0, immediate termination with loss of any
    pending messages. You can set any linger timeout you like by
    calling the zctx_set_linger() method.

  - Moves the iothreads configuration to a separate method, so that
    default usage is 1 I/O thread. Lets you configure this value.
    Sets up signal (SIGINT and SIGTERM) handling so that blocking
    calls such as zmq_recv() and zmq_poll() will return when the user
    presses Ctrl-C.
"""


cdef('typedef struct _zctx_t zctx_t;')


@cdef('void zctx_destroy (zctx_t **self_p);')
def destroy(ctx):
    """
    Destroy context and all sockets in it
    """
    return C.zctx_destroy(ptop('zctx_t', ctx))


@cdef('zctx_t * zctx_new (void);')
def new():
    """
    Create new context.
    """
Exemple #3
0
from pyczmq._cffi import C, ffi, cdef


cdef('typedef struct _zauth_t zauth_t;')


@cdef('void zauth_destroy (zauth_t **self_p);')
def destroy(auth):
    """ Destructor """
    return C.zauth_destroy(ptop('zauth_t', auth))


@cdef(' zauth_t * zauth_new (zctx_t *ctx);')
def new(ctx):
    """
    Install authentication for the specified context. Returns a new
    zauth object that you can use to configure authentication. Note
    that until you add policies, all incoming NULL connections are
    allowed (classic ZeroMQ behaviour), and all PLAIN and CURVE
    connections are denied. If there was an error during
    initialization, returns NULL.
    """
    return ffi.gc(zauth_new(ctx), destroy)



@cdef('void zauth_allow (zauth_t *self, char *address);')
def allow(auth, addr):
    """
    Allow (whitelist) a single IP address. For NULL, all clients from
    this address will be accepted. For PLAIN and CURVE, they will be
Exemple #4
0
__doc__ = """
The zbeacon class implements a peer-to-peer discovery service for
local networks. A beacon can broadcast and/or capture service
announcements using UDP messages on the local area network. This
implementation uses IPv4 UDP broadcasts. You can define the format of
your outgoing beacons, and set a filter that validates incoming
beacons. Beacons are sent and received asynchronously in the
background. The zbeacon API provides a incoming beacons on a ZeroMQ
socket (the pipe) that you can configure, poll on, and receive
messages on. Incoming beacons are always delivered as two frames: the
ipaddress of the sender (a string), and the beacon data itself
(binary, as published).
"""

cdef('typedef struct _zbeacon_t zbeacon_t;')


@cdef('void zbeacon_destroy (zbeacon_t **self_p);')
def destroy(beacon):
    """Destroy a beacon
    """
    C.zbeacon_destroy(ptop('zbeacon_t', beacon))


@cdef('zbeacon_t * zbeacon_new (zctx_t *self, int port_nbr);')
def new(ctx, port):
    """Create a new beacon on a certain UDP port
    """
    return ffi.gc(C.zbeacon_new(ctx, port), destroy)
Exemple #5
0
from pyczmq._cffi import C, ffi, ptop, cdef

__doc__ = """
The zmsg class provides methods to send and receive multipart messages
across 0MQ sockets. This class provides a list-like container
interface, with methods to work with the overall container. zmsg_t
messages are composed of zero or more zframe_t frames.
"""


cdef('typedef struct _zmsg_t zmsg_t;')


@cdef('void zmsg_destroy (zmsg_t **self_p);')
def destroy(m):
    """Destroy a message object and all frames it contains
    """
    C.zmsg_destroy(ptop('zmsg_t', m))

@cdef('zmsg_t * zmsg_new (void);')
def new():
    """Create a new empty message object,

    Note, no gc wrapper, messages self-destruct by send.  If you don't
    send a message, you DO have to destroy() it.
    """
    return C.zmsg_new()


@cdef('zmsg_t * zmsg_recv (void *socket);', nullable=True)
def recv(socket):
Exemple #6
0
cdef('''

/*  =========================================================================
    zsockopt - get/set 0MQ socket options

            ****************************************************
            *   GENERATED SOURCE CODE, DO NOT EDIT!!           *
            *   TO CHANGE THIS, EDIT scripts/sockopts.gsl      *
            *   AND RUN ./generate in models/.                 *
            ****************************************************
    -------------------------------------------------------------------------
    Copyright (c) 1991-2013 iMatix Corporation <www.imatix.com>
    Copyright other contributors as noted in the AUTHORS file.

    This file is part of CZMQ, the high-level C binding for 0MQ:
    http://czmq.zeromq.org.

    This is free software; you can redistribute it and/or modify it under
    the terms of the GNU Lesser General Public License as published by the
    Free Software Foundation; either version 3 of the License, or (at your
    option) any later version.

    This software is distributed in the hope that it will be useful, but
    WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABIL-
    ITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General
    Public License for more details.

    You should have received a copy of the GNU Lesser General Public License
    along with this program. If not, see <http://www.gnu.org/licenses/>.
    =========================================================================
*/

 int zsocket_ipv6 (void *zocket);
 int zsocket_ipv4only (void *zocket);
 int zsocket_plain_server (void *zocket);
 char * zsocket_plain_username (void *zocket);
 char * zsocket_plain_password (void *zocket);
 int zsocket_curve_server (void *zocket);
 char * zsocket_curve_publickey (void *zocket);
 char * zsocket_curve_secretkey (void *zocket);
 char * zsocket_curve_serverkey (void *zocket);
 char * zsocket_zap_domain (void *zocket);
 int zsocket_type (void *zocket);
 int zsocket_sndhwm (void *zocket);
 int zsocket_rcvhwm (void *zocket);
 int zsocket_affinity (void *zocket);
 char * zsocket_identity (void *zocket);
 int zsocket_rate (void *zocket);
 int zsocket_recovery_ivl (void *zocket);
 int zsocket_sndbuf (void *zocket);
 int zsocket_rcvbuf (void *zocket);
 int zsocket_linger (void *zocket);
 int zsocket_reconnect_ivl (void *zocket);
 int zsocket_reconnect_ivl_max (void *zocket);
 int zsocket_backlog (void *zocket);
 int zsocket_maxmsgsize (void *zocket);
 int zsocket_multicast_hops (void *zocket);
 int zsocket_rcvtimeo (void *zocket);
 int zsocket_sndtimeo (void *zocket);
 int zsocket_tcp_keepalive (void *zocket);
 int zsocket_tcp_keepalive_idle (void *zocket);
 int zsocket_tcp_keepalive_cnt (void *zocket);
 int zsocket_tcp_keepalive_intvl (void *zocket);
 char * zsocket_tcp_accept_filter (void *zocket);
 int zsocket_rcvmore (void *zocket);
 int zsocket_fd (void *zocket);
 int zsocket_events (void *zocket);
 char * zsocket_last_endpoint (void *zocket);

//  Set socket options
 void zsocket_set_ipv6 (void *zocket, int ipv6);
 void zsocket_set_immediate (void *zocket, int immediate);
 void zsocket_set_router_raw (void *zocket, int router_raw);
 void zsocket_set_ipv4only (void *zocket, int ipv4only);
 void zsocket_set_delay_attach_on_connect (void *zocket, int delay_attach_on_connect);
 void zsocket_set_router_mandatory (void *zocket, int router_mandatory);
 void zsocket_set_probe_router (void *zocket, int probe_router);
 void zsocket_set_req_relaxed (void *zocket, int req_relaxed);
 void zsocket_set_req_correlate (void *zocket, int req_correlate);
 void zsocket_set_conflate (void *zocket, int conflate);
 void zsocket_set_plain_server (void *zocket, int plain_server);
 void zsocket_set_plain_username (void *zocket, const char * plain_username);
 void zsocket_set_plain_password (void *zocket, const char * plain_password);
 void zsocket_set_curve_server (void *zocket, int curve_server);
 void zsocket_set_curve_publickey (void *zocket, const char * curve_publickey);
 void zsocket_set_curve_publickey_bin (void *zocket, const char *curve_publickey);
 void zsocket_set_curve_secretkey (void *zocket, const char * curve_secretkey);
 void zsocket_set_curve_secretkey_bin (void *zocket, const char *curve_secretkey);
 void zsocket_set_curve_serverkey (void *zocket, const char * curve_serverkey);
 void zsocket_set_curve_serverkey_bin (void *zocket, const char *curve_serverkey);
 void zsocket_set_zap_domain (void *zocket, const char * zap_domain);
 void zsocket_set_sndhwm (void *zocket, int sndhwm);
 void zsocket_set_rcvhwm (void *zocket, int rcvhwm);
 void zsocket_set_affinity (void *zocket, int affinity);
 void zsocket_set_subscribe (void *zocket, const char * subscribe);
 void zsocket_set_unsubscribe (void *zocket, const char * unsubscribe);
 void zsocket_set_identity (void *zocket, const char * identity);
 void zsocket_set_rate (void *zocket, int rate);
 void zsocket_set_recovery_ivl (void *zocket, int recovery_ivl);
 void zsocket_set_sndbuf (void *zocket, int sndbuf);
 void zsocket_set_rcvbuf (void *zocket, int rcvbuf);
 void zsocket_set_linger (void *zocket, int linger);
 void zsocket_set_reconnect_ivl (void *zocket, int reconnect_ivl);
 void zsocket_set_reconnect_ivl_max (void *zocket, int reconnect_ivl_max);
 void zsocket_set_backlog (void *zocket, int backlog);
 void zsocket_set_maxmsgsize (void *zocket, int maxmsgsize);
 void zsocket_set_multicast_hops (void *zocket, int multicast_hops);
 void zsocket_set_rcvtimeo (void *zocket, int rcvtimeo);
 void zsocket_set_sndtimeo (void *zocket, int sndtimeo);
 void zsocket_set_xpub_verbose (void *zocket, int xpub_verbose);
 void zsocket_set_tcp_keepalive (void *zocket, int tcp_keepalive);
 void zsocket_set_tcp_keepalive_idle (void *zocket, int tcp_keepalive_idle);
 void zsocket_set_tcp_keepalive_cnt (void *zocket, int tcp_keepalive_cnt);
 void zsocket_set_tcp_keepalive_intvl (void *zocket, int tcp_keepalive_intvl);
 void zsocket_set_tcp_accept_filter (void *zocket, const char * tcp_accept_filter);

//  Emulation of widely-used 2.x socket options
 void zsocket_set_hwm (void *zocket, int hwm);

int zsockopt_test (bool verbose);
''')
Exemple #7
0
from pyczmq._cffi import ffi, C, ptop, cdef

__doc__ = """
The zloop class provides an event-driven reactor pattern. The reactor
handles zmq_pollitem_t items (pollers or writers, sockets or fds), and
once-off or repeated timers. Its resolution is 1 msec. It uses a
tickless timer to reduce CPU interrupts in inactive processes.
"""

cdef('typedef struct _zloop_t zloop_t;')
cdef(
    'typedef int (zloop_fn) (zloop_t *loop, zmq_pollitem_t *item, void *arg);')
cdef('typedef int (zloop_timer_fn) (zloop_t *loop, int timer_id, void *arg);')


def poll_callback(f):
    @ffi.callback('zloop_fn')
    def handler(loop, item, arg):
        return f(loop, item, ffi.from_handle(arg))

    return handler


def timer_callback(f):
    @ffi.callback('zloop_timer_fn')
    def handler(loop, timer_id, arg):
        return f(loop, timer_id, ffi.from_handle(arg))

    return handler

Exemple #8
0
from pyczmq._cffi import ffi, C, ptop, cdef

__doc__ = """
The zloop class provides an event-driven reactor pattern. The reactor
handles zmq_pollitem_t items (pollers or writers, sockets or fds), and
once-off or repeated timers. Its resolution is 1 msec. It uses a
tickless timer to reduce CPU interrupts in inactive processes.
"""


cdef('typedef struct _zloop_t zloop_t;')
cdef('typedef int (zloop_fn) (zloop_t *loop, zmq_pollitem_t *item, void *arg);')


@cdef('void zloop_destroy (zloop_t **self_p);')
def destroy(loop):
    """
    Destroy a reactor, this is not necessary if you create it with
    new.
    """
    return C.zloop_destroy(ptop('zloop_t', loop))


@cdef(' zloop_t * zloop_new (void);')
def new():
    """Create a new zloop reactor"""
    return ffi.gc(C.zloop_new(), destroy)


@cdef('int zloop_poller (zloop_t *self, zmq_pollitem_t *item,'
         ' zloop_fn handler, void *arg);')
Exemple #9
0
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]
    return C.zstr_sendx(sock, *varargs)


@cdef('int zstr_recvx (void *socket, char **string_p, ...);')
def recvx(sock, string_p):
    """
    Receive a series of strings (until NULL) from multipart data
    Each string is allocated and filled with string data; if there
    are not enough frames, unallocated strings are set to NULL.
    Returns -1 if the message could not be read, else returns the
    number of strings filled, zero or more.
    """
    return C.zstr_recvx(sock, string_p)


cdef('int zstr_test (bool verbose);')
Exemple #10
0
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]
    return C.zstr_sendx(sock, *varargs)


@cdef('int zstr_recvx (void *socket, char **string_p, ...);')
def recvx(sock, string_p):
    """
    Receive a series of strings (until NULL) from multipart data
    Each string is allocated and filled with string data; if there
    are not enough frames, unallocated strings are set to NULL.
    Returns -1 if the message could not be read, else returns the
    number of strings filled, zero or more.
    """
    return C.zstr_recvx(sock, string_p)


cdef('int zstr_test (bool verbose);')
Exemple #11
0
from __future__ import print_function
from pyczmq._cffi import C, cdef, ffi, ptop

__doc__ = """
The zframe class provides methods to send and receive single message
frames across 0MQ sockets. A frame corresponds to one zmq_msg_t. When
you read a frame from a socket, the zframe_more() method indicates if
the frame is part of an unfinished multipart message. The zframe_send
method normally destroys the frame, but with the ZFRAME_REUSE flag,
you can send the same frame many times. Frames are binary, and this
class has no special support for text data.
"""


cdef("typedef struct _zframe_t zframe_t;")


MORE = 1
REUSE = 2
DONTWAIT = 4


@cdef("void zframe_destroy (zframe_t **self_p);")
def destroy(frame):
    """Destroy a frame
    """
    C.zframe_destroy(ptop("zframe_t", frame))


@cdef("zframe_t * zframe_new (const void *data, size_t size);")
def new(data):
Exemple #12
0
from pyczmq._cffi import C, ffi, ptop, cdef

cdef('typedef struct _zcertstore_t zcertstore_t;')


@cdef('void zcertstore_destroy (zcertstore_t **self_p);')
def destroy(store):
    """
    Destroy a certificate store object in memory. Does not affect anything
    stored on disk.
    """
    C.zcertstore_destroy(ptop('zcertstore_t', store))


@cdef('zcertstore_t * zcertstore_new (char *location, ...);')
def new(location):
    """
    Create a new certificate store from a disk directory, loading and
    indexing all certificates in that location. The directory itself may be
    absent, and created later, or modified at any time. The certificate store
    is automatically refreshed on any zcertstore_lookup() call. If the
    location is specified as NULL, creates a pure-memory store, which you
    can work with by inserting certificates at runtime. The location is
    treated as a printf format.
    """
    return ffi.gc(C.zcertstore_new(location), destroy)


@cdef('zcert_t * zcertstore_lookup (zcertstore_t *self, char *public_key);')
def lookup(store, key):
    """
Exemple #13
0
from pyczmq._cffi import ffi, C, ptop, cdef
from pyczmq import zsock

__doc__ = """
The zloop class provides an event-driven reactor pattern. The reactor
handles zmq_pollitem_t items (pollers or writers, sockets or fds), and
once-off or repeated timers. Its resolution is 1 msec. It uses a
tickless timer to reduce CPU interrupts in inactive processes.
"""


cdef('typedef struct _zloop_t zloop_t;')
cdef('typedef int (zloop_fn) (zloop_t *loop, zmq_pollitem_t *item, void *arg);')
cdef('typedef int (zloop_timer_fn) (zloop_t *loop, int timer_id, void *arg);')
cdef('typedef int (zloop_reader_fn) (zloop_t *loop, zsock_t *reader, void *arg);')


def poll_callback(f):
    @ffi.callback('zloop_fn')
    def handler(loop, item, arg):
        return f(loop, item, ffi.from_handle(arg))
    return handler


def timer_callback(f):
    @ffi.callback('zloop_timer_fn')
    def handler(loop, timer_id, arg):
        return f(loop, timer_id, ffi.from_handle(arg))
    return handler

Exemple #14
0
    return Z.zmq_msg_more(msg)


@cdef('int zmq_msg_get (zmq_msg_t *msg, int option);')
def msg_get(msg, opt):
    return Z.zmq_msg_get(msg, opt)


@cdef('int zmq_msg_set (zmq_msg_t *msg, int option, int optval);')
def msg_set(msg, opt, val):
    return Z.zmq_msg_set(msg, opt, val)


cdef('''
typedef struct {
    uint16_t event;
    int32_t  value;
} zmq_event_t;
''')


@cdef('void *zmq_socket (void *ctx, int type);')
def socket(ctx, typ):
    return Z.zmq_socket(ctx, typ)


@cdef('int zmq_close (void *sock);')
def close(sock):
    return Z.zmq_close(sock)


@cdef('int zmq_setsockopt (void *s, int option,'
Exemple #15
0
from pyczmq._cffi import C, ffi, cdef, ptop

CURVE_ALLOW_ANY = "*"

cdef('typedef struct _zauth_t zauth_t;')


@cdef('void zauth_destroy (zauth_t **self_p);')
def destroy(auth):
    """ Destructor """
    C.zauth_destroy(ptop('zauth_t', auth))


@cdef('zauth_t * zauth_new (zctx_t *ctx);')
def new(ctx):
    """
    Install authentication for the specified context. Returns a new
    zauth object that you can use to configure authentication. Note
    that until you add policies, all incoming NULL connections are
    allowed (classic ZeroMQ behaviour), and all PLAIN and CURVE
    connections are denied. If there was an error during
    initialization, returns NULL.
    """
    return ffi.gc(C.zauth_new(ctx), destroy)


@cdef('void zauth_allow (zauth_t *self, char *address);')
def allow(auth, addr):
    """
    Allow (whitelist) a single IP address. For NULL, all clients from
    this address will be accepted. For PLAIN and CURVE, they will be
Exemple #16
0
from pyczmq._cffi import C, ffi, ptop, cdef

cdef('typedef struct _zcert_t zcert_t;')


@cdef('void zcert_destroy (zcert_t **self_p);')
def destroy(cert):
    """Destroy a certificate in memory
    """
    C.zcert_destroy(ptop('zcert_t', cert))


@cdef('zcert_t * zcert_new (void);')
def new():
    """Create and initialize a new certificate in memory
    """
    return ffi.gc(C.zcert_new(), destroy)


@cdef('zcert_t * zcert_new_from (char *public_key, char *secret_key);')
def new_from(public_key, secret_key):
    """Constructor, accepts public/secret key pair from caller
    """
    return ffi.gc(C.zcert_new_from(public_key, secret_key), destroy)


@cdef('char * zcert_public_key (zcert_t *self);')
def public_key(cert):
    """Return public part of key pair as 32-byte binary string
    """
    return C.zcert_public_key(cert)
Exemple #17
0
from pyczmq._cffi import C, ffi, cdef, ptop

__doc__ = """
The zpoller class provides a minimalist interface to ZeroMQ's zmq_poll
API, for the very common case of reading from a number of sockets. It
does not provide polling for output, nor polling on file handles. If
you need either of these, use the zmq_poll API directly.
"""

cdef("typedef struct _zpoller_t zpoller_t;")


@cdef("void zpoller_destroy (zpoller_t **self_p);")
def destroy(poller):
    """Destroy a poller"""
    C.zpoller_destroy(ptop("zpoller_t", poller))


@cdef("zpoller_t * zpoller_new (void *reader, ...);")
def new(reader, *readers):
    """Create new poller"""
    return ffi.gc(C.zpoller_new(reader, *readers), destroy)


@cdef(" void * zpoller_wait (zpoller_t *self, int timeout);", nullable=True)
def wait(poller, timeout):
    """
    Poll the registered readers for I/O, return first socket that has input.
    This means the order that sockets are defined in the poll list affects
    their priority. If you need a balanced poll, use the low level zmq_poll
    method directly.
Exemple #18
0
from pyczmq._cffi import C, ptop, cdef

__doc__ = """
The zmsg class provides methods to send and receive multipart messages
across 0MQ sockets. This class provides a list-like container
interface, with methods to work with the overall container. zmsg_t
messages are composed of zero or more zframe_t frames.
"""

cdef('typedef struct _zmsg_t zmsg_t;')


@cdef('void zmsg_destroy (zmsg_t **self_p);')
def destroy(m):
    """Destroy a message object and all frames it contains
    """
    C.zmsg_destroy(ptop('zmsg_t', m))


@cdef('zmsg_t * zmsg_new (void);')
def new():
    """Create a new empty message object,

    Note, no gc wrapper, messages self-destruct by send.  If you don't
    send a message, you DO have to destroy() it.
    """
    return C.zmsg_new()


@cdef('zmsg_t * zmsg_recv (void *socket);', nullable=True)
def recv(socket):
Exemple #19
0
from __future__ import print_function
from pyczmq._cffi import C, cdef, ffi, ptop

__doc__ = """
The zframe class provides methods to send and receive single message
frames across 0MQ sockets. A frame corresponds to one zmq_msg_t. When
you read a frame from a socket, the zframe_more() method indicates if
the frame is part of an unfinished multipart message. The zframe_send
method normally destroys the frame, but with the ZFRAME_REUSE flag,
you can send the same frame many times. Frames are binary, and this
class has no special support for text data.
"""


cdef('typedef struct _zframe_t zframe_t;')


MORE = 1
REUSE = 2
DONTWAIT = 4


@cdef('void zframe_destroy (zframe_t **self_p);')
def destroy(frame):
    """Destroy a frame
    """
    C.zframe_destroy(ptop('zframe_t', frame))


@cdef('zframe_t * zframe_new (const void *data, size_t size);')
def new(data):
Exemple #20
0
    calling zmq_term(). This avoids an infinite wait on open sockets.

  - Automatically configures sockets with a ZMQ_LINGER timeout you can
    define, and which defaults to zero. The default behavior of zctx
    is therefore like 0MQ/2.0, immediate termination with loss of any
    pending messages. You can set any linger timeout you like by
    calling the zctx_set_linger() method.

  - Moves the iothreads configuration to a separate method, so that
    default usage is 1 I/O thread. Lets you configure this value.
    Sets up signal (SIGINT and SIGTERM) handling so that blocking
    calls such as zmq_recv() and zmq_poll() will return when the user
    presses Ctrl-C.
"""

cdef('typedef struct _zctx_t zctx_t;')


@cdef('zctx_t * zctx_shadow (zctx_t *self);')
def shadow(ctx):
    """
    Create new shadow context, returns context object
    """
    return C.zctx_shadow(ctx)


@cdef('zctx_t * zctx_shadow_zmq_ctx (void *zmqctx);')
def shadow_zmq_ctx(zmqctx):
    """
    Create a new context by shadowing a plain zmq context
    """
Exemple #21
0
cdef('''

/*  =========================================================================
    zsockopt - get/set 0MQ socket options

            ****************************************************
            *   GENERATED SOURCE CODE, DO NOT EDIT!!           *
            *   TO CHANGE THIS, EDIT scripts/sockopts.gsl      *
            *   AND RUN ./generate in models/.                 *
            ****************************************************
    -------------------------------------------------------------------------
    Copyright (c) 1991-2013 iMatix Corporation <www.imatix.com>
    Copyright other contributors as noted in the AUTHORS file.

    This file is part of CZMQ, the high-level C binding for 0MQ:
    http://czmq.zeromq.org.

    This is free software; you can redistribute it and/or modify it under
    the terms of the GNU Lesser General Public License as published by the
    Free Software Foundation; either version 3 of the License, or (at your
    option) any later version.

    This software is distributed in the hope that it will be useful, but
    WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABIL-
    ITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General
    Public License for more details.

    You should have received a copy of the GNU Lesser General Public License
    along with this program. If not, see <http://www.gnu.org/licenses/>.
    =========================================================================
*/

 int zsocket_ipv6 (void *zocket);
 int zsocket_ipv4only (void *zocket);
 int zsocket_probe_router (void *zocket);
 int zsocket_plain_server (void *zocket);
 char * zsocket_plain_username (void *zocket);
 char * zsocket_plain_password (void *zocket);
 int zsocket_curve_server (void *zocket);
 char * zsocket_curve_publickey (void *zocket);
 char * zsocket_curve_secretkey (void *zocket);
 char * zsocket_curve_serverkey (void *zocket);
 char * zsocket_zap_domain (void *zocket);
 int zsocket_type (void *zocket);
 int zsocket_sndhwm (void *zocket);
 int zsocket_rcvhwm (void *zocket);
 int zsocket_affinity (void *zocket);
 char * zsocket_identity (void *zocket);
 int zsocket_rate (void *zocket);
 int zsocket_recovery_ivl (void *zocket);
 int zsocket_sndbuf (void *zocket);
 int zsocket_rcvbuf (void *zocket);
 int zsocket_linger (void *zocket);
 int zsocket_reconnect_ivl (void *zocket);
 int zsocket_reconnect_ivl_max (void *zocket);
 int zsocket_backlog (void *zocket);
 int zsocket_maxmsgsize (void *zocket);
 int zsocket_multicast_hops (void *zocket);
 int zsocket_rcvtimeo (void *zocket);
 int zsocket_sndtimeo (void *zocket);
 int zsocket_tcp_keepalive (void *zocket);
 int zsocket_tcp_keepalive_idle (void *zocket);
 int zsocket_tcp_keepalive_cnt (void *zocket);
 int zsocket_tcp_keepalive_intvl (void *zocket);
 char * zsocket_tcp_accept_filter (void *zocket);
 int zsocket_rcvmore (void *zocket);
 int zsocket_fd (void *zocket);
 int zsocket_events (void *zocket);
 char * zsocket_last_endpoint (void *zocket);

//  Set socket options
 void zsocket_set_ipv6 (void *zocket, int ipv6);
 void zsocket_set_immediate (void *zocket, int immediate);
 void zsocket_set_router_raw (void *zocket, int router_raw);
 void zsocket_set_ipv4only (void *zocket, int ipv4only);
 void zsocket_set_delay_attach_on_connect (void *zocket, int delay_attach_on_connect);
 void zsocket_set_router_mandatory (void *zocket, int router_mandatory);
 void zsocket_set_req_relaxed (void *zocket, int req_relaxed);
 void zsocket_set_req_correlate (void *zocket, int req_correlate);
 void zsocket_set_conflate (void *zocket, int conflate);
 void zsocket_set_plain_server (void *zocket, int plain_server);
 void zsocket_set_plain_username (void *zocket, const char * plain_username);
 void zsocket_set_plain_password (void *zocket, const char * plain_password);
 void zsocket_set_curve_server (void *zocket, int curve_server);
 void zsocket_set_curve_publickey (void *zocket, const char * curve_publickey);
 void zsocket_set_curve_publickey_bin (void *zocket, const char *curve_publickey);
 void zsocket_set_curve_secretkey (void *zocket, const char * curve_secretkey);
 void zsocket_set_curve_secretkey_bin (void *zocket, const char *curve_secretkey);
 void zsocket_set_curve_serverkey (void *zocket, const char * curve_serverkey);
 void zsocket_set_curve_serverkey_bin (void *zocket, const char *curve_serverkey);
 void zsocket_set_zap_domain (void *zocket, const char * zap_domain);
 void zsocket_set_sndhwm (void *zocket, int sndhwm);
 void zsocket_set_rcvhwm (void *zocket, int rcvhwm);
 void zsocket_set_affinity (void *zocket, int affinity);
 void zsocket_set_subscribe (void *zocket, const char * subscribe);
 void zsocket_set_unsubscribe (void *zocket, const char * unsubscribe);
 void zsocket_set_identity (void *zocket, const char * identity);
 void zsocket_set_rate (void *zocket, int rate);
 void zsocket_set_recovery_ivl (void *zocket, int recovery_ivl);
 void zsocket_set_sndbuf (void *zocket, int sndbuf);
 void zsocket_set_rcvbuf (void *zocket, int rcvbuf);
 void zsocket_set_linger (void *zocket, int linger);
 void zsocket_set_reconnect_ivl (void *zocket, int reconnect_ivl);
 void zsocket_set_reconnect_ivl_max (void *zocket, int reconnect_ivl_max);
 void zsocket_set_backlog (void *zocket, int backlog);
 void zsocket_set_maxmsgsize (void *zocket, int maxmsgsize);
 void zsocket_set_multicast_hops (void *zocket, int multicast_hops);
 void zsocket_set_rcvtimeo (void *zocket, int rcvtimeo);
 void zsocket_set_sndtimeo (void *zocket, int sndtimeo);
 void zsocket_set_xpub_verbose (void *zocket, int xpub_verbose);
 void zsocket_set_tcp_keepalive (void *zocket, int tcp_keepalive);
 void zsocket_set_tcp_keepalive_idle (void *zocket, int tcp_keepalive_idle);
 void zsocket_set_tcp_keepalive_cnt (void *zocket, int tcp_keepalive_cnt);
 void zsocket_set_tcp_keepalive_intvl (void *zocket, int tcp_keepalive_intvl);
 void zsocket_set_tcp_accept_filter (void *zocket, const char * tcp_accept_filter);

//  Emulation of widely-used 2.x socket options
 void zsocket_set_hwm (void *zocket, int hwm);

int zsockopt_test (bool verbose);
''')
Exemple #22
0
from __future__ import print_function
from pyczmq._cffi import C, cdef, ptop

__doc__ = """
The zframe class provides methods to send and receive single message
frames across 0MQ sockets. A frame corresponds to one zmq_msg_t. When
you read a frame from a socket, the zframe_more() method indicates if
the frame is part of an unfinished multipart message. The zframe_send
method normally destroys the frame, but with the ZFRAME_REUSE flag,
you can send the same frame many times. Frames are binary, and this
class has no special support for text data.
"""


cdef('typedef struct _zframe_t zframe_t;')


MORE = 1
REUSE = 2
DONTWAIT = 4


@cdef('void zframe_destroy (zframe_t **self_p);')
def destroy(frame):
    """Destroy a frame
    """
    return C.zframe_destroy(ptop('zframe_t', frame))


@cdef('zframe_t * zframe_new (const void *data, size_t size);')
def new(data):
Exemple #23
0
from pyczmq._cffi import C, ffi, ptop, cdef

cdef('typedef struct _zcertstore_t zcertstore_t;')


@cdef('void zcertstore_destroy (zcertstore_t **self_p);')
def destroy(store):
    """
    Destroy a certificate store object in memory. Does not affect anything
    stored on disk.
    """
    C.zcertstore_destroy(ptop('zcertstore_t', store))


@cdef('zcertstore_t * zcertstore_new (char *location, ...);')
def new(location):
    """
    Create a new certificate store from a disk directory, loading and 
    indexing all certificates in that location. The directory itself may be
    absent, and created later, or modified at any time. The certificate store 
    is automatically refreshed on any zcertstore_lookup() call. If the 
    location is specified as NULL, creates a pure-memory store, which you 
    can work with by inserting certificates at runtime. The location is
    treated as a printf format.
    """
    return ffi.gc(C.zcertstore_new(location), destroy)


@cdef('zcert_t * zcertstore_lookup (zcertstore_t *self, char *public_key);')
def lookup(store, key):
    """
Exemple #24
0
import inspect
from pyczmq._cffi import C, ffi, ptop, cdef
from pyczmq import zmsg

__doc__ = """
"""

cdef('typedef struct _zsock_t zsock_t;')


@cdef('void zsock_destroy (zsock_t **p_self);')
def destroy(sock):
    """Destroy a sock."""
    C.zsock_destroy(ptop('zsock_t', sock))


@cdef('zsock_t * zsock_new (int type, const char *filename, size_t line_nbr);')
def new(type, filename=None, line_nbr=None):
    if filename is None:
        frame = inspect.stack()[1][0]
        info = inspect.getframeinfo(frame)
        filename = info.filename
        line_nbr = info.lineno
    return ffi.gc(C.zsock_new(type, filename, line_nbr), destroy)


@cdef('int zsock_bind (zsock_t *self, const char *format, ...);')
def bind(sock, endpoint):
    """ Bind a socket to a formatted endpoint. If the port is specified as '*'
    and the endpoint starts with "tcp://", binds to an ephemeral TCP port in
    a high range. Always returns the port number on successful TCP binds, else
Exemple #25
0
    return Z.zmq_msg_more(msg)


@cdef('int zmq_msg_get (zmq_msg_t *msg, int option);')
def msg_get(msg, opt):
    return Z.zmq_msg_get(msg, opt)


@cdef('int zmq_msg_set (zmq_msg_t *msg, int option, int optval);')
def msg_set(msg, opt, val):
    return Z.zmq_msg_set(msg, opt, val)


cdef('''
typedef struct {
    uint16_t event;
    int32_t  value;
} zmq_event_t;
''')


@cdef('void *zmq_socket (void *ctx, int type);')
def socket(ctx, typ):
    return Z.zmq_socket(ctx, typ)


@cdef('int zmq_close (void *sock);')
def close(sock):
    return Z.zmq_close(sock)


@cdef('int zmq_setsockopt (void *s, int option,'
Exemple #26
0
from pyczmq._cffi import C, ffi, ptop, cdef
from pyczmq import zsock, zmsg, zframe # need zsock_t, zmsg_t, zframe_t

__doc__ = """
"""


cdef('typedef struct _zactor_t zactor_t;')


# Actors get a pipe and arguments from caller
cdef('typedef void (zactor_fn) (zsock_t *pipe, void *args);')


def callback(f):
    @ffi.callback('zactor_fn')
    def handler(pipe, args):
        return f(pipe, ffi.from_handle(args))
    return handler


@cdef('void zactor_destroy (zactor_t **p_self);')
def destroy(actor):
    """Destroy an actor."""
    C.zactor_destroy(ptop('zactor_t', actor))


@cdef('zactor_t * zactor_new (zactor_fn *task, void *args);')
def new(task, args):
    """Create a new actor passing arbitrary arguments reference."""
    return ffi.gc(C.zactor_new(task, ffi.new_handle(args)), destroy)
Exemple #27
0
from pyczmq._cffi import C, ffi, cdef, ptop

__doc__ = """
The zpoller class provides a minimalist interface to ZeroMQ's zmq_poll
API, for the very common case of reading from a number of sockets. It
does not provide polling for output, nor polling on file handles. If
you need either of these, use the zmq_poll API directly.
"""

cdef('typedef struct _zpoller_t zpoller_t;')


@cdef('void zpoller_destroy (zpoller_t **self_p);')
def destroy(poller):
    """Destroy a poller"""
    C.zpoller_destroy(ptop('zpoller_t', poller))


@cdef('zpoller_t * zpoller_new (void *reader, ...);')
def new(reader, *readers):
    """Create new poller"""
    readers = list(readers) + [ffi.NULL]
    return ffi.gc(C.zpoller_new(reader, *readers), destroy)


@cdef(' void * zpoller_wait (zpoller_t *self, int timeout);', nullable=True)
def wait(poller, timeout):
    """
    Poll the registered readers for I/O, return first socket that has input.
    This means the order that sockets are defined in the poll list affects
    their priority. If you need a balanced poll, use the low level zmq_poll