ERR_ABRT: Out of pcbs or netconns

classic Classic list List threaded Threaded
15 messages Options
Reply | Threaded
Open this post in threaded view
|

ERR_ABRT: Out of pcbs or netconns

tirmalabenikasibeni
This post was updated on .
Hi all,

I am developing a MODBUS Server which can serve multiple clients
simultaneously, using LwIP 2.0.3 & netconn and FreeRTOS 9.0.0 and
STM32H743BI.

A client (my pc in this case) can connect the server with no problem. When
disconnected and connected again there is no problem also, but if it tried
to connect 3. time, connection can't be established and netconn_accept
returns ERR_ABRT.

This is a part of my lwipopts.h:
#define MEMP_NUM_NETCONN        30
#define MEMP_NUM_NETBUF         30
#define MEMP_NUM_PBUF           60
#define MEMP_NUM_UDP_PCB        6
#define MEMP_NUM_TCP_PCB        10
#define MEMP_NUM_TCP_PCB_LISTEN 8
#define MEMP_NUM_TCP_SEG        8
#define MEMP_NUM_SYS_TIMEOUT    10

And my thread and handler:

void modbus_server_netconn_thread(void *arg)
{
  struct netconn *conn = NULL, *newconn = NULL;
  err_t err, accept_err;


  osThreadDef(MBParticular, modbus_handler, osPriorityNormal, 8, configMINIMAL_STACK_SIZE *4);

  /* Create a new TCP connection handle */

  conn = netconn_new(NETCONN_TCP);

  if (conn!= NULL)
  {
    /* Bind to port 502 with default IP address */

    err = netconn_bind(conn, NULL, 502);

    if (err == ERR_OK)
    {
      /* Put the connection into LISTEN state */

      netconn_listen(conn);

      while(1)
      {
        /* accept any incoming connection */

        accept_err = netconn_accept(conn, &newconn);

        if(accept_err == ERR_OK)
        {
            osThreadCreate (osThread(MBParticular), (void *)newconn);

//          /* delete connection */
//          netconn_delete(newconn);  //if I put this here, no data can be rcved
            newconn = NULL;
        }
        else netconn_delete(newconn);
      }
    }
  }
}

static void modbus_handler(void const *arg)
{
  struct netconn *conn = (struct netconn *)arg;
  err_t recv_err;
  u16_t buflen;
  char* buf;
  struct pbuf *p = NULL;
  struct netbuf *inbuf;

  while(TRUE){

  /* Read the data from the port, blocking if nothing yet there.
   We assume the request (the part we care about) is in one netbuf */

  recv_err = netconn_recv(conn, &inbuf);

  if (recv_err == ERR_OK)
  {
    if (netconn_err(conn) == ERR_OK)
    {
      netbuf_data(inbuf, (void**)&buf, &buflen);

    //    HANDLE PACKET

    }
  }

  /* Delete the buffer (netconn_recv gives us ownership, so we have to make sure to deallocate the buffer) */

  netbuf_delete(inbuf);

  }

  /* Close the connection */
  netconn_delete(conn);
  osThreadTerminate(NULL);
}

Please forgive me if I waste your time, but I am struggling for a couple of
days.

Thank you!



--
Sent from: http://lwip.100.n7.nabble.com/lwip-users-f3.html

_______________________________________________
lwip-users mailing list
lwip-users@nongnu.org
https://lists.nongnu.org/mailman/listinfo/lwip-users
Reply | Threaded
Open this post in threaded view
|

Re: ERR_ABRT: Out of pcbs or netconns

Terry Barnaby
On 11/04/2019 08:33, tirmalabenikasibeni wrote:

> Hi all,
>
> I am developing a MODBUS Server which can serve multiple clients
> simultaneously, using LwIP 2.0.3 & netconn and FreeRTOS 9.0.0 and
> STM32H743BI.
>
> A client (my pc in this case) can connect the server with no problem. When
> disconnected and connected again there is no problem also, but if it tried
> to connect 3. time, connection can't be established and netconn_accept
> returns ERR_ABRT.
>
> This is a part of my lwipopts.h:
>
>
> And my thread and handler:
>
>
>
> Please forgive me if I waste your time, but I am struggling for a couple of
> days.
>
> Thank you!
>
>
>
> --
> Sent from: http://lwip.100.n7.nabble.com/lwip-users-f3.html
>
> _______________________________________________
> lwip-users mailing list
> [hidden email]
> https://lists.nongnu.org/mailman/listinfo/lwip-users

I know its pseudo code, but in your modbus_handler() thread function do
you actually break out of the while(TRUE) loop and call netconn_close()
and netconn_delete() when the remote client disconnects ? (I'm not sure
if both netconn_close() and netconn_delete() are needed). If not the
available connections will be used up after a time.


_______________________________________________
lwip-users mailing list
[hidden email]
https://lists.nongnu.org/mailman/listinfo/lwip-users
Reply | Threaded
Open this post in threaded view
|

Re: ERR_ABRT: Out of pcbs or netconns

tirmalabenikasibeni
This post was updated on .
Hello Terry,


Terry Barnaby wrote
>  but in your modbus_handler() thread function do
> you actually break out of the while(TRUE) loop and call netconn_close()
> and netconn_delete() when the remote client disconnects ?

I can show you more. I think I am handling what you say. But I'm not sure.

while(TRUE){

  /* Read the data from the port, blocking if nothing yet there.
   We assume the request (the part we care about) is in one netbuf */

  recv_err = netconn_recv(conn, &inbuf);

  if (recv_err == ERR_OK)
  {
    if (netconn_err(conn) == ERR_OK)
    {
      netbuf_data(inbuf, (void**)&buf, &buflen);

      p = pbuf_alloc(PBUF_TRANSPORT, MODBUS_BUFFER_SIZE, PBUF_RAM);

      if(p == NULL){
    	  pbuf_free(p);
      }

    //    HANDLE PACKET

       pbuf_free(p);
    }
  }

  else if (recv_err==ERR_CLSD) goto exit;
  else osDelay(1);

  /* Delete the buffer (netconn_recv gives us ownership, so we have to make sure to deallocate the buffer) */

  netbuf_delete(inbuf);

  }

  exit:
  /* Close the connection */
  netconn_delete(conn);
  osThreadTerminate(NULL);
}





--
Sent from: http://lwip.100.n7.nabble.com/lwip-users-f3.html

_______________________________________________
lwip-users mailing list
lwip-users@nongnu.org
https://lists.nongnu.org/mailman/listinfo/lwip-users
Reply | Threaded
Open this post in threaded view
|

Re: ERR_ABRT: Out of pcbs or netconns

Terry Barnaby
On 11/04/2019 10:31, tirmalabenikasibeni wrote:
Hello Terry,


Terry Barnaby wrote
 but in your modbus_handler() thread function do 
you actually break out of the while(TRUE) loop and call netconn_close() 
and netconn_delete() when the remote client disconnects ?
I can show you more. I think I am handling what you say. But I'm not sure.







--
Sent from: http://lwip.100.n7.nabble.com/lwip-users-f3.html

_______________________________________________
lwip-users mailing list
[hidden email]
https://lists.nongnu.org/mailman/listinfo/lwip-users

I'm no expert on Lwip, but looks ok to me. Might be worth adding a printf or whatever method you have to debug to check that the connection is actually being closed. Not sure if you need a netconn_close() as well as netconn_delete() or not.

I don't think you want:

    newconn = NULL;
 }
 else netconn_delete(newconn);

in the listen thread.

_______________________________________________
lwip-users mailing list
[hidden email]
https://lists.nongnu.org/mailman/listinfo/lwip-users
Reply | Threaded
Open this post in threaded view
|

Re: ERR_ABRT: Out of pcbs or netconns

tirmalabenikasibeni
Terry Barnaby wrote
> I don't think you want:
>
>      newconn = NULL;
>   }
>   else netconn_delete(newconn);
>
> in the listen thread.

Hi again,

It doesn't make any difference whether these lines are written or not. Still
same error: "ERR_ABRT"





--
Sent from: http://lwip.100.n7.nabble.com/lwip-users-f3.html

_______________________________________________
lwip-users mailing list
[hidden email]
https://lists.nongnu.org/mailman/listinfo/lwip-users
Reply | Threaded
Open this post in threaded view
|

Re: ERR_ABRT: Out of pcbs or netconns

sarp
In reply to this post by tirmalabenikasibeni
Kanka Netconn zaten multi client bağlanmasına izin veren bir soket.
Bağlantı başına yeni thread yaratmana gerek yok.
Hangi şirkette çalışıyorsun?



--
Sent from: http://lwip.100.n7.nabble.com/lwip-users-f3.html

_______________________________________________
lwip-users mailing list
[hidden email]
https://lists.nongnu.org/mailman/listinfo/lwip-users
Reply | Threaded
Open this post in threaded view
|

Re: ERR_ABRT: Out of pcbs or netconns

