예제 #1
0
        public void StartListening(int incomingBuffer = 1000)
        {
            String prt = m_port.ToString();

            SByte[] sprt = new SByte[prt.Length];
            for (int i = 0; i < prt.Length; ++i)
            {
                sprt[i] = (sbyte)prt[i];
            }

            unsafe
            {
                fixed(SByte *ppp = sprt)
                {
                    m_sock = new TCPSocket(ppp);
                }
            }

            ThreadPool.SetMaxThreads(40, 40);
            ThreadPool.SetMinThreads(40, 40);

            if (false == m_sock.InError())
            {
                m_sock.StartListening();
            }

            while (m_sock.Accept())
            {
                if (true == m_sock.InError())
                {
                    continue;
                }

                UInt32 handler = m_sock.ReturnClientSocket();

                var ThreadMain = System.Diagnostics.Stopwatch.StartNew();
                //ThreadPool.QueueUserWorkItem(Socket.StarterFunction, handler);
                ThreadPool.QueueUserWorkItem(HttpStreamReader.ListenSocketHandler, handler);
                ThreadMain.Stop();
            }

            // Create a TCP/IP socket.
            //m_listeningSocket = new SystemSocket(m_ipAddress.AddressFamily, SocketType.Stream, ProtocolType.Tcp);

            // Bind the socket to the local endpoint and listen for incoming connections.

            /*try
             * {
             *  m_listeningSocket.Bind(m_ipEndPoint);
             *  m_listeningSocket.Listen(incomingBuffer);
             *
             *  ThreadPool.SetMaxThreads(40, 40);
             *  ThreadPool.SetMinThreads(40, 40);
             *
             *  // Start listening for connections.
             *  while (true)
             *  {
             *      // Program is suspended while waiting for an incoming connection.
             *      SystemSocket handler = m_listeningSocket.Accept();
             *      System.Console.WriteLine(handler.Handle);
             *
             *      var ThreadMain = System.Diagnostics.Stopwatch.StartNew();
             *      //ThreadPool.QueueUserWorkItem(Socket.StarterFunction, handler);
             *      ThreadPool.QueueUserWorkItem(HttpStreamReader.ListenSocketHandler, handler);
             *      ThreadMain.Stop();
             *      System.Console.WriteLine("Request Time " + ThreadMain.ElapsedMilliseconds);
             *
             *      //log
             *      //EndPoint endpt = handler.LocalEndPoint;
             *      //long result = IPGlobalProperties.GetIPGlobalProperties()
             *      //            .GetTcpIPv4Statistics()
             *      //            .CurrentConnections;
             *      //System.Console.WriteLine(result);
             *
             *  }
             *
             * }
             * catch (Exception e)
             * {
             *  Console.WriteLine(e.ToString());
             *  Environment.Exit(-1);
             * }*/
        }