[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [lwip-users] ERR_ABRT: Out of pcbs or netconns
From: |
tirmalabenikasibeni |
Subject: |
Re: [lwip-users] ERR_ABRT: Out of pcbs or netconns |
Date: |
Mon, 22 Apr 2019 01:28:23 -0700 (MST) |
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
- Re: [lwip-users] ERR_ABRT: Out of pcbs or netconns, (continued)
- Re: [lwip-users] ERR_ABRT: Out of pcbs or netconns, sarp, 2019/04/11
- Re: [lwip-users] ERR_ABRT: Out of pcbs or netconns, tirmalabenikasibeni, 2019/04/11
- Re: [lwip-users] ERR_ABRT: Out of pcbs or netconns, Sarp Daltaban, 2019/04/11
- Re: [lwip-users] ERR_ABRT: Out of pcbs or netconns, tirmalabenikasibeni, 2019/04/11
- Re: [lwip-users] ERR_ABRT: Out of pcbs or netconns, goldsimon, 2019/04/11
- Re: [lwip-users] ERR_ABRT: Out of pcbs or netconns, tirmalabenikasibeni, 2019/04/12
- Re: [lwip-users] ERR_ABRT: Out of pcbs or netconns, address@hidden, 2019/04/16
- Re: [lwip-users] ERR_ABRT: Out of pcbs or netconns, tirmalabenikasibeni, 2019/04/18
- Re: [lwip-users] ERR_ABRT: Out of pcbs or netconns, Simon Goldschmidt, 2019/04/18
- Re: [lwip-users] ERR_ABRT: Out of pcbs or netconns, tirmalabenikasibeni, 2019/04/22
- Re: [lwip-users] ERR_ABRT: Out of pcbs or netconns,
tirmalabenikasibeni <=