lwip-users
[Top][All Lists]
Advanced

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

Re: Re: [lwip-users] Problem with multi file sending http server


From: Mariusz Dz
Subject: Re: Re: [lwip-users] Problem with multi file sending http server
Date: Thu, 25 Nov 2010 17:57:59 +0100

>Can you show us the actual code?

static err_t
http_recv(void *arg, struct tcp_pcb *pcb, struct pbuf *p, err_t err)
{
        //some variables
        hs = arg;
        if (err == ERR_OK && p != NULL)
        {
                /* Inform TCP that we have taken the data. */
                tcp_recved(pcb, p->tot_len);
                //if(hs->file == NULL)
                {
                        data = p->payload;
                        pbuf_free(p);

                        if (strncmp(data, "GET ", 4) == 0)
                        {
                                fresult_open = 1;
                                if (strncmp(data, "GET /css/style.css", 18)
== 0)
                                {
                                        fresult_open = f_open
(&plik,"www/css/style.css", FA_READ);
                                }
                                //and some more open files like above
                                else
                                {
                                        close_conn(pcb, hs);
                                }

                                if(fresult_open == 0)
                                {
                                        fresult_read = f_read (&plik, dane,
10000, &zapisanych_bajtow);
                                        fresult = f_close (&plik);

                                        hs->file = wsk_dane;
                                        hs->left = zapisanych_bajtow;

                                        send_data(pcb, hs);

                                        //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);
                                        tcp_output(pcb);//dont change if the
problem is or not
                                }
                        }
                        else
                        {close_conn(pcb, hs);}
                }
                else
                {pbuf_free(p);}
        }

        if (err == ERR_OK && p == NULL)
                {close_conn(pcb, hs);}
  
        return ERR_OK;
}

send_data(struct tcp_pcb *pcb, struct http_state *hs)
{
  err_t err;
  u16_t len;

  /* We cannot send more data than space avaliable in the send
     buffer. */
  if (tcp_sndbuf(pcb) < hs->left)
  {
    len = tcp_sndbuf(pcb);
  }
  else
  {
    len = hs->left;
  }

  err = tcp_write(pcb, hs->file, len, TCP_WRITE_FLAG_COPY); //was 0 in place
TCP_WRITE_FLAG_COPY

  if (err == ERR_OK)
  {
    hs->file += len;
    hs->left -= len;
  }
}

I think that most important code

>> About the 3. question i mean how make that i dont have to read all
>> file at
>> onec from sd card, but read some data, half file, send it the rest of
>> file
>> and it will be  treated as one file.
>
>Just call tcp_write() repeatedly with the next block of data that you've
>read.

Dosent matter what flags will be set on position apiflags? 


------------------------------------------------------
Mieszkania, domy, działki - najlepsze oferty!
http://linkint.pl/f284d




reply via email to

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