1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
|
"""Python binding for 0MQ device function."""
#
# Copyright (c) 2010-2011 Brian E. Granger & Min Ragan-Kelley
#
# This file is part of pyzmq.
#
# pyzmq is free software; you can redistribute it and/or modify it under
# the terms of the Lesser GNU General Public License as published by
# the Free Software Foundation; either version 3 of the License, or
# (at your option) any later version.
#
# pyzmq is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# Lesser GNU General Public License for more details.
#
# You should have received a copy of the Lesser GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
#-----------------------------------------------------------------------------
# Imports
#-----------------------------------------------------------------------------
from libzmq cimport zmq_device, zmq_proxy, ZMQ_VERSION_MAJOR
from zmq.backend.cython.socket cimport Socket as cSocket
from zmq.backend.cython.checkrc cimport _check_rc
#-----------------------------------------------------------------------------
# Basic device API
#-----------------------------------------------------------------------------
def device(int device_type, cSocket frontend, cSocket backend=None):
"""device(device_type, frontend, backend)
Start a zeromq device.
.. deprecated:: libzmq-3.2
Use zmq.proxy
Parameters
----------
device_type : (QUEUE, FORWARDER, STREAMER)
The type of device to start.
frontend : Socket
The Socket instance for the incoming traffic.
backend : Socket
The Socket instance for the outbound traffic.
"""
if ZMQ_VERSION_MAJOR >= 3:
return proxy(frontend, backend)
cdef int rc = 0
with nogil:
rc = zmq_device(device_type, frontend.handle, backend.handle)
_check_rc(rc)
return rc
def proxy(cSocket frontend, cSocket backend, cSocket capture=None):
"""proxy(frontend, backend, capture)
Start a zeromq proxy (replacement for device).
.. versionadded:: libzmq-3.2
.. versionadded:: 13.0
Parameters
----------
frontend : Socket
The Socket instance for the incoming traffic.
backend : Socket
The Socket instance for the outbound traffic.
capture : Socket (optional)
The Socket instance for capturing traffic.
"""
cdef int rc = 0
cdef void* capture_handle
if isinstance(capture, cSocket):
capture_handle = capture.handle
else:
capture_handle = NULL
with nogil:
rc = zmq_proxy(frontend.handle, backend.handle, capture_handle)
_check_rc(rc)
return rc
__all__ = ['device', 'proxy']
|