TCP Server wip_read()

Good afternoon.
Somebody can advise
Question
For the beginning code

void commHandler( wip_event_t *ev, void *ctx)
 {
        u8 *DataRead[16];
        ................

         switch( ev->kind) 
        {
               case WIP_CEV_OPEN:
                        .....
                 break;
         case WIP_CEV_READ:
         TRACE((1,"%d",ev->content.read.readable)); // ev->content.read.readable  - return "0"
         Read=wip_read(ev->channel,DataRead, ev->content.read.readable); 
                               // wip_read() return "-944",  DataRead - is empty 
................

If string Read=wip_read(ev->channel,DataRead, ev->content.read.readable); chang to
Read=wip_read(ev->channel,DataRead, sizeof(DataRead));
then wip_read() returns the size the received data, and DataRead -has the correct information.
Why ev->content.read.readable returns zero ?
How else to know the size the received data?
Where can I find a detailed description of wip_event_t? (In the “1-WIP_Open_AT_IP_Connectivity_Development_Guide” description missing).
Thank.

Hiya,

You don’t know the size of data available until you’ve started reading. For example, if you’re reading a large (greater than 1492 byte) data file you’re going to continue to get packets of data until the transaction is complete (i.e. the socket is closed by the other end) or the socket read fails. So you have to read the data in chunks and be able to deal with it on a read by read basis.

sizeof(DataRead) indicates to the wip_read() function how much space you have made available to copy data from the wip buffer to your buffer - i.e. the MAXIMUM amount of data you can accept at any one time. BTW, you should have allocated your DataRead buffer BEFORE calling wip_read() - wip_read() doesn’t do any memory allocation - or you’re going to end up with a memory overrun exception of some kind.

You keep reading data until the value returned by wip_read() (which is the actual count of bytes copied into your buffer) is less than the size of your buffer ( sizeof(DataRead) ). This indicates that htere’s no more data available in the internal WIP buffers - but the read() may not be complete - that’s up to you to determine according to the protocol that you are using.

Finally, you can have a look in the header files for more info about what’s in various structures.

ciao, Dave

Good afternoon.

This example is taken from “AirPrime___Open_AT_Tutorial___Rev1.0.pdf”

/*Identifer for the bearer*/
wip_bearer_t Br_Id;
/* Channel identifier */
wip_channel_t Channel; /*Channel for the Server*/
wip_channel_t Client_Channel; /*Channel ID for the Client spawned*/
/*Control Handler for the Client socket spawned*/
void TCP_Handler(wip_event_t *Event,void *ctx)
{
u32 Read;
[b]ascii *Data_Buffer;[/b]
u32 Write;
TRACE (( 1, "Inside TCP_Handler"));
Client_Channel = Event->channel;
switch(Event->kind)
{
case WIP_CEV_READ:
[b]Data_Buffer  = adl_memGet((Event->content.read.readable+1));[/b]
wm_memset(Data_Buffer,0x00,Event->content.read.readable);
TRACE (( 1, "Inside WIP_CEV_READ"));
/*Read the data send by the remote party */
Read = wip_read(Client_Channel,Data_Buffer, Event->content.read.readable);
TRACE (( 1, "Data recevied: %d",Read));
*(Data_Buffer+Read) ='\0';
if(Read>0)
{
/*Send the data read to the external application*/
adl_atSendResponsePort(ADL_AT_UNS, ADL_PORT_UART1,Data_Buffer);
adl_atSendResponsePort(ADL_AT_UNS, ADL_PORT_UART1,"\r\n");
}
[b]_adl_memRelease(&Data_Buffer);[/b]
break;
case WIP_CEV_WRITE:
TRACE (( 1, "Inside WIP_CEV_WRITE"));
break;
case WIP_CEV_OPEN:
TRACE (( 1, "Inside WIP_CEV_OPEN"));
/*Client is conneted to the server, send the test data*/
Write = wip_write(Client_Channel,"This is a test data",19);
break;
case WIP_CEV_PEER_CLOSE:
TRACE (( 1, "Inside WIP_CEV_PEER_CLOSE"));
break;
}
}

Data_Buffer = adl_memGet((Event->content.read.readable+1)); - memory for the buffer is allocated is dynamically.
I want to implement is the same thing.
вот мой код

static void editPort ( wip_event_t *ev, void *ctx )
{
	//adl_fcmFlow_e e;
	u32 Read;
	u8 *DataRead[16];
	ascii DataWrite[50];
	TRACE ((1,"Client %d event",ev->channel));
	switch (ev->kind)
	{
		case WIP_CEV_DONE:
			TRACE ( ( ERROR_TRACE_LEVEL, "WIP_CEV_DONE" ) );
		break;
		case WIP_CEV_ERROR:
			TRACE ( ( ERROR_TRACE_LEVEL, "WIP_CEV_ERROR" ) );
		break;
		case WIP_CEV_OPEN:
			TRACE ( ( ERROR_TRACE_LEVEL, "WIP_CEV_OPEN" ) );
		//	adl_fcmSwitchV24State (UARTHandle, ADL_FCM_V24_STATE_DATA);
			wm_sprintf(DataWrite,"HELLO %d", (int)ev->channel);
			//DataWrite=
					wm_strcat(DataWrite,"\0");
			wip_write(ev->channel,DataWrite,wm_strlen(DataWrite));
		break;
		case WIP_CEV_PEER_CLOSE:
			TRACE ( ( ERROR_TRACE_LEVEL, "WIP_CEV_PEER_CLOSE" ) );
		//	adl_fcmSwitchV24State (UARTHandle, ADL_FCM_V24_STATE_AT);
		break;
		case WIP_CEV_PING:
			TRACE ( ( ERROR_TRACE_LEVEL, "WIP_CEV_PING" ) );
		break;
		case WIP_CEV_READ:
			TRACE ( ( ERROR_TRACE_LEVEL, "WIP_CEV_READ" ) );
			TRACE((1,"%d",ev->content.read.readable));
			//DataRead  = adl_memGet((ev->content.read.readable+1));
			//wm_memset(DataRead,0x00,ev->content.read.readable);
			[b]TRACE((1,"ev->channel %d , ev->content.read.readable %d",ev->channel, ev->content.read.readable));
			TRACE((1,"ev->content.done.aux %d , ev->content.done.result %d",ev->content.done.aux, ev->content.done.result));[/b]
			[b]TRACE((1,"ev->kind %d , ev->content.read %d",ev->kind, ev->content.read));[/b]
			//TRACE((1,"ev->channel %d , ev->content.read.readable %d",ev->channel, ev->content.));
			Read=wip_read(ev->channel,DataRead, sizeof(DataRead));//ev->content.read.readable);
			switch (Read)
			{
			case WIP_CERR_CSTATE:
				TRACE ((1,"WIP_CERR_CSTATE= %d",Read));
			break;
			case WIP_CERR_NOT_SUPPORTED:
				TRACE ((1,"WIP_CERR_NOT_SUPPORTED= %d",Read));
			break;
			default:
				[b]TRACE ((1,"Read= %d",Read));[/b]
				TRACE((1,(ascii *)DataRead));
				*(DataRead+Read) ='\0';
				TRACE((1,(ascii *)DataRead));
				//adl_fcmSendData (UARTHandle,(u8 *) DataRead, (ev->content.read.readable+1));
				adl_atSendResponse(ADL_AT_RSP,(ascii *)DataRead);
			break;
			}
			//adl_memRelease(DataRead);
		break;
		case WIP_CEV_WRITE:
			TRACE ( ( ERROR_TRACE_LEVEL, "WIP_CEV_WRITE" ) );
		break;
		default:
			TRACE ( ( ERROR_TRACE_LEVEL, "Unknown event ev->kind" ) );
		break;
	}
}

This is the result of code:
2014/03/27;08:45:53:340;001;ADL;1;Client 403753464 event
2014/03/27;08:45:53:340;002;ADL;1;WIP_CEV_OPEN
2014/03/27;08:45:53:340;004;ADL;1;WIP_CEV_WRITE
2014/03/27;08:45:53:340;005;ADL;1;Read= -994
2014/03/27;08:45:53:340;006;ADL;1;HELLO 403753464
2014/03/27;08:46:13:769;001;ADL;1;Client 403753464 event
2014/03/27;08:46:13:769;002;ADL;1;WIP_CEV_READ
2014/03/27;08:46:13:769;003;ADL;1;0
2014/03/27;08:46:13:769;004;ADL;1;ev->channel 403753464 , ev->content.read.readable 0
2014/03/27;08:46:13:769;005;ADL;1;ev->content.done.aux 0 , ev->content.done.result 0
2014/03/27;08:46:13:769;006;ADL;1;ev->kind 5 , ev->content.read 0
2014/03/27;08:46:13:769;007;ADL;1;Read= 9

2014/03/27;08:46:13:769;008;ADL;1;123456789a&

Over this and have any question
Why ev->content.read.readable returns zero ?
Where can I find a detailed description of wip_event_t? (In the “1-WIP_Open_AT_IP_Connectivity_Development_Guide” description missing).
Thank.