GPRS 系统消息的处理
//Socket Notify Event indication handler framework
void oa_soc_notify_ind(void *inMsg)
{
oa_int32 ret = 0;
oa_app_soc_notify_ind_struct *soc_notify = (oa_app_soc_notify_ind_struct*) inMsg;
//if other application's socket id, ignore it.
if(soc_notify->socket_id != g_soc_context.socket_id)
{
GPRS_DEBUG("%s:sock_id=%d unknow, event_type=%d!",__func__,soc_notify->socket_id,soc_notify->event_type);
return;
}
switch (soc_notify->event_type)
{
case OA_SOC_WRITE:
{
/* Notify for send data*/
if (soc_notify->result == OA_TRUE)
{
g_soc_context.is_blocksend = OA_FALSE;
//resend the data ,else will lost data
GPRS_DEBUG("%s:sock_id=%d resend!",__func__,soc_notify->socket_id);
oa_soc_send_req( );
}
else
{
GPRS_DEBUG("%s:sock_id=%d send fail err=%d!",__func__,soc_notify->socket_id,soc_notify->error_cause);
oa_soc_close_req( );
}
break;
}
case OA_SOC_READ:
{
/* Notify for received data */
if (soc_notify->result == OA_TRUE)
{
do
{
oa_memset(gprs_rx_buffer, 0 , (OA_MAX_SOC_RCV_BUFLEN*sizeof(oa_uint8)));
//received gprs data, read data for protocol
ret = oa_soc_recv(soc_notify->socket_id , (oa_uint8*)gprs_rx_buffer, OA_MAX_SOC_RCV_BUFLEN, 0);
GPRS_DEBUG("%s:sock_id=%d read ok ret=%d!",__func__,soc_notify->socket_id,ret);
if(ret > 0)
{
// read data length=ret,
oa_soc_gprs_recv((oa_uint8*)gprs_rx_buffer, ret);
}
else
{
//read data error or block
}
}while(ret>0); //Make sure use do{...}while to read out all received data.
}
else
{
GPRS_DEBUG("%s:sock_id=%d read fail err=%d!",__func__,soc_notify->socket_id,soc_notify->error_cause);
oa_soc_close_req( );
}
break;
}
case OA_SOC_CONNECT:
{
if (soc_notify->result == OA_TRUE)
{
GPRS_DEBUG("%s:sock_id=%d connect ok!",__func__,soc_notify->socket_id);
//if connect OK, goto query gprs_tx data and send
oa_sleep(100); //just connected need delay 100ms then send gprs data, else may lost data
g_soc_context.state = OA_SOC_STATE_ONLINE;
oa_soc_send_req( );
}
else
{
GPRS_DEBUG("%s:sock_id=%d connect fail err=%d!",__func__,soc_notify->socket_id,soc_notify->error_cause);
oa_soc_close_req( );
}
break;
}
case OA_SOC_CLOSE:
{
// the socket is closed by remote server, use soc_close to close local socketID, else will lead OA_SOC_LIMIT_RESOURCE
GPRS_DEBUG("%s:sock_id=%d close,error_cause=%d",__func__,soc_notify->socket_id,soc_notify->error_cause);
oa_soc_close_req();
break;
}
case OA_SOC_ACCEPT:
break;
default:
break;
}
oa_soc_start_heartbeat_timer();
}
|