Wrap the System.Threading.Timer with useful functions and state information
Inheritance: IDisposable
Example #1
0
        private void onConnectionDropped(Connection conn, Connection.DropReason reason)
        {
#if DEBUG
            EDB.WriteLine("TransportPublisherLink: onConnectionDropped -- " + reason);
#endif
            if (dropping || conn != connection)
            {
                return;
            }
            if (reason == Connection.DropReason.TransportDisconnect)
            {
                needs_retry = true;
                next_retry  = DateTime.Now.Add(retry_period);
                if (retry_timer == null)
                {
                    retry_timer = ROS.timer_manager.StartTimer(onRetryTimer, 100);
                }
                else
                {
                    retry_timer.Restart();
                }
            }
            else
            {
                if (reason == Connection.DropReason.HeaderError)
                {
                    EDB.WriteLine("SOMETHING BE WRONG WITH THE HEADER FOR: " +
                                  (parent != null ? parent.name : "unknown"));
                }
                drop();
            }
        }
Example #2
0
        /// <summary>
        ///     Wrap a timer a with added functionality, and make sure it dies with this TimerManager
        ///     This DOES NOT START IT.
        /// </summary>
        /// <param name="cb">
        ///     The callback of the wrapped timer
        /// </param>
        /// <param name="d">
        ///     The delay it should have
        /// </param>
        /// <param name="p">
        ///     The period it should have
        /// </param>
        public WrappedTimer StartTimer(TimerCallback cb, int d = Timeout.Infinite, int p = Timeout.Infinite)
        {
            WrappedTimer wt = MakeTimer(cb, d, p);

            wt.Start();
            return(wt);
        }
Example #3
0
        /// <summary>
        ///     Wrap and start timer a with added functionality, and make sure it dies with this TimerManager
        ///     This DOES NOT START IT.
        /// </summary>
        /// <param name="cb">
        ///     The callback of the wrapped timer
        /// </param>
        /// <param name="d">
        ///     The delay it should have
        /// </param>
        /// <param name="p">
        ///     The period it should have
        /// </param>
        public WrappedTimer MakeTimer(TimerCallback cb, int d = Timeout.Infinite, int p = Timeout.Infinite)
        {
            WrappedTimer wt = new WrappedTimer(cb, d, p);

            MakeTimer(wt);
            return(wt);
        }
Example #4
0
 /// <summary>
 ///     Add a wrapped timer to the hashset
 /// </summary>
 /// <param name="t">the wrapped timer</param>
 public void MakeTimer(WrappedTimer t)
 {
     lock (heardof)
     {
         if (heardof.Contains(t))
         {
             throw new Exception("The same timer cannot be tracked twice");
         }
         heardof.Add(t);
     }
 }
Example #5
0
 /// <summary>
 ///     Stop tracking a timer, and kill it
 /// </summary>
 /// <param name="t">The timer to forget and kill</param>
 public void RemoveTimer(ref WrappedTimer t)
 {
     lock (heardof)
     {
         if (heardof.Contains(t))
         {
             heardof.Remove(t);
         }
     }
     t.Dispose();
     t = null;
 }
Example #6
0
        public void Start()
        {
            PollManager.Instance.addPollThreadListener(removeDroppedConnections);

#if TCPSERVER
            tcpserver_transport = new TcpListener(IPAddress.Any, network.tcpros_server_port);
            tcpserver_transport.Start(10);
            acceptor = ROS.timer_manager.StartTimer(CheckAndAccept, 100, 100);
#else
            tcpserver_transport = new TcpTransport(PollManager.Instance.poll_set);
            tcpserver_transport.listen(network.tcpros_server_port, 10, (t) => {
                tcpRosAcceptConnection(t.accept());
            });
#endif
        }
Example #7
0
        public void Start()
        {
            poll_manager = PollManager.Instance;
            poll_conn    = removeDroppedConnections;
            poll_manager.addPollThreadListener(poll_conn);

#if TCPSERVER
            tcpserver_transport = new TcpListener(IPAddress.Any, network.tcpros_server_port);
            tcpserver_transport.Start(10);
            acceptor = ROS.timer_manager.StartTimer(CheckAndAccept, 100, 100);
#else
            tcpserver_transport = new TcpTransport(new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp), poll_manager.poll_set);
            new Thread(() =>
            {
                while (true)
                {
                    bool diedinfire;
                    lock (fierydeathmutex)
                        diedinfire = _diaf;
                    if (diedinfire)
                    {
                        break;
                    }
                    TcpTransport newguy = tcpserver_transport.accept();
                    if (newguy != null)
                    {
                        tcpRosAcceptConnection(newguy);
                    }
                    else
                    {
                        Thread.Sleep(90);
                    }
                    Thread.Sleep(10);
                }
            }).Start();
#endif
        }
Example #8
0
 /// <summary>
 ///     Add a wrapped timer to the hashset
 /// </summary>
 /// <param name="t">the wrapped timer</param>
 public void MakeTimer(WrappedTimer t)
 {
     lock (heardof)
     {
         if (heardof.Contains(t))
             throw new Exception("The same timer cannot be tracked twice");
         heardof.Add(t);
     }
 }
Example #9
0
 /// <summary>
 ///     Wrap and start timer a with added functionality, and make sure it dies with this TimerManager
 ///     This DOES NOT START IT.
 /// </summary>
 /// <param name="cb">
 ///     The callback of the wrapped timer
 /// </param>
 /// <param name="d">
 ///     The delay it should have
 /// </param>
 /// <param name="p">
 ///     The period it should have
 /// </param>
 public WrappedTimer MakeTimer(TimerCallback cb, int d = Timeout.Infinite, int p = Timeout.Infinite)
 {
     WrappedTimer wt = new WrappedTimer(cb, d, p);
     MakeTimer(wt);
     return wt;
 }
Example #10
0
 /// <summary>
 ///     Stop tracking a timer, and kill it
 /// </summary>
 /// <param name="t">The timer to forget and kill</param>
 public void RemoveTimer(ref WrappedTimer t)
 {
     lock (heardof)
     {
         if (heardof.Contains(t))
             heardof.Remove(t);
     }
     t.Dispose();
     t = null;
 }