Kieran Mansley wrote:
On Wed, 2009-06-24 at 14:03 +0200, Jesper Vestergaard wrote:
what is the prober way of assembling the data from a arbitrary
number of packets?
Call netconn_recv() repeatedly and concatenate the data you get until
you have as much as you want.
Kieran
I have tried calling netconn_recv() repeatedly but a problem has
occured. I get the data fine but when i will respond to the request
with netconn_write(pxNetCon, cDynamicPage, (u16_t)strlen( cDynamicPage
), NETCONN_COPY ); no data is being sent. The code for retrieving the
data is here:
/pxNetCon->recv_timeout=20;
/* Data is ready */
pxRxBuffer = netconn_recv( pxNetCon );
pcRxString = pvPortMalloc( mem_size );
do
{
/* Where is the data? */
netbuf_data( pxRxBuffer, ( void * ) &(pcRxString2),
&usLength );
/* Allocate memory for the data */
mem_size = mem_size + usLength;
pcRxString = pvPortRealloc( pcRxString, (mem_size) );
/* In the first iteration we can copy the data as
it is */
if (mem_size == usLength)
{
memcpy(pcRxString, pcRxString2, usLength);
}
else
{
pcRxString3 = pvPortMalloc( usLength + 1 );
memcpy(pcRxString3, pcRxString2, usLength);
/* We use string functions on a char array so add a
null terminator */
pcRxString3[usLength] = '\0';
strcat( pcRxString, pcRxString3 );
vPortFree( pcRxString3 ); }
netbuf_free( pxRxBuffer );
pxRxBuffer = netconn_recv( pxNetCon );
//pxRxBuffer = NULL;
}
/* if theres is no more packets in the buffer proceed */
while (pxRxBuffer != NULL);/