[Top][All Lists]

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

[lwip-users] How to avoid lwIP v2.1.2 udp send stuck when data is coming

From: Lan Yang
Subject: [lwip-users] How to avoid lwIP v2.1.2 udp send stuck when data is coming in faster than it is going out
Date: Thu, 15 Sep 2022 21:48:00 +0800

Hi lwip-users,

Help! ! !
I've been having some problems lately with lwIP v2.1.2's udp_send function.

The program logic is as follows:
1. I customized a udp_client_send() function, its content is:
/***************udp_client_send() function begin*********************/
void udp_client_send(const char *pData, int16_t len) {
  if (udp_send_mutex == RT_NULL) {
    rt_kprintf("udp send mutex is NULL");
  rt_mutex_take(udp_send_mutex, RT_WAITING_FOREVER);
  struct pbuf *p;
  p = pbuf_alloc(PBUF_TRANSPORT, len, PBUF_RAM);
  if (p != NULL) {
    pbuf_take(p, pData, len);
    udp_send(upcb, p);
  } else {
    rt_kprintf("udp_client_send p == NULL\r\n");
/***************udp_client_send() function end**********************/
2. There are two threads, both of which call udp_client_send();
3. Among these two threads, one thread calls udp_client_send() 100 times within 1ms, and the other calls udp_client_send() randomly within 1ms
4. The length of the function sent through UDP each time is about 80~5000;
5. We transplanted the lwip from this source code: https://github.com/RT-Thread/rt-thread/blob/a0ca06b4994d7c4a423b03f272c2c2a86a7bd07f/components/net/lwip/lwip-2.1.2/src/include/lwip/udp.h#L138

Two issues I encountered:
issue1. After running for a while, program will assert at p->ref >0.
Later, I learned that udp_send cannot be called by multiple threads, so I added a mutex later;
issue2. After adding the mutex lock on the basis of issue1, after running for a while, assert again, stuck in "p != NULL"

Here's what you need help with:
Q1: Is it the best way to solve issue1 by adding a mutex?
Q2: Regarding issue 2, our team guessed that issue 2 was caused by the fact that the speed at which the application layer stuffed UDP with data was faster than the speed at which UDP forwarded data. Is our guess correct? How to verify and adjust? Do you have any suggestions?
Q3: We define
The operation of this function udp_client_send() routine? Is there a better definition for Demo?
Q4: What do lwip experts usually do to avoid such a situation where data is coming in faster than it is going out?

Best regards,

CONFIDENTIALITY NOTICE: The contents of this email and any attachments are intended solely for the addressee(s) and contain confidential and/or privileged information and are legally protected from disclosure unless otherwise indicated. If you received this message by mistake, please immediately alert the sender by reply email and then delete this message and any attachments. If you are not the intended recipient, you are hereby notified that any use, dissemination, copying, or storage of this message or its attachments is strictly prohibited.  

reply via email to

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