Esempio n. 1
0
        /// <summary>
        /// Starts proccessiong incoming connections (Accepts and queues connections).
        /// </summary>
        private void StartProcCons()
        {
            try{
                CircleCollection <IPBindInfo> binds = new CircleCollection <IPBindInfo>();
                foreach (IPBindInfo bindInfo in m_pBindInfo)
                {
                    Socket s = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
                    s.Bind(new IPEndPoint(bindInfo.IP, bindInfo.Port));
                    s.Listen(500);

                    bindInfo.Tag = s;
                    binds.Add(bindInfo);
                }

                // Accept connections and queue them
                while (m_Running)
                {
                    // We have reached maximum connection limit
                    if (m_pSessions.Count > m_MaxConnections)
                    {
                        // Wait while some active connectins are closed
                        while (m_pSessions.Count > m_MaxConnections)
                        {
                            Thread.Sleep(100);
                        }
                    }

                    // Get incomong connection
                    IPBindInfo bindInfo = binds.Next();

                    // There is waiting connection
                    if (m_Running && ((Socket)bindInfo.Tag).Poll(0, SelectMode.SelectRead))
                    {
                        // Accept incoming connection
                        Socket s = ((Socket)bindInfo.Tag).Accept();

                        // Add session to queue
                        lock (m_pQueuedConnections){
                            m_pQueuedConnections.Enqueue(new QueuedConnection(s, bindInfo));
                        }
                    }

                    Thread.Sleep(2);
                }
            }
            catch (SocketException x) {
                // Socket listening stopped, happens when StopServer is called.
                // We need just skip this error.
                if (x.ErrorCode == 10004)
                {
                }
                else
                {
                    OnSysError("WE MUST NEVER REACH HERE !!! StartProcCons:", x);
                }
            }
            catch (Exception x) {
                OnSysError("WE MUST NEVER REACH HERE !!! StartProcCons:", x);
            }
        }
Esempio n. 2
0
 /// <summary>
 /// Default constructor.
 /// </summary>
 /// <param name="sessionID">Session ID.</param>
 /// <param name="socket">Server connected socket.</param>
 /// <param name="bindInfo">BindInfo what accepted socket.</param>
 /// <param name="server">Reference to server.</param>
 public SocketServerSession(string sessionID,SocketEx socket,IPBindInfo bindInfo,SocketServer server)
 {
     m_SessionID = sessionID;
     m_pSocket   = socket;
     m_pBindInfo = bindInfo;
     m_pServer   = server;
                 
     m_SessionStartTime = DateTime.Now;
 }
Esempio n. 3
0
        /// <summary>
        /// Default constructor.
        /// </summary>
        /// <param name="sessionID">Session ID.</param>
        /// <param name="socket">Server connected socket.</param>
        /// <param name="bindInfo">BindInfo what accepted socket.</param>
        /// <param name="server">Reference to server.</param>
        public SocketServerSession(string sessionID, SocketEx socket, IPBindInfo bindInfo, SocketServer server)
        {
            m_SessionID = sessionID;
            m_pSocket   = socket;
            m_pBindInfo = bindInfo;
            m_pServer   = server;

            m_SessionStartTime = DateTime.Now;
        }
Esempio n. 4
0
        /// <summary>
        /// Compares the current instance with another object of the same type.
        /// </summary>
        /// <param name="obj">An object to compare with this instance.</param>
        /// <returns>Returns true if two objects are equal.</returns>
        public override bool Equals(object obj)
        {
            if (obj == null)
            {
                return(false);
            }
            if (!(obj is IPBindInfo))
            {
                return(false);
            }

            IPBindInfo bInfo = (IPBindInfo)obj;

            if (bInfo.HostName != m_HostName)
            {
                return(false);
            }
            if (bInfo.Protocol != m_Protocol)
            {
                return(false);
            }
            if (!bInfo.EndPoint.Equals(m_pEndPoint))
            {
                return(false);
            }
            if (bInfo.SslMode != m_SslMode)
            {
                return(false);
            }
            if (!X509Certificate.Equals(bInfo.Certificate, m_pCertificate))
            {
                return(false);
            }

            return(true);
        }
Esempio n. 5
0
 /// <summary>
 /// Default constructor.
 /// </summary>
 /// <param name="socket">Socket.</param>
 /// <param name="bindInfo">Bind info.</param>
 public QueuedConnection(Socket socket,IPBindInfo bindInfo)
 {
     m_pSocket   = socket;
     m_pBindInfo = bindInfo;
 }
Esempio n. 6
0
		/// <summary>
		/// Initialize and start new session here. Session isn't added to session list automatically, 
		/// session must add itself to server session list by calling AddSession().
		/// </summary>
		/// <param name="socket">Connected client socket.</param>
        /// <param name="bindInfo">BindInfo what accepted socket.</param>
		protected virtual void InitNewSession(Socket socket,IPBindInfo bindInfo)
		{
		}
Esempio n. 7
0
 /// <summary>
 /// Default constructor.
 /// </summary>
 /// <param name="socket">Socket.</param>
 /// <param name="bindInfo">Bind info.</param>
 public QueuedConnection(Socket socket, IPBindInfo bindInfo)
 {
     m_pSocket   = socket;
     m_pBindInfo = bindInfo;
 }
Esempio n. 8
0
 /// <summary>
 /// Initialize and start new session here. Session isn't added to session list automatically,
 /// session must add itself to server session list by calling AddSession().
 /// </summary>
 /// <param name="socket">Connected client socket.</param>
 /// <param name="bindInfo">BindInfo what accepted socket.</param>
 protected virtual void InitNewSession(Socket socket, IPBindInfo bindInfo)
 {
 }