[Top][All Lists]

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

Re: [lwip-users] lwIP hangs after some data transferred

From: Grzegorz Niemirowski
Subject: Re: [lwip-users] lwIP hangs after some data transferred
Date: Thu, 4 Sep 2014 00:10:02 +0200

It can be some problem with memory management but there is no place I should free memory. There are just automatic variables (allocated on stack) and public variables (allocated on heap). There are also four FreeRTOS queues, but they are created only once, when one of tasks starts. I don't use malloc or similar functions. Here is the source code of the task:

#include "lwip/sockets.h"
#include "stm32f4xx_hal.h"
#include "cmsis_os.h"
#include <stdint.h>
#include <string.h>
#include "flash_settings.h"

void serve(int conn);

uint16_t RX_BUFFER[50];
uint16_t TX_BUFFER[50];
extern struct settings_struct settings;
uint8_t changePort = 0;
extern xQueueHandle appQueueRx;
extern xQueueHandle appQueueTx;

void appTask(void const * argument)
appQueueRx = xQueueCreate(1, 100);

 int newconn, size;
 struct sockaddr_in address, remotehost;
 int appSocket;

/* create a TCP socket */
 if ((appSocket = socket(AF_INET, SOCK_STREAM, 0)) < 0)
 fcntl(appSocket, F_SETFL, lwip_fcntl(appSocket, F_GETFL, 0) | O_NONBLOCK);

 /* bind to port 2324 at any interface */
 memset(&address, 0, sizeof(address));
 address.sin_family = AF_INET;
 address.sin_port = htons(settings.appPort);
 address.sin_addr.s_addr = INADDR_ANY;

 if (bind(appSocket, (struct sockaddr *)&address, sizeof(address)) < 0)

 /* listen for incoming connections (TCP listen backlog = 5) */
 listen(appSocket, 5);

 size = sizeof(remotehost);

newconn = accept(appSocket, (struct sockaddr *)&remotehost, (socklen_t *)&size);
   if (changePort){
    changePort = 0;
    appSocket = socket(AF_INET, SOCK_STREAM, 0);
fcntl(appSocket, F_SETFL, lwip_fcntl(appSocket, F_GETFL, 0) | O_NONBLOCK);
    address.sin_port = htons(settings.appPort);
    bind(appSocket, (struct sockaddr *)&address, sizeof (address));
    listen(appSocket, 5);
   if (newconn >= 0) serve(newconn); else vTaskDelay(100);

void serve(int conn)
int ret;
ret = read(conn, TX_BUFFER, sizeof(TX_BUFFER));
if (ret>0) {
 xQueueSend(appQueueTx, &TX_BUFFER, 100);
 xQueueReceive(appQueueRx, &RX_BUFFER, 100);
 write(conn, (const unsigned char*)RX_BUFFER, (size_t)sizeof(RX_BUFFER));

Noam weissman <address@hidden> napisał(a):
Please check if you free memory properly. It sounds like a memory leak?
-----Original Message-----
From: address@hidden on behalf of Grzegorz
Niemirowski Sent: Tue 9/2/2014 8:34 PM
To: Mailing list for lwIP users
Subject: Re: [lwip-users] lwIP hangs after some data transferred
Thanks Noam. I have interrupt priorities set exactly as you have written.
The problem must be somewhere else.

reply via email to

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