Ejemplo n.º 1
0
        private void runListener()
        {
            while (m_isOpen && m_port >= 0)
            {
                try
                {
                    if (listener.Pending())
                    {
                        TcpClient socket = listener.AcceptTcpClient();
                        TokenUserCollectionTransportSpace conn = new TokenUserCollectionTransportSpace(socket, m_encoding);

                        if (OnConnect != null)
                        {
                            lock (activeThreadsLock)
                            {
                                activeThreads++;
                            }
                            conn.CallbackThread = new Thread(() =>
                            {
                                OnConnect(conn);
                            });
                            conn.CallbackThread.Start();
                        }

                        lock (connections)
                        {
                            connections.Add(conn);
                        }
                    }
                    else
                    {
                        Thread.Sleep(m_idleTime);
                    }
                }
                catch (ThreadInterruptedException) { } //thread is interrupted when we quit
                catch (Exception e)
                {
                    if (m_isOpen)
                    {
                        OnError?.Invoke(this, e);
                    }
                }
            }
        }
Ejemplo n.º 2
0
        private bool processConnection(TokenUserCollectionTransportSpace conn)
        {
            bool moreWork = conn.processOutgoing(m_maxSendAttempts);

            if (OnDataAvailable == null || activeThreads >= m_maxCallbackThreads || conn.Socket.Available <= 0)
            {
                return(moreWork);
            }
            lock (activeThreadsLock)
            {
                activeThreads++;
            }
            conn.CallbackThread = new Thread(() =>
            {
                OnDataAvailable(conn);
            });
            conn.CallbackThread.Start();
            Thread.Yield();
            return(moreWork);
        }
Ejemplo n.º 3
0
        private bool processConnection(TokenUserCollectionTransportSpace conn)
        {
            bool moreWork = conn.processOutgoing(m_maxSendAttempts);

            if (OnDataAvailable == null || activeThreads >= m_maxCallbackThreads || conn.Socket.Available <= 0)
                return moreWork;
            lock (activeThreadsLock)
            {
                activeThreads++;
            }
            conn.CallbackThread = new Thread(() =>
            {
                OnDataAvailable(conn);
            });
            conn.CallbackThread.Start();
            Thread.Yield();
            return moreWork;
        }
Ejemplo n.º 4
0
        private void runListener()
        {
            while (m_isOpen && m_port >= 0)
            {
                try
                {
                    if (listener.Pending())
                    {
                        TcpClient socket = listener.AcceptTcpClient();
                        TokenUserCollectionTransportSpace conn = new TokenUserCollectionTransportSpace(socket, m_encoding);

                        if (OnConnect != null)
                        {
                            lock (activeThreadsLock)
                            {
                                activeThreads++;
                            }
                            conn.CallbackThread = new Thread(() =>
                            {
                                OnConnect(conn);
                            });
                            conn.CallbackThread.Start();
                        }

                        lock (connections)
                        {
                            connections.Add(conn);
                        }
                    }
                    else
                    {
                        Thread.Sleep(m_idleTime);
                    }
                }
                catch (ThreadInterruptedException) { } //thread is interrupted when we quit
                catch (Exception e)
                {
                    if (m_isOpen)
                    {
                        OnError?.Invoke(this, e);
                    }
                }
            }
        }