lwip-users
[Top][All Lists]
Advanced

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

Re: [lwip-users] ERR_CLSD error after a fixed number of read/write


From: Damiano Grechi
Subject: Re: [lwip-users] ERR_CLSD error after a fixed number of read/write
Date: Thu, 20 Oct 2011 09:59:55 +0200

Ok,
 
I found a bug in the client. The server works correctly.

On Tue, Oct 11, 2011 at 4:51 PM, Damiano Grechi <address@hidden> wrote:
Hi,
 
I'm using LwIP and FreeRTOS to develope a simple client/server application with STM3220G board.
The client (running on PC) connects to server and then sends a message every 2 seconds.
The server (running on STM3220G board) processes the incoming message and replies with an appropriate response.
 
After a fixed number of read/write, the server netconn_recv() returns NULL and the connection error is equal to ERR_CLSD. It seems a memory allocation problem.
 
Unlike what has been done in the examples, after the netconn_accept() the connection is kept open: the server doesn't call netconn_close() and netconn_delete() after netconn_write(). Is this allowed?
 
The server code is like the following:
 
static void thread_1(void *arg)
{
  conn = netconn_new(NETCONN_TCP);
 
  if (conn!= NULL)
  {
    err = netconn_bind(conn, NULL, 9229);
   
    if (err == ERR_OK)
    {
      netconn_listen(conn);
     
      while(1)
      {
        if (CONN_NUM < 1)
        {
          MY_CONN = netconn_accept(conn);
         
          CONN_NUM++;
        }
        else
        {
          vTaskDelay(500);
        }
      }
    }
  }
}
 
static void thread_2(void *arg)
{
  for (;;)
  {
    if (CONN_NUM > 0)
    {
      inbuf = netconn_recv(MY_CONN);
     
      if (inbuf != NULL)
      {
        if (netconn_err(MY_CONN) == ERR_OK)
        {
          netbuf_data(inbuf, (void**)&recv_buf, &recv_buflen);
         
          if (recv_buflen >= 9)
          {
            msg_id = recv_buf[4];
             
            switch (msg_id)
            {
              case MSG_1:
                //...
                netconn_write(MY_CONN, (const unsigned char*)send_buff, (size_t)send_buflen, NETCONN_NOCOPY);
                break;
              
              case MSG_2:
                //...
                netconn_write(MY_CONN, (const unsigned char*)send_buff, (size_t)send_buflen, NETCONN_NOCOPY);
                break;
           
              default:
                break;
            }
          }
         
          while( netbuf_next(inbuf) >= 0 ){}
        }
       
        netbuf_delete(inbuf);
      }
     
      vTaskDelay(10);
    }
    else
    {
      vTaskDelay(500);
    }
  }
}

Thanks.

--

Damiano Grechi

ALTA LAB S.r.l.
Via Boncompagni, 67
20139 - Milano - Italy
Tel:  +39 02 36515556
Fax:  +39 02 36515559
email: address@hidden




--

Damiano Grechi

ALTA LAB S.r.l.
Via Boncompagni, 67
20139 - Milano - Italy
Tel:  +39 02 36515556
Fax:  +39 02 36515559
email: address@hidden


reply via email to

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