|
From: | Christoph Kronen |
Subject: | Re: [lwip-users] FreeRTOS / lwip multiple connections |
Date: | Tue, 30 Aug 2011 09:31:00 +0200 |
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 ); }
|
[Prev in Thread] | Current Thread | [Next in Thread] |