devices.py 1.6 KB

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