diff --git a/NuGet.Config b/NuGet.Config deleted file mode 100644 index aad3952a3..000000000 --- a/NuGet.Config +++ /dev/null @@ -1,7 +0,0 @@ - - - - - - - \ No newline at end of file diff --git a/src/NetMQ/Monitoring/INetMQMonitor.cs b/src/NetMQ/Monitoring/INetMQMonitor.cs new file mode 100644 index 000000000..efd8b296f --- /dev/null +++ b/src/NetMQ/Monitoring/INetMQMonitor.cs @@ -0,0 +1,128 @@ +using System; +using System.Threading.Tasks; + +namespace NetMQ.Monitoring +{ + /// + /// Monitors a for events, raising them via events. + /// + /// + /// To run a monitor instance, either: + /// + /// Call (blocking) and , or + /// Call and . + /// + /// + public interface INetMQMonitor : IDisposable + { + /// + /// Gets the monitoring address. + /// + string Endpoint { get; } + + /// + /// Gets whether this monitor is currently running. + /// + /// + /// Start the monitor running via either or . + /// Stop the monitor via either or . + /// + bool IsRunning { get; } + + /// + /// Gets and sets the timeout interval for poll iterations when using and . + /// + /// + /// The higher the number the longer it may take the to stop the monitor. + /// This value has no effect when the monitor is run via . + /// + TimeSpan Timeout { get; set; } + + /// + /// Raised whenever any monitored event fires. + /// + event EventHandler? EventReceived; + + /// + /// Occurs when a connection is made to a socket. + /// + event EventHandler? Connected; + + /// + /// Occurs when a synchronous connection attempt failed, and its completion is being polled for. + /// + event EventHandler? ConnectDelayed; + + /// + /// Occurs when an asynchronous connect / reconnection attempt is being handled by a reconnect timer. + /// + event EventHandler? ConnectRetried; + + /// + /// Occurs when a socket is bound to an address and is ready to accept connections. + /// + event EventHandler? Listening; + + /// + /// Occurs when a socket could not bind to an address. + /// + event EventHandler? BindFailed; + + /// + /// Occurs when a connection from a remote peer has been established with a socket's listen address. + /// + event EventHandler? Accepted; + + /// + /// Occurs when a connection attempt to a socket's bound address fails. + /// + event EventHandler? AcceptFailed; + + /// + /// Occurs when a connection was closed. + /// + event EventHandler? Closed; + + /// + /// Occurs when a connection couldn't be closed. + /// + event EventHandler? CloseFailed; + + /// + /// Occurs when the stream engine (TCP and IPC specific) detects a corrupted / broken session. + /// + event EventHandler? Disconnected; + + /// + /// Adds the monitor object to a NetMQPoller. Register to to be signalled on new events. + /// + /// The poller to attach to. + /// The type of poller. + /// The is null. + /// The monitor is already started or already attached to a poller. + void AttachToPoller(T poller) where T : INetMQPoller; + + /// + /// Removes the monitor object from the attached poller. + /// + void DetachFromPoller(); + + /// + /// Starts monitoring the socket. This method doesn't start a new thread and will block until the monitor poll is stopped. + /// + /// The Monitor must not have already started nor attached to a poller. + void Start(); + + /// + /// Starts a background task for the monitoring operation. + /// + /// A task representing the monitoring operation. + Task StartAsync(); + + /// + /// Stops monitoring. Blocks until monitoring completed. + /// + /// If this monitor is attached to a poller you must detach it first and not use the method. + void Stop(); + } +} diff --git a/src/NetMQ/Monitoring/NetMQMonitor.cs b/src/NetMQ/Monitoring/NetMQMonitor.cs index bac778aac..7cb201916 100644 --- a/src/NetMQ/Monitoring/NetMQMonitor.cs +++ b/src/NetMQ/Monitoring/NetMQMonitor.cs @@ -7,17 +7,8 @@ namespace NetMQ.Monitoring { - /// - /// Monitors a for events, raising them via events. - /// - /// - /// To run a monitor instance, either: - /// - /// Call (blocking) and , or - /// Call and . - /// - /// - public class NetMQMonitor : IDisposable + /// + public class NetMQMonitor : INetMQMonitor { private readonly NetMQSocket m_monitoringSocket; private readonly bool m_ownsMonitoringSocket; @@ -68,84 +59,48 @@ public NetMQMonitor(NetMQSocket socket, string endpoint, bool ownsSocket = false m_ownsMonitoringSocket = ownsSocket; } - /// - /// The monitoring address. - /// + /// public string Endpoint { get; } - /// - /// Get whether this monitor is currently running. - /// - /// - /// Start the monitor running via either or . - /// Stop the monitor via either or . - /// + /// public bool IsRunning { get; private set; } - /// - /// Gets and sets the timeout interval for poll iterations when using and . - /// - /// - /// The higher the number the longer it may take the to stop the monitor. - /// This value has no effect when the monitor is run via . - /// + /// public TimeSpan Timeout { get; set; } #region Events - /// - /// Raised whenever any monitored event fires. - /// + /// public event EventHandler? EventReceived; - /// - /// Occurs when a connection is made to a socket. - /// + /// public event EventHandler? Connected; - /// - /// Occurs when a synchronous connection attempt failed, and its completion is being polled for. - /// + /// public event EventHandler? ConnectDelayed; - /// - /// Occurs when an asynchronous connect / reconnection attempt is being handled by a reconnect timer. - /// + /// public event EventHandler? ConnectRetried; - /// - /// Occurs when a socket is bound to an address and is ready to accept connections. - /// + /// public event EventHandler? Listening; - /// - /// Occurs when a socket could not bind to an address. - /// + /// public event EventHandler? BindFailed; - /// - /// Occurs when a connection from a remote peer has been established with a socket's listen address. - /// + /// public event EventHandler? Accepted; - /// - /// Occurs when a connection attempt to a socket's bound address fails. - /// + /// public event EventHandler? AcceptFailed; - /// - /// Occurs when a connection was closed. - /// + /// public event EventHandler? Closed; - /// - /// Occurs when a connection couldn't be closed. - /// + /// public event EventHandler? CloseFailed; - /// - /// Occurs when the stream engine (TCP and IPC specific) detects a corrupted / broken session. - /// + /// public event EventHandler? Disconnected; #endregion @@ -219,13 +174,7 @@ private void InternalClose() } } - /// - /// Add the monitor object to a NetMQPoller, register to to be signalled on new events - /// - /// - /// - /// - /// + /// public void AttachToPoller(T poller) where T : INetMQPoller { if (poller == null) @@ -239,9 +188,7 @@ public void AttachToPoller(T poller) where T : INetMQPoller poller.Add(m_monitoringSocket); } - /// - /// Remove the monitor object from attached poller - /// + /// public void DetachFromPoller() { DetachFromPoller(false); @@ -260,10 +207,7 @@ private void DetachFromPoller(bool dispose) InternalClose(); } - /// - /// Start monitor the socket, the method doesn't start a new thread and will block until the monitor poll is stopped - /// - /// The Monitor must not have already started nor attached to a poller. + /// public void Start() { if (IsRunning) @@ -287,10 +231,7 @@ public void Start() } } - /// - /// Start a background task for the monitoring operation. - /// - /// + /// public Task StartAsync() { if (IsRunning) @@ -302,10 +243,7 @@ public Task StartAsync() return Task.Factory.StartNew(Start); } - /// - /// Stop monitoring. Blocks until monitoring completed. - /// - /// If this monitor is attached to a poller you must detach it first and not use the stop method. + /// public void Stop() { if (m_attachedPoller != null)