[En-Nut-Discussion] Browser Problems

Dave ethernut at wormfood.org
Tue Jun 7 16:55:58 CEST 2005


On Tue, 2005-06-07 at 11:46 +0200, Martin Buechling wrote:
> Hi,
>  
> I m using NutOS Ver 3.9.7.1 and have some problems to
> connect with Mozilla and Internet Explorer to the webserver.
>  
> Often some pictures on the html page or the stylesheet 
> won`t be loaded.
>  
> When I use the Opera Browser the problem won`t appear.
>  
> So I ve traced the communication on the ethernet. It seems
> that Mozilla and Opera try to use multiple connections to
> access the html page and Opera use only one.
>  
> If I increase the number of http threads(I use only one) this will fix
> 
> the problem (maybe for a while but I don`t know how many connections
> will be used!). But this will cause resource problems for my project.
>  
> Does somebody have an idea to solve this problem without increasing
> the number of http threads. 
>  
> Thanks a lot,
> Martin

Hi Martin,
   Here is a little snippet of code (modified slightly), that I'm using
on a project I'm working on. I don't know if this technique is fast
enough for http or not, but you may be able to refine it a little and
make it work. I'm sure there is a better way to do this, but it was all
I could think of on short notice. I call the main thread 'inetd' since
you can add more services to it, and make it work for other things. This
code works great for what I'm doing, and if you choose to use it, please
let me know if it works for you, and any modifications you make to
improve it.

-Dave

#define HTTPD_THREAD_LIMIT 5 /* or whatever you want to set it to */
char thread_count=0; // number of active server threads
char thread_ready=0; // flag to show that a socket is ready and waiting for a new connection

THREAD(inetd, arg)
{
        thread_ready=0; // not ready to handle incoming requests
        thread_count=0; // no threads running
        for(;;)
        {
                if(thread_ready<0)
                        thread_ready=0; // just in case 2 threads exit at the same time

                if(thread_count<HTTPD_THREAD_LIMIT && thread_ready<=0)
                {
                        thread_count++; // add one more thread to the total count
                        thread_ready++; // and show we are ready for incoming connections (almost)
                        NutThreadCreate("httpd", httpd, 0, 1384);
                }
                NutThreadYield();
        }
}

THREAD(httpd, arg)
{
    /* define your variables here, like sock and stream */

            sock = NutTcpCreateSocket();

            NutTcpAccept(sock, 80);
            // we do not pass this point, if we do not have a connection

            thread_ready--; // show we are not ready any more, since now we have a connection

            stream = _fdopen((int) sock, "r+b");

            /*
             * insert your code here, or call your function
             */

            fclose(stream);

            NutTcpCloseSocket(sock);

            thread_count--; // because this thread is about to die

            NutThreadExit(); // kill this thread since we are done here

    for(;;); // not needed, but keeps the compiler from bitching,
             // since it don't understand that NutThreadExit stops before we get here
}




More information about the En-Nut-Discussion mailing list