lwip-users
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [lwip-users] FreeRTOS / lwip multiple connections


From: vincent cui
Subject: Re: [lwip-users] FreeRTOS / lwip multiple connections
Date: Tue, 30 Aug 2011 14:04:58 +0000

Christoph:

 

Deal with mult-connection correctly, there is 3 way.

1.       Using raw api

2.       Using netconn API, but you have to create a  task to handle the HTTP request, then back to main thread to start accept next request.

3.       Using socket, you must set it with non-blocking and select it

 

I use the 3th method. The following code must be add to listen socket.

 

Int arg = 0x1;

lwip_ioctl(listhensocket, FIONBIO, &arg);

 

but I found that the listen socket cann’t work once it is set with nonblocking…

now, I remove it, it works … hope someone explain why

other, you also need call lwIP_shutdown and lowip_close to terminate socket in order to be avoid to CLOSE_WAIT .

 

Vincent Cui
Sr.Firmware Engineer
Mobile: +8613482482211
Tel: +86 21 34612525x6104
Fax: +86 21 34619770
E-Mail: address@hidden
Shanghai EnLogic Electric Technology Co., Ltd.
Address: 1104-1106, Building A, No.391, Guiping Road, Xuhui District, Shanghai, 200233
http://www.enlogic.com

 

From: lwip-users-bounces+address@hidden [mailto:lwip-users-bounces+address@hidden On Behalf Of Christoph Kronen
Sent: 2011
830 15:31
To: Mailing list for lwIP users
Subject: Re: [lwip-users] FreeRTOS / lwip multiple connections

 

Hi Vincent,

I changed the receiving process to be nonblocking, it wasn't like this in the first place. The code below has the same entry point as your "vHandler_HTTP(__pstNewConn);", it gets called when the connection is already established.

My problem was the following: I needed to check for new data received via Ethernet as well as new data from a Sendqueue in the same task. So netconn_recv() could not be blocking. In another topic, Simon Goldschmitt suggested to use lwIP 1.3.1 and to set "LWIP_SO_RCVTIMEO" to make netconn_recv() nonblocking. Unfortunately this crashed my Sam7X all the time.

So what I do now, is to peek into the receive mailbox and only if there is data I start the netconn_recv() process. Probably horrible programming, but it works for now.

Richard suggested to use semaphores on TCP events, that sounds much cleaner and I will definitely try to do it that way. But then I would need a FreeRTOS function like "WaitForMultipleObjects", since the Task needs to wake up for either a TCP event semaphore OR a new element in my SendQueue.

The CommandInterpreter from Richards socket example (thanks !) works for my Sam7X and I am in the process of rewriting it to have the same functionality as the code below.

@Vincent: You said your webserver is able to have multiple connections, could you give me a tip on that ? Do you have a small code example for "multiconnection socket" part ?

Thank you very much,

Christoph

static void vProcessSpeedtest( struct netconn *pxNetCon )
{
struct netbuf *pxRxBuffer;
struct pbuf *dummybuffer;
unsigned char *pcRxString;
xTCP_TXBuff * TXPointer = 0;
unsigned short usLength;
    while (1)
    {
        // Peek into the Receive mailbox
        if ( pdTRUE == xQueuePeek((pxNetCon->recvmbox),&dummybuffer,0))
        {
            pxRxBuffer = netconn_recv( pxNetCon );
            if( pxRxBuffer != NULL )
            {
                do
                {
                    netbuf_data( pxRxBuffer, ( void * ) &pcRxString, &usLength );
                  
                    //use the incoming data at this point

                }   while ( netbuf_next(pxRxBuffer) >=0 );
                netbuf_delete( pxRxBuffer );
            }
            else break;
        }
        // Check the Transmit Queue for Data and send it
        if ( xQueueReceive( xTXPointerQueue, &TXPointer, 0 ))
        {
            netconn_write(pxNetCon, TXPointer->data, TXPointer->length, NETCONN_NOFLAG);
            vFreeTCPBuffer(TXPointer);
        }
        vTaskDelay( 1 / portTICK_RATE_MS );
    }
    netconn_close( pxNetCon );
}



-------- Original-Nachricht --------
Datum: Tue, 30 Aug 2011 03:28:07 +0000
Von: vincent cui <address@hidden>
An: Mailing list for lwIP users <address@hidden>
Betreff: Re: [lwip-users] FreeRTOS / lwip multiple connections

Hi Chistoph:

 

 

 

 

 

 

The "lwIP Embedded Webserver Demo" is what I took as a starting point. I removed the webserver functionality, now I have a task that

 

 

  • checks for incoming data (nonblocking)

 

  • checks a Queue for outgoing data (nonblocking)

 

  • wait 1 ms (to prevent 100% cpu usage)

 

  • repeat :-)

 

 

 

