?? cmpp.c
字號:
SetEvent(cent->hDeliverEvent, -10);
sleep(2);
DestroyEvent(cent->hAvailEvent);
DestroyEvent(cent->hRespEvent);
DestroyEvent(cent->hDeliverEvent);
return;
}
void cmpp_type_init (VTASK * type)
{
CmppEntity * cent = NULL;
cent = (CmppEntity *)type->var;
setSize (type, sizeof(CmppCon));
setEntitySize (type, sizeof(CmppEntity));
setConnCount (type, MAX_PCON);
setConnInit (type, cmppcon_init);
setConnDestruct (type, cmppcon_destruct);
setEntityInit (type, cmppent_init);
setEntityDestruct (type, cmppent_destruct);
setBody (type, cmpp_schedule);
setIdleState (type, cmpp_null);
setServiceState (type, cmpp_ready);
return;
}
void cmpp_schedule (MESSAGE * msg)
{
char selector = 0;
ITEM_TYPE item = 0;
VTASK * vtask = NULL;
VTASK * entity = NULL;
CmppEntity * cmcent = NULL;
CmppCon * cmcon = NULL;
CmppBlock * block = NULL;
int num = 0;
SubmitPending * subitem = NULL;
if (!msg || !msg->dest)
return;
selector = msg->primitive.selector;
item = msg->primitive.item;
entity = msg->dest;
cmcent = (CmppEntity *)entity->var;
if (selector == UP) {
block = (CmppBlock *)msg->parameters;
} else if (selector == TIMEOUT) {
vtask = entity;
cmcon = (CmppCon *) vtask->var;
entity = (VTASK *)getEntity(vtask);
cmcent = (CmppEntity *)entity->var;
} else {
warning("cmpp_schedule: unknown interface %d.\n", selector);
return;
}
switch (selector) {
case UP:
if (item == cmpp_terminate_req) {
num = sk_num(cmcent->init_list) + sk_num(cmcent->mo_list);
if (block->conid >= num) {
error("cmpp_terminate_req follows incorrect "
"connection index %d.\n", block->conid);
deleteFrame(&block->data);
break;
}
if (block->conid < sk_num(cmcent->init_list))
vtask = sk_value(cmcent->init_list, block->conid);
else
vtask = sk_value(cmcent->mo_list,
block->conid - sk_num(cmcent->init_list));
if (!vtask) {
warning("cmpp_shedule: cmpp_terminate_req invalid, no vtask found.\n");
return;
}
cmcon = (CmppCon *)vtask->var;
} else if (item == cmpp_submit_req) {
startHook(cmcent->hDistribute);
/**distribute_submit(entity);*/
deleteFrame(&block->data);
return;
} else {
error("**unsupported primitive %d from upper layer.\n", item);
deleteFrame(&block->data);
return;
}
break;
case TIMEOUT:
/* Connect message sent, but not got ConnectResponse.
* while waiting for ConnectResponse, timeout event occurs */
if (item == t_retry)
msg->primitive.item = TimerTO_Retry;
/* after TACTTEST, timeout event occurs. this will invoke
* system send ActiveTest message to verify ISMG state. */
else if (item == t_acttest) {
msg->primitive.item = TimerTO_ActTest;
issue_active_test (vtask);
startTimer(vtask, t_acttest, TACTTEST);
return;
}
/* ActiveTest message sent, but not got ActiveTestResp.
* while waiting for ActiveTestResp, timeout event occurs */
else if (item == t_reactive) {
if (cmcon->actretry <= MAXRETRY) {
if (sendTcpCon (cmcon->fd, cmcon->actpdu) < 0) {
error("ActiveTest retransmit timeout: CMPP connection %s"
" to ISMG %s:%d crashed while reading length.\n",
vtask->name, cmcent->remote_host,
cmcent->remote_port);
vtask->state = cmpp_null;
checkIdleConnection(vtask);
startTimer(entity, t_build, TBUILD);
return;
}
cmcon->actretry++;
startTimer(vtask, t_reactive, TREACTIVE);
startTimer(vtask, t_acttest, TACTTEST);
return;
} else {
error("ActiveTest retransmit %d times via CMPP connection %s"
" to, ISMG %s:%d, now give up re-submit.\n",
cmcon->actretry, vtask->name,
cmcent->remote_host, cmcent->remote_port);
cmcon->actretry = 0;
vtask->state = cmpp_null;
checkIdleConnection(vtask);
startTimer(entity, t_build, TBUILD);
return;
}
}
/* automatically restart CMPP connection through t_build TIMER and
* ConnectionBuild hook. when t_build timeout, conection_build hook
* will be started. the hook is responsible for creating TCP con. */
else if (item == t_build) {
if (sk_num(cmcent->init_list) < cmcent->mt_num ||
sk_num(cmcent->mo_list) < cmcent->mo_num)
{
startHook(cmcent->hBuildConn);
}
/* Submit message has been sent, no SubmitResponse message got so far.
* Each Submit message has its dynamic Timer to prepare for
* retransmitting the Submit message. */
} else if (item == t_resubmit) {
subitem = (SubmitPending *) getTimeoutUserInfo(msg);
if (!subitem)
break;
if (subitem->submtimer != getTimeoutInst(msg))
break;
if (subitem->retrynum <= MAXRETRY) {
if (sendTcpCon (cmcon->fd, subitem->submitframe) < 0) {
error("Submit retransmit timeout: CMPP connection %s to "
"ISMG %s:%d crashed while reading length.\n",
vtask->name, cmcent->remote_host,
cmcent->remote_port);
vtask->state = cmpp_null;
checkIdleConnection(vtask);
startTimer(entity, t_build, TBUILD);
return;
}
subitem->status = SUBMIT_REWAITRESP;
subitem->retrynum++;
subitem->submtimer = startDynTimer (vtask, t_resubmit,
TRESUBMIT, subitem);
return;
} else {
error("Submit retransmit %d times via CMPP connection %s to "
"ISMG %s:%d, now give up re-submit.\n",
subitem->retrynum - 1, vtask->name,
cmcent->remote_host, cmcent->remote_port);
subitem->status = SUBMIT_AVAIL;
subitem->retrynum = 0;
store_unsucc_submit(vtask, subitem->submit);
emptyFrame(subitem->submitframe);
subitem->submtimer = NULL;
startHook(cmcent->hDistribute);
return;
}
}
break;
}
if (!vtask) {
error("**no virtual task for the primitive %d.\n", item);
return;
}
cmcon = (CmppCon *)vtask->var;
switch (vtask->state) {
case cmpp_null:
break;
case cmpp_handshaking:
switch (item) {
case TimerTO_Retry:
if (cmcon->retrynum < MAXRETRY && send_cmpp_connect(vtask) >= 0) {
vtask->state = cmpp_handshaking;
} else {
if (cmcon->retrynum > MAXRETRY)
error("Connect Response waiting timeout: after %d times "
"retrying to sending CONNECT, "
"system decides to terminate this CMPP "
"connection.\n", MAXRETRY);
else
error("Connect Response waiting timeout: TCP connection"
" crashed while sending CMPP Connect.\n");
vtask->state = cmpp_null;
checkIdleConnection(vtask);
startTimer(entity, t_build, TBUILD);
}
break;
}
break;
case cmpp_ready:
break;
}
checkIdleConnection(vtask);
if (selector == UP) {
deleteFrame(&block->data);
}
}
/*
struct tm
{
int tm_sec; // seconds
int tm_min; // minutes
int tm_hour; // hours
int tm_mday; // day of the month
int tm_mon; // month
int tm_year; // year
int tm_wday; // day of the week
int tm_yday; // day in the year
int tm_isdst; // daylight saving time
};
*/
int create_cmpp_connect (VTASK * vtask)
{
CmppCon * cmcon = NULL;
FRAME_PTR frame = NULL;
uint8 strtime [11];
struct tm * curtime;
time_t calendt;
uint32 netord = 0;
if (!vtask) return -1;
cmcon = (CmppCon *)vtask->var;
if (cmcon->concreated) return 0;
time(&calendt);
curtime = localtime(&calendt);
cmcon->timestamp = (curtime->tm_mon+1) * 100000000 +
curtime->tm_mday * 1000000 +
curtime->tm_hour * 10000 +
curtime->tm_min * 100 +
curtime->tm_sec * 1 ;
sprintf(strtime, "%010ld", cmcon->timestamp);
//putnLastBytes (&frame, cmcon->sp_id, sizeof(cmcon->sp_id));
putnLastBytes (&frame, cmcon->sp_id, strlen(cmcon->sp_id));
appendnBytes (&frame, '\0', 9);
putnLastBytes (&frame, cmcon->sharedsecret, strlen(cmcon->sharedsecret));
putnLastBytes (&frame, strtime, 10);
Md5Val (bytePointer(frame), frameLength(frame), cmcon->authsrc);
emptyFrame (frame);
/* filling the header of connect */
putnLastBytes (&frame, (uint8 *)&netord, 4);
netord = CMPP_CONNECT;
netord = htonl(netord);
putnLastBytes (&frame, (uint8 *)&netord, 4);
netord = CMPPGetSeqID();
netord = htonl(netord);
putnLastBytes (&frame, (uint8 *)&netord, 4);
/* filling the content of connect */
putnLastBytes (&frame, cmcon->sp_id, sizeof(cmcon->sp_id));
putnLastBytes (&frame, cmcon->authsrc, 16);
putLastByte (&frame, cmcon->version);
netord = htonl(cmcon->timestamp);
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -