lwip-users
[Top][All Lists]
Advanced

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

Re: [lwip-users] HTTP questions`


From: Trampas Stern
Subject: Re: [lwip-users] HTTP questions`
Date: Mon, 23 Dec 2019 16:15:26 -0500

I think I am missing some key understanding.  I have the http_recv() function and assume that the when call  tcp_recved() it will ACK the TCP packet. So for a POST which spans multiple packets the first packet contains the "POST " string, and then I am expecting after calling tcp_recved(), I will get another call to http_recv() with the next packet in the POST message. 

Is this correct or am I missing something?

Thanks
Trampas



static err_t http_recv(void *arg, struct tcp_pcb *pcb, struct pbuf *p, err_t err)
{
int i;
char *data;
struct fs_file file;
struct http_state *hs;
char fileName[128]={0};
char buffer[MAX_JSON_LEN];

hs = (struct http_state *) arg;
WARNING("ACCEPT Connection %d",pcb->remote_port);

if (err == ERR_OK && p != NULL) {
/* Inform TCP that we have taken the data. */
tcp_recved(pcb, p->tot_len);
WARNING("Len %d",p->tot_len);
printLong((char *)p->payload,p->tot_len);

if (hs->ptrData == NULL && hs->fname[0] == 0 && hs->packet_num == 0)
{
data = "" *)p->payload;

if (strncmp(data, "GET ", 4) == 0)
{
hs->packet_num++;
LOG("GET");
process_get(hs,pcb,p);
pbuf_free(p);
}
else if (strncmp(data, "POST ", 5) == 0)
{
hs->packet_num++;
LOG("POST");
process_post(hs,pcb,p);
pbuf_free(p);
}else
{
LOG("Recieved %d %d",p->len,p->tot_len);
pbuf_free(p);
WARNING("Unknown Connection, closing %d",pcb->remote_port);
http_close_conn(pcb, hs);
}
} else {
pbuf_free(p);
}
}

if (err == ERR_OK && p == NULL) {
WARNING("Connection closed %d",pcb->remote_port);
http_close_conn(pcb, hs);
}

return ERR_OK;
}

On Mon, Dec 23, 2019 at 11:45 AM Trampas Stern <address@hidden> wrote:
I am using a httpd.c example code from an old version of LWIP.  I am working to understand a few things and could use some help. 

From what I understand when a new connection happens the http_accept() function is called:

pcb = tcp_new();
tcp_bind(pcb, IP_ADDR_ANY, 80);
pcb = tcp_listen(pcb);
tcp_accept(pcb, http_accept);

In the http_accept() we setup the callback to the call http_recv() when a packet comes in. 
/* Tell TCP that we wish to be informed of incoming data by a call
to the http_recv() function. */
tcp_recv(pcb, http_recv);
tcp_err(pcb, http_conn_err);
tcp_poll(pcb, http_poll, 8);

So when I send a file via POST, I am getting a call to http_recv for the first packet of data.  However since the file is bigger than the TCP/IP buffer I assume http_recv() would be called again for the next packet and I do not seem to get a second call to the http_recv().  I was wondering if I was missing something?

Thanks
Trampas


reply via email to

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