the LwIP webserver demo code is following, I don’t know how do  you infer it is noblocking for incoming data and outgoing ….

 

 

Where to wait 1 ms .

 

 

 

 

void  WebServer_Handler(void *pdata)

 

 

{

 

 

         struct netconn  *__pstConn, *__pstNewConn;

 

 

                                                       

 

 

    __pstConn = netconn_new(NETCONN_TCP);

 

 

    netconn_bind(__pstConn, NULL,80);

 

 

    netconn_listen(__pstConn);

 

 

 

 

         for(;;)

 

 

         {

 

 

                   __pstNewConn = netconn_accept(__pstConn);

 

 

                  

 

 

                   if(__pstNewConn != NULL)

 

 

                   {                          

 

 

                            vHandler_HTTP(__pstNewConn);

 

 

                            while(netconn_delete(__pstNewConn) != ERR_OK)

 

 

                            {

 

 

                                     vTaskDelay(10);

 

 

                            }

 

 

                   }

 

 

    }

 

 

}

 

 

 

 

 

 

 

 

Vincent Cui
Sr.Firmware Engineer
Mobile: +8613482482211
Tel: +86 21 34612525x6104
Fax: +86 21 34619770
E-Mail: address@hidden

Shanghai EnLogic Electric Technology Co., Ltd.
Address: 1104-1106, Building A, No.391, Guiping Road, Xuhui District, Shanghai, 200233
http://www.enlogic.com

 

 

 

 

 

From: lwip-users-bounces+address@hidden [mailto:lwip-users-bounces+address@hidden On Behalf Of Christoph Kronen
Sent: 2011
829 0:48
To: address@hidden
Subject: [lwip-users] FreeRTOS / lwip multiple connections

 

 

 

 

Hi all,

I am using FreeRTOS 7.0.1 on a Sam7X512 and upgraded the contributed port lwIP 1.3.0 to 1.3.2.

The "lwIP Embedded Webserver Demo" is what I took as a starting point. I removed the webserver functionality, now I have a task that

 

 

  • checks for incoming data (nonblocking)

 

  • checks a Queue for outgoing data (nonblocking)

 

  • wait 1 ms (to prevent 100% cpu usage)

 

  • repeat :-)

 


This works pretty well, I get around 1400 kbyte/s RX and TX.
Now to my question: Is it possible/difficult/easy to transform this functionality to accept multiple connections on the same port ? At the moment I am using the netconn API, so I guess I have to switch to the Socket API ?

I read through Richards thread on his "FreeRTOS/lwip Win32 simulator" project and it sounds as if it is quite difficult to have multiple connections in a multithreaded environment. Unfortunately I could not find other helpful topics or contributed examples.

I am rather new to FreeRTOS and lwIP, so please excuse me if I am missing something obvious :-)

Please give me some comments / suggestions / tips / pushes into the right direction.

Thank you very much !

Christoph

 

 


reply via email to

[Prev in Thread] Current Thread [Next in Thread]