lwip-users
[Top][All Lists]
Advanced

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

[lwip-users] tcp connection problem


From: Janusz U.
Subject: [lwip-users] tcp connection problem
Date: Thu, 31 Aug 2006 14:58:42 +0200

hello,
 
I am using FreeRTOS  4.1.0 - OS, lwIP 1.1.1 and ppp. PPP, IP, ICMP (ping) work fine and is stable I hope.
I have problem with TCP. I make http server. Ather telnet ip 80 connection is made (TCP_DEBUG: TCP connection established ...->80) and then OS crashes. I did analise => OS is halt on TCP_EVENT_ACCEPT(pcb, ERR_OK, err); in tcp_in.c (tcp_process). Have you any ideas?
 
My server code:
//--------------------------------------------------------------- inicjalizacja lwIP ---------------------------------------------
 
/*void tcpip_init_done(void * arg)
{
 sys_sem_t *sem = arg;
 sys_sem_signal(*sem);
} */
 
void vlwIPInit( void )
{
// sys_sem_t sem;
 
    /* Initialize lwIP and its interface layer. */
 sys_init();
 mem_init();        
 memp_init();
 pbuf_init();
 netif_init();
 ip_init();   // wykonywane takze przez tcpip_init
 tcpip_init( NULL, NULL ); // bez samafory
 
/*   sem = sys_sem_new(0);
   tcpip_init(tcpip_init_done, &sem);
   sys_sem_wait(sem);
   sys_sem_free(sem);  */
}
 
//------------------------------------------------------------ serwer http ---------------------------------------------------------------
/*------------------------------------------------------------*/
/* The size of the buffer in which the dynamic WEB page is created. */
#define webMAX_PAGE_SIZE 2048
 
/* Standard GET response. */
#define webHTTP_OK "HTTP/1.0 200 OK\r\nContent-type: text/html\r\n\r\n"
 
/* The port on which we listen. */
#define webHTTP_PORT  ( 80 )
 
/* Delay on close error. */
#define webSHORT_DELAY  ( 10 )
 
/* Format of the dynamic page that is returned on each connection. */
#define webHTML_START \
"<html>\
<head>\
</head>\
<BODY >\r\nPage Hits = "
 
#define webHTML_END \
"\r\n</pre>\
\r\n</BODY>\
</html>"
 
/*
 * Process an incoming connection on port 80.
 *
 * This simply checks to see if the incoming data contains a GET request, and
 * if so sends back a single dynamically created page.  The connection is then
 * closed.  A more complete implementation could create a task for each
 * connection.
 */
static void vProcessConnection( struct netconn *pxNetCon );
 
/*------------------------------------------------------------*/
 
static void vProcessConnection( struct netconn *pxNetCon )
{
 static portCHAR cDynamicPage[ webMAX_PAGE_SIZE ], cPageHits[ 11 ];
 struct netbuf *pxRxBuffer;
 portCHAR *pcRxString;
 unsigned portSHORT usLength;
 static unsigned portLONG ulPageHits = 0;
 
 /* We expect to immediately get data. */
 pxRxBuffer = netconn_recv( pxNetCon );
 
 if( pxRxBuffer != NULL )
 {
  /* Where is the data? */
  netbuf_data( pxRxBuffer, ( void * ) &pcRxString, &usLength );   
 
  /* Is this a GET?  We don't handle anything else. */
  if( !strncmp( pcRxString, "GET", 3 ) )
  {
   pcRxString = cDynamicPage;
 
   /* Update the hit count. */
   ulPageHits++;
   sprintf( cPageHits, "%lu", ulPageHits );
 
   /* Write out the HTTP OK header. */
            netconn_write(pxNetCon, webHTTP_OK, (u16_t)strlen( webHTTP_OK ), NETCONN_COPY );
 
   /* Generate the dynamic page...
 
   ... First the page header. */
   strcpy( cDynamicPage, webHTML_START );
   /* ... Then the hit count... */
   strcat( cDynamicPage, cPageHits );
   strcat( cDynamicPage, "<p><pre>Task          State  Priority  Stack #<br>************************************************<br>" );
   /* ... Then the list of tasks and their status... */
   vTaskList( ( signed portCHAR * ) cDynamicPage + strlen( cDynamicPage ) ); 
   /* ... Finally the page footer. */
   strcat( cDynamicPage, webHTML_END );
 
   /* Write out the dynamically generated page. */
   netconn_write(pxNetCon, cDynamicPage, (u16_t)strlen( cDynamicPage ), NETCONN_COPY );
  }
 
  netbuf_delete( pxRxBuffer );
 }
 
 netconn_close( pxNetCon );
}
/*------------------------------------------------------------*/
#define mainWEBSERVER_PRIORITY      ( tskIDLE_PRIORITY + 2 )
 
void vBasicWEBServer( void *pvParameters )
{
 struct netconn *pxHTTPListener, *pxNewConnection;
 
 /* Create a new tcp connection handle */
 
 kprintf("http serv lev 0\n");
  pxHTTPListener = netconn_new( NETCONN_TCP );
 kprintf("http serv lev 1\n");
 netconn_bind(pxHTTPListener, NULL, webHTTP_PORT );
 kprintf("http serv lev 2\n");
 netconn_listen( pxHTTPListener );
 kprintf("http serv lev 3\n");
 
 /* Loop forever */
 for( ;; )
 {
  kprintf("http serv lev 4\n");
  /* Wait for connection. */
  pxNewConnection = netconn_accept(pxHTTPListener); //tutaj watek sie zatrzymuje oczekujac na polaczenie
  
  kprintf("http serv lev 5\n");
 
  if(pxNewConnection != NULL)
  {
   kprintf("http serv lev 6\n");
   /* Service connection. */
   vProcessConnection( pxNewConnection );
   while( netconn_delete( pxNewConnection ) != ERR_OK )
   {
    vTaskDelay( webSHORT_DELAY );
   }
  }
 }
}
best regards
Janusz
 

reply via email to

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