tirmalabenikasibeni
sarp wrote
> Kanka Netconn zaten multi client bağlanmasına izin veren bir soket.
> Bağlantı başına yeni thread yaratmana gerek yok.

Yani diyosunki sadece listen thread olsun, her accepted bağlantı için bir
kez callback çağır yeterli. Doğru mu?


sarp wrote
> Hangi şirkette çalışıyorsun?

Datakomda çalışıyorum moruk sen?



--
Sent from: http://lwip.100.n7.nabble.com/lwip-users-f3.html

_______________________________________________
lwip-users mailing list
[hidden email]
https://lists.nongnu.org/mailman/listinfo/lwip-users
Reply | Threaded
Open this post in threaded view
|

Re: ERR_ABRT: Out of pcbs or netconns

sarp
Doğru kanka, tek thread yeterli eğer ppp'yi beslemiyorsan.
Endoks & t4e'de çalışıyorum.

tirmalabenikasibeni <[hidden email]>, 11 Nis 2019 Per, 16:47 tarihinde şunu yazdı:
sarp wrote
> Kanka Netconn zaten multi client bağlanmasına izin veren bir soket.
> Bağlantı başına yeni thread yaratmana gerek yok.

Yani diyosunki sadece listen thread olsun, her accepted bağlantı için bir
kez callback çağır yeterli. Doğru mu?


sarp wrote
> Hangi şirkette çalışıyorsun?

Datakomda çalışıyorum moruk sen?



--
Sent from: http://lwip.100.n7.nabble.com/lwip-users-f3.html

_______________________________________________
lwip-users mailing list
[hidden email]
https://lists.nongnu.org/mailman/listinfo/lwip-users

_______________________________________________
lwip-users mailing list
[hidden email]
https://lists.nongnu.org/mailman/listinfo/lwip-users
Reply | Threaded
Open this post in threaded view
|

Re: ERR_ABRT: Out of pcbs or netconns

tirmalabenikasibeni
This post was updated on .
I am not an LwIP expert. My origin point is CubeH7 applications for STM32H743. I have changed the code according to your advises:

static void modbus_handler(struct netconn *conn)
{
  err_t recv_err;
  u16_t buflen;
  char* buf;
  struct pbuf *p = NULL;
  struct netbuf *inbuf;

  recv_err = netconn_recv(conn, &inbuf);

  if (recv_err == ERR_OK)
  {
    if (netconn_err(conn) == ERR_OK)
    {
      netbuf_data(inbuf, (void**)&buf, &buflen);

      if(buf != NULL) ticknow = sys_now();

      p = pbuf_alloc(PBUF_TRANSPORT, MODBUS_BUFFER_SIZE, PBUF_RAM);

     HANDLEhandleHANDLE

      pbuf_free(p);
    }
  }
  else if (recv_err==ERR_CLSD) netconn_delete(conn);

  netbuf_delete(inbuf);
}

static void modbus_server_netconn_thread(void *arg)
{
  struct netconn *conn, *newconn;
  err_t err, accept_err;

  conn = netconn_new(NETCONN_TCP);

  if (conn!= NULL)
  {
    err = netconn_bind(conn, NULL, 502);

    if (err == ERR_OK)
    {
      netconn_listen(conn);

      while(1)
      {
        accept_err = netconn_accept(conn, &newconn);

        if(accept_err == ERR_OK)
        {
          modbus_handler(newconn);
        }
      }
    }
  }
}

When connected, there is an OK and after an ERROR and after some communication no OK is returned.
Thanks.


--
Sent from: http://lwip.100.n7.nabble.com/lwip-users-f3.html

_______________________________________________
lwip-users mailing list
lwip-users@nongnu.org
https://lists.nongnu.org/mailman/listinfo/lwip-users
Reply | Threaded
Open this post in threaded view
|

Re: ERR_ABRT: Out of pcbs or netconns

goldsimon@gmx.de
In reply to this post by sarp
Please, this is an international community list, could you write in English so that everyone can understand?

Thanks,
Simon


Am 11. April 2019 16:22:25 MESZ schrieb Sarp Daltaban <[hidden email]>:
Doğru kanka, tek thread yeterli eğer ppp'yi beslemiyorsan.
Endoks & t4e'de çalışıyorum.

tirmalabenikasibeni <[hidden email]>, 11 Nis 2019 Per, 16:47 tarihinde şunu yazdı:
sarp wrote
> Kanka Netconn zaten multi client bağlanmasına izin veren bir soket.
> Bağlantı başına yeni thread yaratmana gerek yok.

