HTTP questions`

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

HTTP questions`

Trampas Stern
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


_______________________________________________
lwip-users mailing list
[hidden email]
https://lists.nongnu.org/mailman/listinfo/lwip-users
Reply | Threaded
Open this post in threaded view
|

Re: HTTP questions`

Trampas Stern
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 = (char *)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 <[hidden email]> 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


_______________________________________________
lwip-users mailing list
[hidden email]
https://lists.nongnu.org/mailman/listinfo/lwip-users
Reply | Threaded
Open this post in threaded view
|

Re: HTTP questions`

stuart200471
In reply to this post by Trampas Stern
Hello Trampas,
   yes, your understanding is correct...BUT the code you have shown looks
nothing like the current code.
Maybe try using the latest version of the code?
Cheers
Stuart



--
Sent from: http://lwip.100.n7.nabble.com/lwip-users-f3.html

_______________________________________________
lwip-users mailing list
[hidden email]
https://lists.nongnu.org/mailman/listinfo/lwip-users
Reply | Threaded
Open this post in threaded view
|

Re: HTTP questions`

Trampas Stern
I figured it out, as it turns out my form did not have a name for the file name field and a such chrome was not sending any data with the POST message. 

I would switch to the new code but with limited memory I have added code to parse GET request on block bases and was worried about porting changes forward.  Also I like to understand how things work, which is more important to me personally. 

Trampas

On Sun, Jan 5, 2020 at 5:53 PM stuart200471 <[hidden email]> wrote:
Hello Trampas,
   yes, your understanding is correct...BUT the code you have shown looks
nothing like the current code.
Maybe try using the latest version of the code?
Cheers
Stuart



--
Sent from: http://lwip.100.n7.nabble.com/lwip-users-f3.html

_______________________________________________
lwip-users mailing list
[hidden email]
https://lists.nongnu.org/mailman/listinfo/lwip-users

_______________________________________________
lwip-users mailing list
[hidden email]
https://lists.nongnu.org/mailman/listinfo/lwip-users