devices.py 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. """zmq device functions"""
  2. # Copyright (C) PyZMQ Developers
  3. # Distributed under the terms of the Modified BSD License.
  4. from ._cffi import ffi
  5. from ._cffi import lib as C
  6. from .socket import Socket
  7. from .utils import _retry_sys_call
  8. def proxy(frontend, backend, capture=None):
  9. if isinstance(capture, Socket):
  10. capture = capture._zmq_socket
  11. else:
  12. capture = ffi.NULL
  13. _retry_sys_call(C.zmq_proxy, frontend._zmq_socket, backend._zmq_socket, capture)
  14. def proxy_steerable(frontend, backend, capture=None, control=None):
  15. """proxy_steerable(frontend, backend, capture, control)
  16. Start a zeromq proxy with control flow.
  17. .. versionadded:: libzmq-4.1
  18. .. versionadded:: 18.0
  19. Parameters
  20. ----------
  21. frontend : Socket
  22. The Socket instance for the incoming traffic.
  23. backend : Socket
  24. The Socket instance for the outbound traffic.
  25. capture : Socket (optional)
  26. The Socket instance for capturing traffic.
  27. control : Socket (optional)
  28. The Socket instance for control flow.
  29. """
  30. if isinstance(capture, Socket):
  31. capture = capture._zmq_socket
  32. else:
  33. capture = ffi.NULL
  34. if isinstance(control, Socket):
  35. control = control._zmq_socket
  36. else:
  37. control = ffi.NULL
  38. _retry_sys_call(
  39. C.zmq_proxy_steerable,
  40. frontend._zmq_socket,
  41. backend._zmq_socket,
  42. capture,
  43. control,
  44. )
  45. __all__ = ['proxy', 'proxy_steerable']