lwip-users
[Top][All Lists]
Advanced

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

Re: [lwip-users] Receving file from web server using raw TCP


From: Sergio R. Caprile
Subject: Re: [lwip-users] Receving file from web server using raw TCP
Date: Fri, 15 Jan 2016 09:33:53 -0300
User-agent: Mozilla/5.0 (Windows NT 5.1; rv:38.0) Gecko/20100101 Thunderbird/38.5.1

Hi Andy,
you will receive many calls to your callback function, they may or may
not be TCP_MSS bytes long, because that depends on how TCP will handle
the connection with its partner, and you free its memory to do so. One
thing we can know for sure, they won't be longer than that, but they can
be shorter.
You are supposed to tell the stack you are done with the pbuf it handled
to you, so it can be freed and acked to the other end and more can come.
Take a look at a known to work application, it should work OK if your
port has been correctly configured, and you'll know how to handle
incoming data. You need to configure lwipopts.h to your memory capacity.
Also, bear in mind that a pbuf is actually a linked list of pbufs, so
you need to travel it to get the info, but you'll free the first one.
You may or may not receive a single pbuf, it depends on memory
conditions when the stack puts a received frame to memory, and that is
the job of the layer-2 driver, which you should validate by running
known to work applications and a known to work lwip port for your hardware.
Going back to TCP, a typical receive callback is something like this:

        if ((p == NULL) || (err != ERR_OK)){
                printf("Connection closed by remote end\n");
                myclose(pcb);
                return ERR_OK;
        }
        if(willreject){
                return ERR_ABRT;
        }
        len = p->tot_len;
        pbuf_copy_partial(p, buffer, p->tot_len, 0);
        tcp_recved(pcb, p->tot_len);    // send ACK
        // work with buffer
        pbuf_free(p);                   // free memory
        return ERR_OK;

The "myclose()" function is not a simple call to tcp_close(pcb) because
it may fail and you need to retry later by means of the poll callback or
your own method.



reply via email to

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