Yani diyosunki sadece listen thread olsun, her accepted bağlantı için bir
kez callback çağır yeterli. Doğru mu?


sarp wrote
> Hangi şirkette çalışıyorsun?

Datakomda çalışıyorum moruk sen?



--
Sent from: http://lwip.100.n7.nabble.com/lwip-users-f3.html

_______________________________________________
lwip-users mailing list
[hidden email]
https://lists.nongnu.org/mailman/listinfo/lwip-users

_______________________________________________
lwip-users mailing list
[hidden email]
https://lists.nongnu.org/mailman/listinfo/lwip-users
Reply | Threaded
Open this post in threaded view
|

Re: ERR_ABRT: Out of pcbs or netconns

tirmalabenikasibeni
[hidden email] wrote
> Please, this is an international community list, could you write in
> English so that everyone can understand?

Hey Simon, you are right, I apologize.

Can you tell me where is the mistake in this piece of code?



--
Sent from: http://lwip.100.n7.nabble.com/lwip-users-f3.html

_______________________________________________
lwip-users mailing list
[hidden email]
https://lists.nongnu.org/mailman/listinfo/lwip-users
Reply | Threaded
Open this post in threaded view
|

Re: ERR_ABRT: Out of pcbs or netconns

goldsimon@gmx.de
Am 12.04.2019 um 09:02 schrieb tirmalabenikasibeni:
> [hidden email] wrote
>> Please, this is an international community list, could you write in
>> English so that everyone can understand?
>
> Hey Simon, you are right, I apologize.
>
> Can you tell me where is the mistake in this piece of code?

Which code?

Regards,
Simon

_______________________________________________
lwip-users mailing list
[hidden email]
https://lists.nongnu.org/mailman/listinfo/lwip-users
Reply | Threaded
Open this post in threaded view
|

Re: ERR_ABRT: Out of pcbs or netconns

tirmalabenikasibeni
This post was updated on .
goldsimon@gmx.de wrote
> Which code?

In the initial post, or revised one:

static void modbus_handler(struct netconn *conn)
{
  err_t recv_err;
  u16_t buflen;
  char* buf;
  struct pbuf *p = NULL;
  struct netbuf *inbuf;

  recv_err = netconn_recv(conn, &inbuf);

  if (recv_err == ERR_OK)
  {
    if (netconn_err(conn) == ERR_OK)
    {
      netbuf_data(inbuf, (void**)&buf, &buflen);

      if(buf != NULL) ticknow = sys_now();

      p = pbuf_alloc(PBUF_TRANSPORT, MODBUS_BUFFER_SIZE, PBUF_RAM);

     HANDLEhandleHANDLE

      pbuf_free(p);
    }
  }
  else if (recv_err==ERR_CLSD) netconn_delete(conn);

  netbuf_delete(inbuf);
}

static void modbus_server_netconn_thread(void *arg)
{
  struct netconn *conn, *newconn;
  err_t err, accept_err;

  conn = netconn_new(NETCONN_TCP);

  if (conn!= NULL)
  {
    err = netconn_bind(conn, NULL, 502);

    if (err == ERR_OK)
    {
      netconn_listen(conn);

      while(1)
      {
        accept_err = netconn_accept(conn, &newconn);

        if(accept_err == ERR_OK)
        {
          modbus_handler(newconn);
        }
      }
    }
  }
}
--
Sent from: http://lwip.100.n7.nabble.com/lwip-users-f3.html

_______________________________________________
lwip-users mailing list
lwip-users@nongnu.org
https://lists.nongnu.org/mailman/listinfo/lwip-users
Reply | Threaded
Open this post in threaded view
|

Re: ERR_ABRT: Out of pcbs or netconns

goldsimon@gmx.de


On 18.04.19 11:06, tirmalabenikasibeni wrote:
> [hidden email] wrote
>> Which code?
>
> In the  initial code
> <http://lwip.100.n7.nabble.com/ERR-ABRT-Out-of-pcbs-or-netconns-tp34309.html>
> , or revised one:

There's no code here. I guess the problem is that you're using nabble
while this is a mailing list, not a nabble forum. Nabble just provides a
(somewhat nasty) view to this list, which also has the downside of
people not citing older messages when replying...

Here's what your post looks like in the official mailing list archive:
http://lists.nongnu.org/archive/html/lwip-users/2019-04/msg00055.html

Regards,
Simon

