lwip-users
[Top][All Lists]
Advanced

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

[lwip-users] Using tcp_write() outside tcp_recv callback


From: Jamie
Subject: [lwip-users] Using tcp_write() outside tcp_recv callback
Date: Wed, 1 Apr 2020 14:15:30 -0700 (MST)

Hi, I'm using lwIP 1.4.1 on a SAME70 with NO_SYS = 1. I started with the tcpech_raw application (a clone of which is linked here for reference), which worked exactly as intended on the SAME70 with the SAME70 port. I've now started to modify the tcpecho_raw application to suit my use case, but am running into a few issues. Before I get into the issues, I think it prudent to detail my use case, my lwipopts and approach.

Use Case

  • lwIP is being used for a direct connection between the SAME70 and another processor on the same board. There will only ever be one connection, using static IP addresses.
  • lwIP is used primarily for TX out of the SAME70. RX is used for configuration updates/changes.
  • The SAME70 receives data from other interfaces, and following some processing, needs to TX the data to the other processor. This is a time-sensitive procedure; the delay between the SAME70 receiving and processing the data, to the data being on the wire can't be more than ~10ms.
  • Each discrete packet of data is less than 50 bytes.
  • lwipopts.h

  • NO_SYS = 1
  • MEM_ALIGNMENT = 4
  • MEM_SIZE = 4 * 1024
  • MEMP_NUM_TCP_PCB = 1
  • LWIP_DHCP = 0
  • TCP_MSS = 1460
  • TCP_WND = (2 * TCP_MSS)
  • TCP_SND_BUF = (2 * TCP_MSS)
  • Approach

  • Maintain the same echo_init function.
  • Use a global struct tcp_pcb and assign it during the accept callback.
  • Use similar tcp_recv and tcp_err functions.
  • I'm not using the tcp_poll function for the time being.
  • Where I need some guidance

    1. In the example echo_send function, after tcp_write(), the current pbuf is freed via a do-while call to pbuf_free(ptr), where struct pbuf *ptr = es->p. I'm not using a send function; I'm looking to use tcp_write() and tcp_output() directly from elsewhere in the application, using the global tcp_pcb assigned on accept callback. How can I free the pbuf following tcp_output? The pbuf_free() function requires a pbuf input, which I don't have when calling tcp_write() from outside a callback. Do I need to manually create and allocate a pbuf, use the pbuf's payload and len parameters in the tcp_write call, and then use pcb_free? At the moment I'm able to send a couple of packets before receiving the "tcp_write: could not allocate memory for pbuf copy size ..." error; I assume this is because the pbuf is not deallocated once used (i.e. after tcp_write and tcp_output).
    2. What should my TCP_OVERSIZE value be?
    3. Do my lwipopts.h defines look reasonable?
    4. Is the approach of sending small packets one at a time feasible? I understand that there is considerable overhead associated with this approach. Depending on my testing (once I've got this approach working), I may look to concatenate multiple packets in a buffer and reduce the number of transmissions, as I should be able to do so within the allowed ~10ms time.
    Any guidance on the above 4 questions would be greatly appreciated! Thanks

    Sent from the lwip-users mailing list archive at Nabble.com.

    reply via email to

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