lwip-users
[Top][All Lists]
Advanced

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

Re: [lwip-users] lwip 1.2.0 + freeRTOS


From: Sirjee Rooplall
Subject: Re: [lwip-users] lwip 1.2.0 + freeRTOS
Date: Mon, 25 Jan 2010 14:32:15 +0200

Hi Simon,

I am new to LWIP, so I copied that code from an example I have seen.

I removed the sleep and I have removed the access to the internal pcb, and only rely on the API now.

The problem I am explaining, seems to also exist in LWIP 1.3.0, as I have seen in some of the recent lwip archives.

Another thing:
Because I am connecting through a PPP->GPRS interface the possibility exists where someone removes the antenna and the connection longer exists, however the user can trigger a server connection externally through a push button, which will attempt to perform a neconn_connect which blocks and returns with ERR_ABRT(-3), how do I handle this senario without crashing the stack. At the moment, I keep trying every 30 seconds, and eventually I cause the stack to crash with too many netconn_connect without a physical connection available.

What should my application code do in this case.

struct netconn* ConnectProcess( U16 connPortNo)
{
U8 ip_addrTemp[4];
 struct ip_addr ipaddrToConnectTo;
err_t error;

ipStr2ipAddr((U8 *)&ip_addrTemp[0], (U8 *)&DestIP[0]);
IP4_ADDR(&ipaddrToConnectTo, ip_addrTemp[0], ip_addrTemp[1], ip_addrTemp[2], ip_addrTemp[3]);

  if (pxSeverConnectionHandle==NULL)
  {
    //we make a connection
#ifdef XCOM_DEBUG
     SendDebugString("ConnectProcess->Calling netconn_new");
#endif
   pxSeverConnectionHandle = netconn_new(NETCONN_TCP);
  }

#ifdef XCOM_DEBUG
  SendDebugString("ConnectProcess->Calling netconn_connect");
#endif
error=netconn_connect(pxSeverConnectionHandle, &ipaddrToConnectTo, connPortNo);
  switch (error)
  {
   case ERR_VAL:
#ifdef XCOM_DEBUG
          SendDebugString("ConnectProcess->ERR_VAL=%d", error);
#endif
     return(NULL);
    break;
   case ERR_MEM:
#ifdef XCOM_DEBUG
          SendDebugString("ConnectProcess->ERR_MEM=%d", error);
#endif
     return(NULL);
    break;
   case ERR_OK:
#ifdef XCOM_DEBUG
          SendDebugString("ConnectProcess->ERR_OK=%d, CONNECTED", error);
#endif
    break;
    case ERR_ABRT:
#ifdef XCOM_DEBUG
          SendDebugString("ConnectProcess->ERR_ABRT=%d, ABORTED", error);
#endif
          return(NULL);
     break;
   default :
#ifdef XCOM_DEBUG
          SendDebugString("ConnectProcess->Unhandled Error=%d", error);
#endif
    return(NULL);
    break;
    }
   return pxSeverConnectionHandle;
}


void CloseConnection(void)
{
 err_count = 4;
 while( netconn_close( pxSeverConnectionHandle ) != ERR_OK )
 {
    if (--err_count == 0) break;
    vTaskDelay( 10 );
 }
 err_count = 4;

 err_count = 4;
 while( netconn_delete( pxSeverConnectionHandle ) != ERR_OK )
 {
    if (--err_count == 0) break;
    vTaskDelay( 10 );
 }

 vPortEnterCritical();
 pxSeverConnectionHandle = NULL;
 vPortExitCritical();
}

Kind Regards, Sirjee Rooplall Figment Design laboratories (Pty) Ltd mailto: address@hidden Mobile: +27 (0)83 230 8466 ----- Original Message ----- From: "Simon Goldschmidt" <address@hidden>
To: "Mailing list for lwIP users" <address@hidden>
Sent: Monday, January 25, 2010 2:09 PM
Subject: Re: [lwip-users] lwip 1.2.0 + freeRTOS


You're using an old version, added an extra sleep and violate api layering. Any reasons for that? ;-)

Sirjee Rooplall wrote:
Hi, I am using lwip 1.2.0 under freeRTOS, I am also using PPP + external
modem to establish a PPP connection to a server over GPRS.

Using such an old version is not recommended and makes it hard to track down bugs as they might already have been fixed by now. 1.2.0 is over three years old by now.

All works well, provided I can establish a connection to the server and
the connection is closed.

If for some reason the connection is not closed, i.e the TCP/IP stack does
not get to the FIN_2 closing state, all hell breaks loose and my system
crashes when I attempt to re-connect to the server.

I s there an elegant way to remove the connection witout causing future
failure.

To connect I use:

conn = netconn_new(NETCONN_TCP);
netconn_connect(conn, IP, PORT);
vTaskDelay(100); // wait 100ms

What's that for? (I mean, I could have guessed the comment if it wasn't there, but why sleep?)

Then I check the state of the pcb:
if (conn->pcb.tcp->state == ESTABLISHED)

This is a total no-go! Don't ever (I really mean never!) access the pcb from your netconn application code. The netconn API is exists for you not having to worry about the raw API. Just because you have the struct definition doesn't mean you know what you are doing (see below).

{
  conn->state = NETCONN_CONNECT;

And where did you get that from? Please, don't "mess around" with internal netconn members. In this case, you tell the netconn it is in state 'connecting' after netconn_connect has returned (which means successfully or not) which no doubt leads to problems!

Please have a look at other (example-) netconn apps (you can find some by downloading the contrib module from cvs) and make sure you use the api correctly!

Simon
--
Jetzt kostenlos herunterladen: Internet Explorer 8 und Mozilla Firefox 3.5 -
sicherer, schneller und einfacher! http://portal.gmx.net/de/go/atbrowser


_______________________________________________
lwip-users mailing list
address@hidden
http://lists.nongnu.org/mailman/listinfo/lwip-users






reply via email to

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