1
"""Python binding for 0MQ device function."""
4
# Copyright (c) 2010-2011 Brian E. Granger & Min Ragan-Kelley
6
# This file is part of pyzmq.
8
# pyzmq is free software; you can redistribute it and/or modify it under
9
# the terms of the Lesser GNU General Public License as published by
10
# the Free Software Foundation; either version 3 of the License, or
11
# (at your option) any later version.
13
# pyzmq is distributed in the hope that it will be useful,
14
# but WITHOUT ANY WARRANTY; without even the implied warranty of
15
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16
# Lesser GNU General Public License for more details.
18
# You should have received a copy of the Lesser GNU General Public License
19
# along with this program. If not, see <http://www.gnu.org/licenses/>.
22
#-----------------------------------------------------------------------------
24
#-----------------------------------------------------------------------------
26
from libzmq cimport zmq_device, zmq_proxy, ZMQ_VERSION_MAJOR
27
from zmq.core.socket cimport Socket as cSocket
28
from zmq.core.checkrc cimport _check_rc
30
#-----------------------------------------------------------------------------
32
#-----------------------------------------------------------------------------
34
def device(int device_type, cSocket frontend, cSocket backend=None):
35
"""device(device_type, frontend, backend)
37
Start a zeromq device.
39
WARNING: zmq.device is deprecated as of libzmq-3.2,
40
in favor of zmq.proxy.
44
device_type : (QUEUE, FORWARDER, STREAMER)
45
The type of device to start.
47
The Socket instance for the incoming traffic.
49
The Socket instance for the outbound traffic.
51
if ZMQ_VERSION_MAJOR >= 3:
52
return proxy(frontend, backend)
56
rc = zmq_device(device_type, frontend.handle, backend.handle)
60
def proxy(cSocket frontend, cSocket backend, cSocket capture=None):
61
"""proxy(frontend, backend, capture)
63
Start a zeromq proxy (replacement for device).
68
The Socket instance for the incoming traffic.
70
The Socket instance for the outbound traffic.
72
The Socket instance for capturing traffic.
75
cdef void* capture_handle
76
if isinstance(capture, cSocket):
77
capture_handle = capture.handle
81
rc = zmq_proxy(frontend.handle, backend.handle, capture_handle)
85
__all__ = ['device', 'proxy']