cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
davethetroll
Observer
Observer
1,088 Views
Registered: ‎02-26-2018

When is data sent using udp_send()?

I am developing a bare metal application for the ARM core on the Zynq XC7Z020, where I will ultimately wish to send a fair amount of data using UDP.

In my investigations I have a basic UDP transmitter that sends a 3 byte packet every second.  In doing so, I am reusing the same buffer each time (same pcb, same char[] and same pbuf).

 

It basically works, except every so often one of the packets will take slightly longer and when it arrives it contains the contents of the following packet.

I have added debug code to investigate the structures and note that the pbuf->ref is higher (5) after the send in these instances than normal (3).  It appears therefore that this is the sequence of events.

1) pbuf structure has ref=1.  (that would be my reference in which I created it).
2) udp_send() is called and the stack makes two references to the structure.

3) On exiting the function the packet has not yet been sent, it has simply been queued to do so.
4) A second later the packet still hasn't gone, I change what is in memory.
5) udp_send() is called and the stack makes two more references.
6) Both the first and second packet are sent, but with payload of the second.

So, I understand what is going on and it makes sense.  I also know how to work around (multiple buffers).  I am looking for recommendations.

a) Is all the expected behaviour?
b) Why would it take so long for the packet to leave the stack?
c) Can I ensure that the ref count will be 1 if packet has been sent and that the packet has been sent if the ref count is 1?
d) Is (c) the recommended method of determining that the buffer is ready for reuse, or is there another method?

0 Kudos
4 Replies
davethetroll
Observer
Observer
1,076 Views
Registered: ‎02-26-2018

Addendum:

I'm actually sending 100 byte packages, but only the first three characters change as part of my test.

Checking the ref count prior to calling udp_send gives the result that it is greater than one 47% of the time. If I change the code to send every 100ms, or every 10ms, this only rises to 49%. The ref count has never been greater than 3.
0 Kudos
smcnutt
Contributor
Contributor
1,054 Views
Registered: ‎04-04-2018

Read through rawapi.txt. The api description (don't skip the tcp section) and the section at the end of the file ("Zero-copy MACs") will likely answer most of your questions and explain your observations.

 

0 Kudos
davethetroll
Observer
Observer
1,005 Views
Registered: ‎02-26-2018

Thanks.  That answers it.

  Dave

(It would be useful if this documentation was available in a more readable online format.  It would help if it were mentioned here, or here).

0 Kudos
smcnutt
Contributor
Contributor
995 Views
Registered: ‎04-04-2018

> It would be useful if this documentation was

> available in a more readable online format.

 

You get what you pay for ... and then some: try the wiki.

 

0 Kudos