_______________________________________________
lwip-users mailing list
[hidden email]
https://lists.nongnu.org/mailman/listinfo/lwip-users
Reply | Threaded
Open this post in threaded view
|

Re: ERR_ABRT: Out of pcbs or netconns

tirmalabenikasibeni
I just tryed writing the posts again, but anything in raw text can't be seen.
Anyway...

The first code I wrote is:

void modbus_server_netconn_thread(void *arg)
{
  struct netconn *conn = NULL, *newconn = NULL;
  err_t err, accept_err;


  osThreadDef(MBParticular, modbus_handler, osPriorityNormal, 8,
configMINIMAL_STACK_SIZE *4);

  /* Create a new TCP connection handle */

  conn = netconn_new(NETCONN_TCP);

  if (conn!= NULL)
  {
    /* Bind to port 502 with default IP address */

    err = netconn_bind(conn, NULL, 502);

    if (err == ERR_OK)
    {
      /* Put the connection into LISTEN state */

      netconn_listen(conn);

      while(1)
      {
        /* accept any incoming connection */

        accept_err = netconn_accept(conn, &newconn);

        if(accept_err == ERR_OK)
        {
            osThreadCreate (osThread(MBParticular), (void *)newconn);

//          /* delete connection */
//          netconn_delete(newconn);  //if I put this here, no data can be
rcved
            newconn = NULL;
        }
        else netconn_delete(newconn);
      }
    }
  }
}

static void modbus_handler(void const *arg)
{
  struct netconn *conn = (struct netconn *)arg;
  err_t recv_err;
  u16_t buflen;
  char* buf;
  struct pbuf *p = NULL;
  struct netbuf *inbuf;

  while(TRUE){

  /* Read the data from the port, blocking if nothing yet there.
   We assume the request (the part we care about) is in one netbuf */

  recv_err = netconn_recv(conn, &inbuf);

  if (recv_err == ERR_OK)
  {
    if (netconn_err(conn) == ERR_OK)
    {
      netbuf_data(inbuf, (void**)&buf, &buflen);

    //    HANDLE PACKET

    }
  }

  /* Delete the buffer (netconn_recv gives us ownership, so we have to make
sure to deallocate the buffer) */

  netbuf_delete(inbuf);

  }

  /* Close the connection */
  netconn_delete(conn);
  osThreadTerminate(NULL);
}


And some part of my lwipopts.h:

#define MEMP_NUM_NETCONN        30
#define MEMP_NUM_NETBUF         30
#define MEMP_NUM_PBUF           60
#define MEMP_NUM_UDP_PCB        6
#define MEMP_NUM_TCP_PCB        10
#define MEMP_NUM_TCP_PCB_LISTEN 8
#define MEMP_NUM_TCP_SEG        8
#define MEMP_NUM_SYS_TIMEOUT    10


After sarp's correction it turns into:

static void modbus_handler(struct netconn *conn)
{
  err_t recv_err;
  u16_t buflen;
  char* buf;
  struct pbuf *p = NULL;
  struct netbuf *inbuf;

  recv_err = netconn_recv(conn, &inbuf);

  if (recv_err == ERR_OK)
  {
    if (netconn_err(conn) == ERR_OK)
    {
      netbuf_data(inbuf, (void**)&buf, &buflen);

      if(buf != NULL) ticknow = sys_now();

      p = pbuf_alloc(PBUF_TRANSPORT, MODBUS_BUFFER_SIZE, PBUF_RAM);

     HANDLEhandleHANDLE

      pbuf_free(p);
    }
  }
  else if (recv_err==ERR_CLSD) netconn_delete(conn);

  netbuf_delete(inbuf);
}

static void modbus_server_netconn_thread(void *arg)
{
  struct netconn *conn, *newconn;
  err_t err, accept_err;

  conn = netconn_new(NETCONN_TCP);

  if (conn!= NULL)
  {
    err = netconn_bind(conn, NULL, 502);

    if (err == ERR_OK)
    {
      netconn_listen(conn);

      while(1)
      {
        accept_err = netconn_accept(conn, &newconn);

        if(accept_err == ERR_OK)
        {
          modbus_handler(newconn);
        }
      }
    }
  }
}


But this way, modbus client on my PC returns me 1 OK following 1 ERROR, and
after some communication (generally after 3 OK responds) it returns
ERR_ABRT.




--
Sent from: http://lwip.100.n7.nabble.com/lwip-users-f3.html

_______________________________________________
lwip-users mailing list
[hidden email]
https://lists.nongnu.org/mailman/listinfo/lwip-users