lwip-users
[Top][All Lists]
Advanced

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

Re: [lwip-users] uneven UDP transfer


From: address@hidden
Subject: Re: [lwip-users] uneven UDP transfer
Date: Thu, 22 Sep 2011 20:51:24 +0200
User-agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.6; rv:6.0.2) Gecko/20110902 Thunderbird/6.0.2

First, please don't just post the same thing multiple times. Not getting an answer most often means noone has an idea what's wrong. By just posting multiple times you risk annoying people and then not getting any answer at all...

As to your problem, if not freeing the pbuf helps, that might be a problem in your netif driver. If the driver does not send packets right away (meaning they are already sent when the driver's 'linkoutput' function returns; this is most often not the case for DMA-enabled ethernet MACs), it has to pbuf_ref() a pbuf and then pbuf_free() it after it has been copied to MAC buffers. Failing to do so, a the pbuf can get freed before sending and re-used by the next call to pbuf_alloc(), which could result in the problem you are seeing.

Simon


Huston007 wrote:
Hello there.
so look. I use LwIP 1.3.2 on ST32F207 ARM microcontroller. I want to send a
lot of data from ST32 to PC using UDP, in standalone application.

I make a application basic on udp-server demo. Its great work, if _i dont
free the pbuf in udp_receive callback_.

if i add a pbuf_free(p); at end of callback, the data transfer corrupting,
it going to be uneven, fragmentary. This is my code:


//my receive callback:
void udp_echoserver_receive_callback(void *arg, struct udp_pcb *upcb, struct
pbuf *p, struct ip_addr *addr, u16_t port)
{
   //remember the structures to use it in send function
   upcb1 = upcb;
   addr1 = addr;

   parseIncomingMessage(p); //searching for commands in incoming messages

   /* Free the p buffer */

   pbuf_free(p); //this is it! if i use it, it is uneven transmit! If not,
app receive only few messages and going to corrupt
}
And there is my send function:


void udpSendArray(uint16_t data[])
{
         err_t err;
         uint16_t len = udpPackageSize + headerSize;

         struct pbuf *pb = pbuf_alloc(PBUF_TRANSPORT,len, PBUF_REF);

         pb->payload = data;

         udp_connect(upcb1, addr1, UDP_CLIENT_PORT);
         err = udp_send(upcb1, pb);
         if(err!=ERR_OK)        {
                 //do something. But application never enter this block
         }
         udp_disconnect(upcb1);
         pbuf_free(pb);
}
this function periodically calling from main cycle (main.c):


   while (1)
   {
     /* check if any packet received */
     if (ETH_CheckFrameReceived())
     {
       /* process received ethernet packet */
       LwIP_Pkt_Handle();
     }
     /* handle periodic timers for LwIP */
     LwIP_Periodic_Handle(LocalTime);

         if (full_transmit) udpSendArray(bufADC1);
   }
My code is correct, i think. or not? How to make it work normal? I cant kill
this bug




reply via email to

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