Example #1
0
static err_t
http_recv(void *arg, struct tcp_pcb *pcb, struct pbuf *p, err_t err)
{
	struct http_state *http;
	
	http = arg;

	if (err == ERR_OK && p != NULL) {

		struct pbuf *q;
		for (q = p; q; q = q->next)
			httpd_receive(http, q->payload, q->len);
		pbuf_free(p);

		/* Inform TCP that we have taken the data. */
		tcp_recved(pcb, p->tot_len);

		send_data(pcb, http);
	}

	if (err == ERR_OK && p == NULL) {
		close_conn(pcb, http);
	}
	return ERR_OK;
}
Example #2
0
int main(void) {
    struct http_state http;

    httpd_init(&http, 0);
    while (1) {
        char line[1024];
        int r = read(0, line, 1024);
        if (r < 0)
            break;
        httpd_receive(&http, line, r);
        if (http.state_server == HTTPD_SERVER_CLOSE)
            break;
    }
    return 0;
}