📄 cms_wtp.c
字号:
static CMS_S8 deduce_pdu_type(CMS_U8 octet)
{
CMS_U32 type = (octet>>3)&0x0f;
if (type > 7)
{
return -1;
}
else
{
return type;
}
}
static WTPEvent *unpack_result(CMS_S64 tid, Msg *msg)
{
WTPEvent * event ;
event = wtp_event_create(RcvResult);
event->RcvResult.tid = tid;
event->user_data =
octstr_copy( msg->wdp_datagram.user_data, 3L, octstr_len(msg->wdp_datagram.user_data) - 3 );
return event ;
}
/*--Shawn 2002-12-25*/
static WTPEvent *unpack_invoke(CMS_S64 tid, Msg *msg)
{
WTPEvent * event ;
event = wtp_event_create(RcvResult);
event->RcvResult.tid = tid;
event->user_data =
octstr_copy( msg->wdp_datagram.user_data, 4L, octstr_len(msg->wdp_datagram.user_data) - 3 );
return event ;
}
/*2003.8.19*/
static WTPEvent *unpack_ack(CMS_S64 tid, CMS_U8 octet,CMS_U8 psn)
{
WTPEvent *event;
CMS_U8 this_octet;
event = wtp_event_create(RcvAck);
event->RcvAck.tid = tid;
this_octet = octet;
event->RcvAck.tid_ve = (this_octet>>2)&1;
this_octet = octet;
event->RcvAck.rid = this_octet&1;
event->RcvAck.psn = psn;
return event;
}
WTPEvent *unpack_abort(Msg *msg, CMS_S64 tid, CMS_U8 first_octet, CMS_U8 fourth_octet)
{
WTPEvent *event;
CMS_U8 abort_type;
event = wtp_event_create(RcvAbort);
abort_type = first_octet&7;
event->RcvAbort.tid = tid;
if (abort_type > 1 || fourth_octet > NUMBER_OF_ABORT_REASONS)
{
return event;
}
event->RcvAbort.abort_type = abort_type;
event->RcvAbort.abort_reason = fourth_octet;
return event;
}
////////macro action///////////////
//@
static void RcvSegResult_Action(WTPMachine *machine,WTPEvent *event)
{
static int times = 0;
WTPEvent *new_event= NULL;
times++;
if( times % 11 == 0 )
{
//cms_watchdog();
times = 0;
}
#ifdef __CMS_TOOLKIT__
{
int dataOffset=0;
dataOffset=cmsGetPackageOffset((unsigned char)WTPGlobalMachine->psn);
if(!machine->seg_pdu)
{
machine->seg_pdu=octstr_create_empty();
if(machine->recv_msgsize >0)
{
machine->seg_pdu->data = (unsigned char *)malloc(machine->recv_msgsize+2000);
machine->seg_pdu->size = machine->recv_msgsize+2000;
memset(machine->seg_pdu->data,0,machine->seg_pdu->size);
}
else
{
machine->seg_pdu->data = (unsigned char *)malloc(DEFAULT_WTP_SIZE);
machine->seg_pdu->size = DEFAULT_WTP_SIZE;
memset(machine->seg_pdu->data,0,machine->seg_pdu->size);
}
}
if(event->user_data)
{
int ret = 0;
ret = octstr_insert_data(machine->seg_pdu,dataOffset-event->user_data->len,event->user_data->data,event->user_data->len);
if(ret <0)
{
octstr_destroy(machine->seg_pdu);
machine->seg_pdu = NULL;
goto err;
}
}
}
#else
if(WTPGlobalMachine->seg_pdu != NULL && event->user_data != NULL )
octstr_append_data(WTPGlobalMachine->seg_pdu,event->user_data->data,event->user_data->len);
#endif
WTPRCR = 0;
wtp_timer_start(&WTPGlobalTimer[1],L_R_WITHOUT_USER_ACK);
if(event->RcvSegResult.gtr_ttr == 0x0)
{
#ifdef __CMS_TOOLKIT__
if(WTPGlobalMachine->get_first && WTPGlobalMachine->get_last && cmsIfGetAll())
{
#ifdef __SELECTIVE_RETRANSMISSION__
if(cmsIfPackageContinuous())
{
Octstr stpi;
unsigned char psn = 0;
wtp_timer_stop( &WTPGlobalTimer[3] );
WTPNACK = 0;
memset(&stpi,0,sizeof(stpi));
psn = (unsigned char)cmsGetMaxPackageNum();
stpi.data = &psn;
stpi.len = 1;
wtp_send_ack(0,WTPGlobalMachine,new_event,1,0x03,&stpi);
}
#endif
new_event = wtp_event_create(RcvResult);
//new_event->RcvResult.seg_result_head = 0; /*--Shawn 2002-12-24*/
new_event->RcvResult.tid = machine->tid;
new_event->RcvResult.gtr_ttr = 0x01;
new_event->user_data = WTPGlobalMachine->seg_pdu;
WTPGlobalMachine->seg_pdu = NULL;
wtp_handle_event(WTPGlobalMachine,new_event);
}
else if(wtp_timer_timeleft(&WTPGlobalTimer[3]) > 0 )
{
if(cmsIfPackageContinuous())
{
Octstr stpi;
unsigned char psn = 0;
#ifdef __SELECTIVE_RETRANSMISSION__
if(cmsIfPackageContinuous())
{
wtp_timer_stop( &WTPGlobalTimer[3] );
WTPNACK = 0;
}
#endif
psn = (unsigned char)cmsGetMaxPackageNum();
memset(&stpi,0,sizeof(stpi));
stpi.data = &psn;
stpi.len = 1;
//wtp_timer_stop( &WTPGlobalTimer[3] );
wtp_send_ack(0,WTPGlobalMachine,NULL,1,0x03,&stpi);
}
}
//else
// Cms_UDPInput();
#endif
return;
}
else if(event->RcvSegResult.gtr_ttr == 0x02) /*the last packet in a group*/
{
////cms_trace("access RcvSegResult_Action: event->RcvSegResult.gtr_ttr == 0x02\n" );
////cms_trace("access RcvSegResult_Action: event->RcvSegResult.gtr_ttr == 0x02\n" );
////cms_trace("access RcvSegResult_Action: event->RcvSegResult.gtr_ttr == 0x02\n" );
////cms_trace("access RcvSegResult_Action: event->RcvSegResult.gtr_ttr == 0x02\n" );
////cms_trace("access RcvSegResult_Action: event->RcvSegResult.gtr_ttr == 0x02\n" );
////cms_trace("access RcvSegResult_Action: event->RcvSegResult.gtr_ttr == 0x02\n" );
////cms_trace("access RcvSegResult_Action: event->RcvSegResult.gtr_ttr == 0x02\n" );
////cms_trace("access RcvSegResult_Action: event->RcvSegResult.gtr_ttr == 0x02\n" );
#ifdef __SELECTIVE_RETRANSMISSION__
if(cmsIfPackageContinuous())
{
Octstr stpi;
unsigned char psn = 0;
#ifdef __SELECTIVE_RETRANSMISSION__
if(cmsIfPackageContinuous())
{
wtp_timer_stop( &WTPGlobalTimer[3] );
WTPNACK = 0;
}
#endif
memset(&stpi,0,sizeof(stpi));
psn = (unsigned char)cmsGetMaxPackageNum();
stpi.data = &psn;
stpi.len = 1;
wtp_send_ack(0,WTPGlobalMachine,new_event,1,0x03,&stpi); /*--Shawn 2003-01-04*/
}
else
{
//发NACK
//wtp_send_nack(machine);
wtp_timer_start(&WTPGlobalTimer[3],NACK_TIMER_EXPIRE);
WTPNACK = 0;
wtp_timer_stop(&WTPGlobalTimer[1]); //timer动了
}
#else
wtp_send_ack(0,WTPGlobalMachine,new_event,1,0x03,tpi); /*--Shawn 2003-01-04*/
octstr_destroy(tpi);
tpi = NULL;
#endif
#ifdef __CMS_TOOLKIT__
if(WTPGlobalMachine->get_first && WTPGlobalMachine->get_last && cmsIfGetAll())
{
new_event = wtp_event_create(RcvResult);
//new_event->RcvResult.seg_result_head = 0; /*--Shawn 2002-12-24*/
new_event->RcvResult.tid = machine->tid;
new_event->RcvResult.gtr_ttr = 0x01;
new_event->user_data = WTPGlobalMachine->seg_pdu;
WTPGlobalMachine->seg_pdu = NULL;
wtp_handle_event(WTPGlobalMachine,new_event);
}
//else
//Cms_UDPInput();
//#else
//Cms_UDPInput();
#endif
#ifdef DOPOD_TEST
Cms_WinRecvPDU();
#endif
return;
}
else if(event->RcvSegResult.gtr_ttr == 0x01) /*the last packet*/
{
Octstr stpi;
unsigned char psn = 0;
memset(&stpi,0,sizeof(stpi));
psn = (unsigned char)event->RcvSegResult.psn;
stpi.data = &psn;
stpi.len = 1;
#ifdef __SELECTIVE_RETRANSMISSION__
if(cmsIfPackageContinuous())
{
wtp_send_ack(0,WTPGlobalMachine,new_event,1,0x03,&stpi); /*--Shawn 2003-01-04*/
}
else
{
//发NACK
//wtp_send_nack(machine);
wtp_timer_start(&WTPGlobalTimer[3],NACK_TIMER_EXPIRE);
wtp_timer_stop(&WTPGlobalTimer[1]); //timer动了
}
#else
wtp_send_ack(0,WTPGlobalMachine,new_event,1,0x03,tpi); /*--Shawn 2003-01-04*/
octstr_destroy(tpi);
tpi = NULL;
#endif
#ifdef __CMS_TOOLKIT__
if(WTPGlobalMachine->get_first && WTPGlobalMachine->get_last && cmsIfGetAll())
{
new_event = wtp_event_create(RcvResult);
//new_event->RcvResult.seg_result_head = 0; /*--Shawn 2002-12-24*/
new_event->RcvResult.tid = machine->tid;
new_event->RcvResult.gtr_ttr = 0x01;
new_event->user_data = WTPGlobalMachine->seg_pdu;
WTPGlobalMachine->seg_pdu = NULL;
wtp_handle_event(WTPGlobalMachine,new_event);
}
#else
new_event = wtp_event_create(RcvResult);
//new_event->RcvResult.seg_result_head = 0; /*--Shawn 2002-12-24*/
new_event->RcvResult.tid = machine->tid;
new_event->RcvResult.gtr_ttr = 0x01;
new_event->user_data = WTPGlobalMachine->seg_pdu;
WTPGlobalMachine->seg_pdu = NULL;
wtp_handle_event(WTPGlobalMachine,new_event);
#endif
}
/*else
{
//cms_debug("Error!%s\n","Impossible!");
}*/
return;
err:
{
WTPEvent * wtp_event= NULL;
WSPEvent *wsp_event = NULL;
wtp_event = wtp_event_create( TRAbort );
wtp_event->TRAbort.tid = machine->tid;
wtp_event->TRAbort.abort_type = PROVIDER ;
wtp_event->TRAbort.abort_reason = WTPPROTOERR ;
wtp_handle_event(WTPGlobalMachine,wtp_event);
wsp_event = pack_wsp_event(TRAbortIndication, wtp_event, machine);
wsp_event->TRAbortIndication.abort_code = WSP_ABORT_PROERR;
wsp_dispatch_event( machine, wsp_event);
}
}
static void null_trir_allsend_rw(WTPMachine *machine,WTPEvent *event)
{
WTPEvent * new_event = NULL;
////cms_debug("WTP STATUS:%sWTP_NULL-->TRInvokeRequire-->allsend-->WTP_RESULT_WAIT\n","");
////CmsDebugFunc((unsigned char*)"8880010",(short)0,(void*)NULL);
if(machine)//xiaomingp
{
machine->get_first = 0;
machine->get_last = 0;
machine->psn = 0;
}
machine->u_ack = event->TRInvokeRequire.ack_type;//e->ack_type;
// WTPUserAck = (CMS_S32)machine->u_ack;
machine->tcl = event->TRInvokeRequire.tcl;//e->tcl;
// machine->rid = 0;
new_event = wtp_event_create( RcvInvoke );
new_event->user_data = octstr_duplicate(event->user_data);
new_event->RcvInvoke.tcl = event->TRInvokeRequire.tcl;//e->tcl;
new_event->RcvInvoke.tid = machine->tid = wtp_tid_next();
new_event->RcvInvoke.up_flag = 0x01;//ent->TRInvokeRequire.ack_type;//e->ack_type;//2003.4.8
//new_event->RcvInvoke.seg_seq = 0;
if(machine->InvokeEvent)
{
wtp_event_destroy(machine->InvokeEvent);
machine->InvokeEvent = NULL;
}
mms_StartTimer(WTPGlobalMachine->timer_id,1000);//修改定时器
wtp_timer_start(&WTPGlobalTimer[1],L_R_WITHOUT_USER_ACK);//2003.8.19
machine->InvokeEvent = new_event;
//2003.10.30
if(redirect_host[0]&&redirect_port != 0)
{
memcpy(WTPGlobalMachine->udp_host,redirect_host,sizeof(redirect_host));
WTPGlobalMachine->udp_port = (int)redirect_port;
}
wtp_all_send_invoke( machine, new_event );
WTPRCR = 0;
#ifdef YQB
Cms_UDPInput();
#endif
#ifdef DOPOD_TEST
Cms_WinRecvPDU();
#endif
return ;
}
static void null_trir_segsend_rw(WTPMachine *machine,WTPEvent *event)
{
WTPEvent * new_event = NULL;
////cms_debug("WTP STATUS:WTP_NULL-->TRInvokeRequire-->segsend-->WTP_RESULT_WAIT%s\n","");
////CmsDebugFunc((unsigned char*)"8880011",(short)0,(void*)NULL);
machine->u_ack = event->TRInvokeRequire.ack_type;//e->ack_type;
// WTPUserAck = (CMS_S32)machine->u_ack;
machine->tcl = event->TRInvokeRequire.tcl;//e->tcl;
// machine->rid = 0;
new_event = wtp_event_create( RcvInvoke );
//new_event->user_data = octstr_duplicate(event->user_data);
new_event->user_data = event->user_data;
new_event->big_data = event->big_data; //2003.9.2
event->user_data = NULL;
event->big_data = NULL;
new_event->RcvInvoke.tcl = event->TRInvokeRequire.tcl;//e->tcl;
new_event->RcvInvoke.tid = machine->tid = wtp_tid_next();
new_event->RcvInvoke.up_flag = 0x01;//event->TRInvokeRequire.ack_type;//e->ack_type;//2003.4.8
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -