lwip-users
[Top][All Lists]
Advanced

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

Re: [lwip-users] Freeing memory after http transfer


From: Bernhard 'Gustl' Bauer
Subject: Re: [lwip-users] Freeing memory after http transfer
Date: Thu, 12 Nov 2009 13:36:41 +0100
User-agent: Thunderbird 2.0.0.23 (Windows/20090812)

Simon Goldschmidt schrieb:
You did the correct thing, tcp_sent should do the trick. If not,
that's a bug (either in lwIP, the way you are using it, or in your
code or port) which needs to be analysed.

I have expanded the httpserver_raw from the contribs. The basic functions are alike. In http_recv() I collect all incomming packets and process them. if afterwards there is a file to be sent I do this:

if (hs->file==NULL) {
        close_conn(pcb, hs);
} else {
/* Tell TCP that we wish be to informed of data that has been
   successfully sent by a call to the http_sent() function. */
        tcp_sent(pcb, http_sent);
//      send_data(pcb, hs);
        send_head(pcb, hs);
}

send_head() is like send_data() and sends the header in a separate packet:

static void send_head(struct tcp_pcb *pcb, struct http_state *hs){
  err_t err;
  u16_t len;

  /* We cannot send more data than space available in the send
     buffer. */
  if (tcp_sndbuf(pcb) < hs->file_head_len) {
        LWIP_ERROR("send_head: HTTP header to big!",1,;);
  } else {
    len = hs->file_head_len;
  }
  do {
      err = tcp_write(pcb, hs->file_head, len, 0);
    if (err == ERR_MEM) {
      len /= 2;
    }
  } while (err == ERR_MEM && len > 1);
}

This is my http_sent function:
static err_t http_sent(void *arg, struct tcp_pcb *pcb, u16_t len){
  struct http_state *hs;

  LWIP_UNUSED_ARG(len);
  hs = arg;
  hs->retries = 0;

  if (hs->left > 0) {
    send_data(pcb, hs);
  } else {
    close_conn(pcb, hs);
    if (send_qyb==1) {
        send_qyb=0;
// This is what erases the data in the last packet
//      clear_audio_vars();
//      irq_stop3=0;
     }
  }

  return ERR_OK;
}

I would be glad for any pointers how to trace this problem.

TIA

Gustl




reply via email to

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