Thanks Noam, I will try this and get back.

Regards
Anand

On Wed, Aug 31, 2016 at 8:30 PM, Noam Weissman <n...@silrd.com> wrote:

> Hi Anand,
>
>
>
> You said that you are creating the data on the fly into memory. You need
> to create some kind
>
> of mechanism to create the data but send in chunks. I mean that you may
> need to create a function
>
> that gets a portion of the buffer on every call to it.
>
>
>
> You call it once when you start the transmission and make more calls to it
> inside the sent call back.
>
>
>
> Let’s assume something like that …
>
>
>
> #define TX_PART_SIZE   2000
>
> #define TX_BUFF_SIZE   15000
>
>
>
>
>
> static u8 Buff[TX_BUFF_SIZE];
>
>
>
> int FillFunction(void)
>
> {
>
>   int Size;
>
>
>
>   // function fills the TX buffer and returns the number of bytes it filled
>
>
>
>   return Size;
>
> }
>
>
>
> //------------------------------------------------------------------
>
>
>
> // function to get a portion of the created data
>
> int PartToSend(bool Init, int Size, u8 *Data)
>
> {
>
>   int SendSize;
>
>   static int PartOffset = 0;
>
>   static int LeftToSend = 0;
>
>
>
>   // first buff to get also initialize local variables
>
>   if(Init == TRUE)
>
>   {
>
>     PartOffset = 0;
>
>     LeftToSend = Size;
>
>   }
>
>
>
>   // calculate size to send
>
>   if(LeftToSend > TX_PART_SIZE)
>
>   {
>
>     SendSize = TX_PART_SIZE;
>
>   }
>
>   else
>
>   {
>
>     SendSize = LeftToSend;
>
>   }
>
>
>
>   // take a pointer to data
>
>   Data = &Buff[PartOffset];
>
>
>
>   // advance indexes
>
>   PartOffset += SendSize;
>
>   LeftToSend -= SendSize;
>
>
>
>   // return current size to send
>
>   return SendSize;
>
> }
>
>
>
> //-----------------------------------------------
>
>
>
>   // in your received call back you call the following
>
>
>
>   u8 *Data;
>
>   int DataSize;
>
>
>
>   // create data and get back the size of data filed in buf
>
>   DataSize = FillFunction();
>
>
>
>   // initialize internal variables and get a pointer to first part
>
>   DataSize = PartToSend(TRUE, DataSize, Data);
>
>
>
>   // call sending function and send first part
>
>   tcp_write(...)
>
>
>
>   ,
>
>   ,
>
>   ,
>
>
>
>   // in your tcp_sent call back you do the following
>
>   // get another chank of data
>
>   DataSize = PartToSend(FALSE, 0, Data);
>
>
>
>   // call sending function and send another part
>
>   tcp_write(...)
>
>
>
>
>
> The above will create the full buffer and send 2K and exit from the
> receive call back.
>
> Further sending is done inside the sent call back function.
>
>
>
> The above assumes that you will finish sending before you get another
> receive call !
>
>
>
> Hope that helped.
>
>
>
> BR,
>
> Noam.
>
>
>
>
>
> *From:* lwip-users [mailto:lwip-users-bounces+noam=silrd....@nongnu.org] *On
> Behalf Of *anand arjunan
> *Sent:* Wednesday, August 31, 2016 4:16 PM
> *To:* Mailing list for lwIP users
> *Subject:* Re: [lwip-users] LW IP - TCP instantaneous data transmission
>
>
>
> Hi Noam,
>
>
>
> This is an existing implementation and cannot move to other implementation
> right away. I am adding new features to it with a memory constraint. :-( So
> far the page size was small and the entire page was buffered in the memory
> and sent at one shot once the call back function is out. Now, I don't have
> the luxury of huge memory and hence have to construct the page in sections
> and send them to client as and when they are constructed.
>
>
>
> Thanks
>
> Anand
>
>
>
> On Wed, Aug 31, 2016 at 3:58 PM, Noam Weissman <n...@silrd.com> wrote:
>
> Hi,
>
>
>
> Before you start re-inventing the wheel why not take a readymade HTTP
> server ?
>
>
>
> You have a basic good HTTP server in the lwIP contribution or similar that
> runs in RAW API.
>
>
>
> BR,
>
> Noam.
>
>
>
> *From:* lwip-users [mailto:lwip-users-bounces+noam=silrd....@nongnu.org] *On
> Behalf Of *anand arjunan
> *Sent:* Wednesday, August 31, 2016 12:18 PM
> *To:* lwip-users@nongnu.org
> *Subject:* [lwip-users] LW IP - TCP instantaneous data transmission
>
>
>
> Hi,
>
>
>
> I am using LWIP (Raw TCP mode) (in FreeRTOS) for handling http page
> requests, construct the web page and send the page to the client. I have
> set the TCP_SND_BUF as 8*TCP_MSS where TCP_MSS is 1460. There will be only
> one client / browser connecting to the system at a time.
>
>
>
> In the receive call back function, I constructed the entire web page and
> used the tcp_write () (with TCP_WRITE_FLAG_COPY ) to send the data to LWIP
> buffer. Due to memory limitations, I have to reuse a buffer size of 2.5 K
> to construct the page before writing it to LWIP using tcp_write () as the
> actual page size to be sent to client is more than 14 K. I was thinking
> that as and when I call tcp_output () the data would be
> sent instantaneously to the client. But, I got to know that tcp_Output()
> does not work in the callback function and LWIP will start sending the
> packets automatically once the control is out of the callback function.
>
>
>
> Due to this limitation I slightly modified the design. I have made the
> actual LWIP receive callback to just set another (second) callback function
> so that the actual LWIP callback would return immediately (so that
> tcp_output( ) can work). The second callback would actually construct the
> page and would be invoked by http_poll function or some other timer.
>
>
>
> Even this does not work. It still accumulates the data worth of of 8*1460
> bytes fully and sends only that much to the client. Once the buffer is
> full, tcp_sndbuf(pcb) returns zero and I cannot write anymore to it. I
> thought this would return non zero value as I am calling tcp_output ( )
> outside the LWIP calling function using a timer function.
>
>
>
> I tried disabling the nagle's algorithm using tcp_nagle_disbale( ) before
> transmitting the packets. That did not help either.
>
>
>
> I want the data to be sent to the client (without accumulating) as and
> when I call tcp_output( ) because of the limitation that I can construct
> only 2.5 K bytes of page at a time and reuse it to construct the next
> section of the page.
>
>
>
> Please help. Any help / pointers would be appreciated.
>
>
>
> Thanks
>
> LWIP_Starter
>
>
> _______________________________________________
> lwip-users mailing list
> lwip-users@nongnu.org
> https://lists.nongnu.org/mailman/listinfo/lwip-users
>
>
>
> _______________________________________________
> lwip-users mailing list
> lwip-users@nongnu.org
> https://lists.nongnu.org/mailman/listinfo/lwip-users
>
_______________________________________________
lwip-users mailing list
lwip-users@nongnu.org
https://lists.nongnu.org/mailman/listinfo/lwip-users

Reply via email to