English 中文(简体)
通过改变SLECONN来增加Windows CE的最大积压量?
原标题:Increase maximal backlog in Windows CE by changing SOMAXCONN?

我们重新开发“NET”CF 3.5应用程序,用于“Windows Embedded CE 6 plattform”。 我们重新努力使用一个小型网络服务器(HTTP 1.0)。 该网络应提供网络应用,并回应简单的教育、科学和技术要求。

Our implementation follows the pattern shown in this MSDN article: http://msdn.microsoft.com/en-us/library/aa446537.aspx. We use a TCP listening socket, async-callbacks in combination with BeginAccept, EndAccept, BeginRecieve and EndReceive.

An incoming connection on the listening port is handled by an asynchronous accept callback. (see http://msdn.microsoft.com/en-us/library/5bb431f9.aspx). By calling the EndAccept method, within this asynchronous accept callback, we tell the listening port to hand the connection to a new socket and free the port, so that new incoming connection requests can be accepted by the listening port. The already accepted request is processed in an own thread with (because it is processed in the async callback).

我们已经尝试尽量减少从BeginAccept到En Accept之间的时间。 由于在呼吁BeginAccept和EnAccept这段时期,即将提出的联系请求被列入积压的听众名单。 可以通过所谓的积压参数对电梯长度进行配置,而这一参数的配对率最高。 如果积压的询问已经用尽,新的电离线要求将在三维线之间被拒绝(Client/Browser作为回应收到一份区域数据表)。

现在,我们把这个问题推向了结,大多数现代浏览器,如:Edre、Acre、Sato,例如,使用最多15(或更多)的并行连接,把数据从服务器上载。 每一条同时连接的数量 东道方可在以下几个方面配置:组合——和;网络。 当装上一页时,浏览器根据需要装上的资源数量(如图像、javascript或cs文档)确定必要时可连接15条。

The .NET CF socket.listen method (see http://msdn.microsoft.com/en-us/library/system.net.sockets.socket.listen.aspx) allows the definition of a backlog number.
From our understanding we should have a backlog greater then 15 e.g. 20 or so, because all connection requests are triggered at the same time by the browser, so our small webserver got hit by 15 simultaneous connections requests. A too small backlog queue size, results in aborted TCP connections, because not all incoming connections can be queue until the listening socket can accept them all. In Firebug or Chrome, these requests are shown as "aborted". So we increased the backlog in our case by socket.listen(20) to 20 and hoped that everything would be fine and ready to withstand even the greediest browsers.

问题在于,单列车上的积压参数(名单上的)只字未提给SOMAXXCON(就我们而言,最多是5条连接)。 之后再设定一定数量,没有效果。 当浏览器建立16个同时的袖珍连接点时,有些会丢失,因为有些袖珍材料根本不适于5个积压点,而TCP连接则从网络服务器获得TCP-RST,有些资源在网页上缺失。

Is there any way to change the SOMAXXCON in Windows Embedded CE 6.0? (We re able to change the plattform image - utilize plattform builder). Or is there an error in our understanding of that matter?

We ve attached the source code that we re currently using:

public class StateObject
    {
        // Client  socket.
        public Socket workSocket = null;
        // Size of receive buffer.
        public const int BufferSize = 1024;
        // Receive buffer.
        public byte[] buffer = new byte[BufferSize];
        // Received data string.
        public StringBuilder sb = new StringBuilder();
    }

public void StartListening()
    {
       logger.Debug("Started Listening at : " + this.listeninghostIp + ":" + this.listeningport);
       IPEndPoint localEP = new IPEndPoint(IPAddress.Parse(this.listeninghostIp), Convert.ToInt32(this.listeningport));
       listener = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);

       listener.Bind(localEP);
       listener.Listen(10);
       ThreadPool.QueueUserWorkItem(new WaitCallback(CheckForConnections) );
    }

public void CheckForConnections()
    {
        try
        {
            logger.Debug("listening successfully started! Waiting for incoming connections...");
            listener.BeginAccept(new AsyncCallback(acceptCallback), listener);
          }
        catch (Exception ex)
        {
            logger.Error("Exception Occured while starting Listening : " + ex.Message.ToString());
        }
     }

private void acceptCallback(IAsyncResult ar)
    {
        try
        {

            Socket listener = (Socket)ar.AsyncState;
            listener.BeginAccept(new AsyncCallback(acceptCallback), listener);
            Socket handler = listener.EndAccept(ar);
            StateObject state = new StateObject();
            state.workSocket = handler;
            handler.BeginReceive(state.buffer, 0, StateObject.BufferSize, 0,
        new AsyncCallback(ReadCallback), state);

            logger.Debug("listening socket accepted connection...");

         }
        catch (Exception ex)
        {
            logger.Error("Error on acceptCallback. Error: " + ex.Message);
        }

public void ReadCallback(IAsyncResult ar)
    {
        String content = String.Empty;

        StateObject state = (StateObject)ar.AsyncState;
        Socket handler = state.workSocket;
        int bytesRead = handler.EndReceive(ar);

        if (bytesRead > 0)
        {
            state.sb.Append(Encoding.ASCII.GetString(
            state.buffer, 0, bytesRead));
        }
        ClientConnectionFactory.createConnection(ar.AsyncState);
 }
问题回答

我认为,你重新走上了错误的道路,你可以肯定地处理这一 s,而不改变积压的要求。

客户的要求出现在80港,但答复并没有回到80港的客户手中。 这就意味着,你可以使用超常的袖珍处理来接收请求,然后将其搁置起来并作出答复,这样,随后的请求就不必完全处理以前的请求。 我们在Padarn网络服务器中利用这一技术,在处理单一客户浏览器的多重要求或甚至多个同时客户的多重要求方面没有任何问题。





相关问题
Manually implementing high performance algorithms in .NET

As a learning experience I recently tried implementing Quicksort with 3 way partitioning in C#. Apart from needing to add an extra range check on the left/right variables before the recursive call, ...

Anyone feel like passing it forward?

I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...

How do I compare two decimals to 10 decimal places?

I m using decimal type (.net), and I want to see if two numbers are equal. But I only want to be accurate to 10 decimal places. For example take these three numbers. I want them all to be equal. 0....

Exception practices when creating a SynchronizationContext?

I m creating an STA version of the SynchronizationContext for use in Windows Workflow 4.0. I m wondering what to do about exceptions when Post-ing callbacks. The SynchronizationContext can be used ...

Show running instance in single instance application

I am building an application with C#. I managed to turn this into a single instance application by checking if the same process is already running. Process[] pname = Process.GetProcessesByName("...

How to combine DataTrigger and EventTrigger?

NOTE I have asked the related question (with an accepted answer): How to combine DataTrigger and Trigger? I think I need to combine an EventTrigger and a DataTrigger to achieve what I m after: when ...

热门标签