INetMQSocket.cs 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. using System;
  2. using NetMQ.Core.Utils;
  3. namespace NetMQ
  4. {
  5. /// <summary>
  6. /// NetMQSocket interface, implement to fake the NetMQSocket in tests.
  7. /// </summary>
  8. public interface INetMQSocket : IOutgoingSocket, IReceivingSocket, ISocketPollable, IDisposable
  9. {
  10. /// <summary>
  11. /// This event occurs when at least one message may be received from the socket without blocking.
  12. /// </summary>
  13. /// <remarks>
  14. /// This event is raised when a <see cref="NetMQSocket"/> is added to a running <see cref="Poller"/>.
  15. /// </remarks>
  16. event EventHandler<NetMQSocketEventArgs> ReceiveReady;
  17. /// <summary>
  18. /// This event occurs when at least one message may be sent via the socket without blocking.
  19. /// </summary>
  20. /// <remarks>
  21. /// This event is raised when a <see cref="NetMQSocket"/> is added to a running <see cref="Poller"/>.
  22. /// </remarks>
  23. event EventHandler<NetMQSocketEventArgs> SendReady;
  24. /// <summary>
  25. /// Get the <see cref="SocketOptions"/> of this socket.
  26. /// </summary>
  27. SocketOptions Options { get; }
  28. /// <summary>
  29. /// Get whether a message is waiting to be picked up (<c>true</c> if there is, <c>false</c> if there is none).
  30. /// </summary>
  31. /// <exception cref="TerminatingException">The socket has been stopped.</exception>
  32. bool HasIn { get; }
  33. /// <summary>
  34. /// Get whether a message is waiting to be sent.
  35. /// </summary>
  36. /// <remarks>
  37. /// This is <c>true</c> if at least one message is waiting to be sent, <c>false</c> if there is none.
  38. /// </remarks>
  39. /// <exception cref="TerminatingException">The socket has been stopped.</exception>
  40. bool HasOut { get; }
  41. /// <summary>
  42. /// Bind the socket to <paramref name="address"/>.
  43. /// </summary>
  44. /// <param name="address">a string representing the address to bind this socket to</param>
  45. /// <exception cref="ObjectDisposedException">thrown if the socket was already disposed</exception>
  46. /// <exception cref="TerminatingException">The socket has been stopped.</exception>
  47. /// <exception cref="AddressAlreadyInUseException">The specified address is already in use.</exception>
  48. /// <exception cref="NetMQException">No IO thread was found, or the protocol's listener encountered an
  49. /// error during initialisation.</exception>
  50. void Bind(string address);
  51. /// <summary>Binds the specified TCP <paramref name="address"/> to an available port, assigned by the operating system.</summary>
  52. /// <returns>the chosen port-number</returns>
  53. /// <exception cref="ObjectDisposedException">thrown if the socket was already disposed</exception>
  54. /// <exception cref="ProtocolNotSupportedException"><paramref name="address"/> uses a protocol other than TCP.</exception>
  55. /// <exception cref="TerminatingException">The socket has been stopped.</exception>
  56. /// <exception cref="AddressAlreadyInUseException">The specified address is already in use.</exception>
  57. /// <exception cref="NetMQException">No IO thread was found, or the protocol's listener errored during
  58. /// initialisation.</exception>
  59. int BindRandomPort(string address);
  60. /// <summary>
  61. /// Connect the socket to <paramref name="address"/>.
  62. /// </summary>
  63. /// <param name="address">a string denoting the address to connect this socket to</param>
  64. /// <exception cref="ObjectDisposedException">thrown if the socket was already disposed</exception>
  65. /// <exception cref="TerminatingException">The socket has been stopped.</exception>
  66. /// <exception cref="NetMQException">No IO thread was found.</exception>
  67. /// <exception cref="AddressAlreadyInUseException">The specified address is already in use.</exception>
  68. void Connect(string address);
  69. /// <summary>
  70. /// Disconnect this socket from <paramref name="address"/>.
  71. /// </summary>
  72. /// <param name="address">a string denoting the address to disconnect from</param>
  73. /// <exception cref="ObjectDisposedException">thrown if the socket was already disposed</exception>
  74. /// <exception cref="TerminatingException">The socket has been stopped.</exception>
  75. /// <exception cref="EndpointNotFoundException">Endpoint was not found and cannot be disconnected.</exception>
  76. void Disconnect(string address);
  77. /// <summary>
  78. /// Unbind this socket from <paramref name="address"/>.
  79. /// </summary>
  80. /// <param name="address">a string denoting the address to unbind from</param>
  81. /// <exception cref="ObjectDisposedException">thrown if the socket was already disposed</exception>
  82. /// <exception cref="TerminatingException">The socket has been stopped.</exception>
  83. /// <exception cref="EndpointNotFoundException">Endpoint was not found and cannot be disconnected.</exception>
  84. void Unbind(string address);
  85. /// <summary>Closes this socket, rendering it unusable. Equivalent to calling <see cref="NetMQSocket.Dispose()"/>.</summary>
  86. void Close();
  87. /// <summary>
  88. /// Wait until a message is ready to be received from the socket.
  89. /// </summary>
  90. void Poll();
  91. /// <summary>
  92. /// Wait until a message is ready to be received/sent from this socket or until timeout is reached.
  93. /// If a message is available, the ReceiveReady/SendReady event is fired.
  94. /// </summary>
  95. /// <param name="timeout">a TimeSpan that represents the timeout-period</param>
  96. /// <returns>true if a message was available within the timeout, false otherwise</returns>
  97. bool Poll(TimeSpan timeout);
  98. /// <summary>
  99. /// Poll this socket, which means wait for an event to happen within the given timeout period.
  100. /// </summary>
  101. /// <param name="pollEvents">the poll event(s) to listen for</param>
  102. /// <param name="timeout">the timeout period</param>
  103. /// <returns>
  104. /// PollEvents.None -> no message available
  105. /// PollEvents.PollIn -> at least one message has arrived
  106. /// PollEvents.PollOut -> at least one message is ready to send
  107. /// PollEvents.Error -> an error has occurred
  108. /// or any combination thereof
  109. /// </returns>
  110. /// <exception cref="FaultException">The internal select operation failed.</exception>
  111. /// <exception cref="TerminatingException">The socket has been stopped.</exception>
  112. PollEvents Poll(PollEvents pollEvents, TimeSpan timeout);
  113. /// <summary>
  114. /// Listen to the given endpoint for SocketEvent events.
  115. /// </summary>
  116. /// <param name="endpoint">A string denoting the endpoint to monitor</param>
  117. /// <param name="events">The specific <see cref="SocketEvents"/> events to report on. Defaults to <see cref="SocketEvents.All"/> if omitted.</param>
  118. /// <exception cref="ArgumentNullException"><paramref name="endpoint"/> is <c>null</c>.</exception>
  119. /// <exception cref="ArgumentException"><paramref name="endpoint"/> cannot be empty or whitespace.</exception>
  120. /// <exception cref="ObjectDisposedException">This object is already disposed.</exception>
  121. /// <exception cref="ProtocolNotSupportedException">The protocol of <paramref name="endpoint"/> is not supported.</exception>
  122. /// <exception cref="TerminatingException">The socket has been stopped.</exception>
  123. /// <exception cref="NetMQException">Maximum number of sockets reached.</exception>
  124. void Monitor(string endpoint, SocketEvents events = SocketEvents.All);
  125. }
  126. }