Ejemplo n.º 1
0
 internal void OnMonitor(ZMonitorEventData data)
 {
     if (_eventHandler.ContainsKey(ZMonitorEvents.AllEvents))
     {
         _eventHandler[ZMonitorEvents.AllEvents](data);
     }
     if (_eventHandler.ContainsKey(data.Event))
     {
         _eventHandler[data.Event](data);
     }
 }
Ejemplo n.º 2
0
        // private static readonly int sizeof_MonitorEventData = Marshal.SizeOf(typeof(ZMonitorEventData));

        /// <summary>
        /// Begins monitoring for state changes, raising the appropriate events as they arrive.
        /// </summary>
        /// <remarks>NOTE: This is a blocking method and should be run from another thread.</remarks>
        protected override void Run()
        {
            using (_socket)
            {
                ZError error;
                if (!_socket.Connect(_endpoint, out error))
                {
                    LogError(error, "connect");
                    return;
                }

                var poller = ZPollItem.CreateReceiver();

                while (!Cancellor.IsCancellationRequested)
                {
                    ZMessage incoming;
                    if (!_socket.PollIn(poller, out incoming, out error, PollingInterval))
                    {
                        if (error == ZError.EAGAIN)
                        {
                            // TODO: why sleep here? the loop frequency is already controlled by PollingInterval
                            Thread.Sleep(1);
                            continue;
                        }

                        LogError(error, "poll");
                    }

                    var eventValue = new ZMonitorEventData();

                    using (incoming)
                    {
                        if (incoming.Count > 0)
                        {
                            eventValue.Event      = (ZMonitorEvents)incoming[0].ReadInt16();
                            eventValue.EventValue = incoming[0].ReadInt32();
                        }

                        if (incoming.Count > 1)
                        {
                            eventValue.Address = incoming[1].ReadString();
                        }
                    }

                    OnMonitor(eventValue);
                }

                if (!_socket.Disconnect(_endpoint, out error))
                {
                    LogError(error, "disconnect");
                }
            }
        }
Ejemplo n.º 3
0
 internal ZMonitorFileDescriptorEventArgs(ZMonitor monitor, ZMonitorEventData data)
     : base(monitor, data)
 {
     if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
     {
         FileDescriptor_Posix = data.EventValue;
     }
     else if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
     {
         FileDescriptor_Windows = new IntPtr(data.EventValue);
     }
     else
     {
         throw new PlatformNotSupportedException();
     }
 }
		internal ZMonitorFileDescriptorEventArgs(ZMonitor monitor, ZMonitorEventData data)
			: base(monitor, data)
		{
			if (Platform.Kind == PlatformKind.Posix)
			{
				this.FileDescriptor_Posix = data.EventValue;
			}
			else if (Platform.Kind == PlatformKind.Win32)
			{
				this.FileDescriptor_Windows = new IntPtr(data.EventValue);
			}
			else
			{
				throw new PlatformNotSupportedException();
			}
		}
 internal ZMonitorFileDescriptorEventArgs(ZMonitor monitor, ZMonitorEventData data)
     : base(monitor, data)
 {
     if (Platform.Kind == PlatformKind.Posix)
     {
         this.FileDescriptor_Posix = data.EventValue;
     }
     else if (Platform.Kind == PlatformKind.Win32)
     {
         this.FileDescriptor_Windows = new IntPtr(data.EventValue);
     }
     else
     {
         throw new PlatformNotSupportedException();
     }
 }
Ejemplo n.º 6
0
        // private static readonly int sizeof_MonitorEventData = Marshal.SizeOf(typeof(ZMonitorEventData));

        /// <summary>
        /// Begins monitoring for state changes, raising the appropriate events as they arrive.
        /// </summary>
        /// <remarks>NOTE: This is a blocking method and should be run from another thread.</remarks>
        protected override void Run()
        {
            _socket.Connect(_endpoint);

            ZError   error;
            ZMessage incoming;
            var      poller = ZPollItem.CreateReceiver();

            while (!Cancellor.IsCancellationRequested)
            {
                if (!_socket.PollIn(poller, out incoming, out error, PollingInterval))
                {
                    if (error == ZError.EAGAIN)
                    {
                        Thread.Sleep(1);
                        continue;
                    }

                    throw new ZException(error);
                }

                var eventValue = new ZMonitorEventData();

                using (incoming) {
                    if (incoming.Count > 0)
                    {
                        eventValue.Event      = (ZMonitorEvents)incoming[0].ReadInt16();
                        eventValue.EventValue = incoming[0].ReadInt32();
                    }

                    if (incoming.Count > 1)
                    {
                        eventValue.Address = incoming[1].ReadString();
                    }
                }

                OnMonitor(eventValue);
            }

            if (!_socket.Disconnect(_endpoint, out error))
            {
            }                                                              // ignore errors
        }
Ejemplo n.º 7
0
 /// <summary>
 /// Initializes a new instance of the <see cref="ZMonitorEventArgs"/> class.
 /// </summary>
 /// <param name="monitor">The <see cref="ZMonitor"/> that triggered the event.</param>
 /// <param name="address">The peer address.</param>
 public ZMonitorEventArgs(ZMonitor monitor, ZMonitorEventData ed)
 {
     this.Monitor = monitor;
     this.Event   = ed;
 }
Ejemplo n.º 8
0
		/// <summary>
		/// Initializes a new instance of the <see cref="ZMonitorEventArgs"/> class.
		/// </summary>
		/// <param name="monitor">The <see cref="ZMonitor"/> that triggered the event.</param>
		/// <param name="address">The peer address.</param>
		public ZMonitorEventArgs(ZMonitor monitor, ZMonitorEventData ed)
		{
			this.Monitor = monitor;
			this.Event = ed;
		}
Ejemplo n.º 9
0
 /// <summary>
 /// Initializes a new instance of the <see cref="ZMonitorEventArgs"/> class.
 /// </summary>
 /// <param name="monitor">The <see cref="ZMonitor"/> that triggered the event.</param>
 /// <param name="address">The peer address.</param>
 public ZMonitorEventArgs(ZMonitor monitor, ZMonitorEventData ed)
 {
     Monitor = monitor;
     Event   = ed;
 }