protected void StopConnections()
        {
            if (!Disposed)
            {
                //----- Stop Connections!
                BaseSocketConnection[] connections = GetSocketConnections();

                if (connections != null)
                {
                    FWaitConnectionsDisposing.Reset();

                    int loopSleep = 0;

                    foreach (BaseSocketConnection connection in connections)
                    {
                        connection.BeginDisconnect();
                        ThreadEx.LoopSleep(ref loopSleep);
                    }

                    if (connections.Length > 0)
                    {
                        FWaitConnectionsDisposing.WaitOne(10000, false);
                    }
                }
            }
        }
        /// <summary>
        /// Stop the host creators.
        /// </summary>
        protected void StopCreators()
        {
            //----- Stop Creators!
            BaseSocketConnectionCreator[] creators = GetSocketCreators();

            if (creators != null)
            {
                FWaitCreatorsDisposing.Reset();

                int loopCount = 0;

                foreach (BaseSocketConnectionCreator creator in creators)
                {
                    try
                    {
                        creator.Stop();
                    }
                    finally
                    {
                        RemoveCreator(creator);
                        creator.Dispose();

                        ThreadEx.LoopSleep(ref loopCount);
                    }
                }

                if (creators.Length > 0)
                {
                    FWaitCreatorsDisposing.WaitOne(10000, false);
                }
            }
        }
Ejemplo n.º 3
0
        internal override void BeginSendToAll(ServerSocketConnection connection, byte[] buffer, bool includeMe)
        {
            if (!Disposed)
            {
                BaseSocketConnection[] items = GetSocketConnections();

                if (items != null)
                {
                    int loopSleep = 0;

                    foreach (BaseSocketConnection cnn in items)
                    {
                        if (Disposed)
                        {
                            break;
                        }

                        try
                        {
                            if (includeMe || connection != cnn)
                            {
                                byte[] localBuffer = new byte[buffer.Length];
                                Buffer.BlockCopy(buffer, 0, localBuffer, 0, buffer.Length);

                                BeginSend(cnn, localBuffer, true);
                            }
                        }
                        finally
                        {
                            ThreadEx.LoopSleep(ref loopSleep);
                        }
                    }
                }
            }
        }
Ejemplo n.º 4
0
        public override void Start()
        {
            if (!Disposed)
            {
                FSocket = new System.Net.Sockets.Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
                FSocket.Bind(LocalEndPoint);
                FSocket.Listen(FBackLog * FAcceptThreads);

                //----- Begin accept new connections!
                int loopCount          = 0;
                SocketAsyncEventArgs e = null;

                for (int i = 1; i <= FAcceptThreads; i++)
                {
                    e            = new SocketAsyncEventArgs();
                    e.UserToken  = this;
                    e.Completed += new EventHandler <SocketAsyncEventArgs>(BeginAcceptCallbackAsync);

                    if (!FSocket.AcceptAsync(e))
                    {
                        BeginAcceptCallbackAsync(this, e);
                    }
                    ;

                    ThreadEx.LoopSleep(ref loopCount);
                }
            }
        }
        private void CheckSocketConnections(Object stateInfo)
        {
            if (!Disposed)
            {
                //----- Disable timer event!
                FIdleTimer.Change(Timeout.Infinite, Timeout.Infinite);

                try
                {
                    //----- Get connections!
                    BaseSocketConnection[] items = GetSocketConnections();

                    if (items != null)
                    {
                        int loopSleep = 0;

                        foreach (BaseSocketConnection cnn in items)
                        {
                            if (Disposed)
                            {
                                break;
                            }

                            try
                            {
                                if (cnn != null)
                                {
                                    //----- Check the idle timeout!
                                    if (DateTime.Now > (cnn.LastAction.AddMilliseconds(FIdleTimeOutValue)))
                                    {
                                        cnn.BeginDisconnect();
                                    }
                                }
                            }
                            finally
                            {
                                ThreadEx.LoopSleep(ref loopSleep);
                            }
                        }
                    }
                }
                finally
                {
                    if (!Disposed)
                    {
                        //----- Restart the timer event!
                        FIdleTimer.Change(FIdleCheckInterval, FIdleCheckInterval);
                    }
                }
            }
        }
Ejemplo n.º 6
0
        public override void Start()
        {
            if (!Disposed)
            {
                FSocket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
                FSocket.Bind(LocalEndPoint);
                FSocket.Listen(FBackLog);



                //----- Begin accept new connections!
                int loopCount = 0;

                for (int i = 1; i <= FAcceptThreads; i++)
                {
                    FSocket.BeginAccept(new AsyncCallback(BeginAcceptCallback), this);
                    ThreadEx.LoopSleep(ref loopCount);
                }
            }
        }
        /// <summary>
        /// Starts the base host.
        /// </summary>
        public void Start()
        {
            if (!Disposed)
            {
                int loopSleep = 0;

                foreach (BaseSocketConnectionCreator creator in FSocketCreators)
                {
                    creator.Start();
                    ThreadEx.LoopSleep(ref loopSleep);
                }

                if (FIdleTimer != null)
                {
                    FIdleTimer.Change(FIdleTimeOutValue, FIdleTimeOutValue);
                }

                Active = true;
            }
        }