Example #1
0
        /// <summary>
        ///     Initializes the base socket.
        /// </summary>
        /// <param name="socket">The underlying ZeroMQ socket.</param>
        /// <param name="heartbeatInterval">Heartbeat interval.</param>
        protected SocketBase(NetMQSocket socket, TimeSpan heartbeatInterval)
        {
            HeartbeatInterval = heartbeatInterval;
            Channels          = new Dictionary <object, Channel>();
            Closed            = false;
            Socket            = socket;
            TimerPoller       = new TimerPoller();

            Proactor = new NetMQProactor(socket, ReceiveMessage);
            TimerPoller.Start();
        }
Example #2
0
        /// <summary>
        ///     Initializes the base socket.
        /// </summary>
        /// <param name="socket">The underlying ZeroMQ socket.</param>
        /// <param name="heartbeatInterval">Heartbeat interval.</param>
        protected SocketBase(NetMQSocket socket, TimeSpan heartbeatInterval)
        {
            HeartbeatInterval = heartbeatInterval;

            Channels    = new Dictionary <object, Channel>(Config.MessageIdComparer);
            Closed      = false;
            Socket      = socket;
            TimerPoller = new TimerPoller();

            Poller = new NetMQPoller {
                Socket
            };
            Socket.ReceiveReady += ReceiveMessage;

            TimerPoller.Start();
            Poller.RunAsync();
        }
Example #3
0
        /// <summary>
        ///     Terminates all active connections, sends out all remaining data and closes the socket.
        /// </summary>
        /// <param name="linger">Time to wait for the connections to close before forcefully terminating the socket.</param>
        public void Close(TimeSpan linger)
        {
            if (Closed)
            {
                return; // Do not raise an exception
            }
            if (linger != TimeSpan.Zero)
            {
                Socket.Options.Linger = linger;
            }

            Socket.ReceiveReady -= ReceiveMessage;
            TimerPoller.Stop();
            Poller.Stop();
            Socket.Close();
            foreach (var pair in Channels)
            {
                pair.Value.Destroy();
            }
            Channels.Clear();
            Closed = true;
        }
Example #4
0
 private void ReleaseUnmanagedResources()
 {
     TimerPoller.Stop();
     Close(TimeSpan.Zero);
 }