int nd_run_cmdline(struct nd_cmdline_root *root, int argc, const char *argv[] ) { int ret=0 ; char buf[1024] ; if (root->init_func) { if(-1==root->init_func(root, argc, argv) ) { nd_logerror("init command lient error ") ; return -1 ; } } fprintf(stdout, "%s>", root->tips ) ; fflush(stdout) ; while (root->exit_stat==0) { int read_flag = 0; if (root->update_func) { ret = root->update_func(root, 0, NULL) ; if (ret > 0) { //fprintf(stdout, "update ret =%d\n%s>",ret, root->tips ) ; fflush(stdout) ; } if(!kbhit()) { nd_sleep(50) ; continue ; } } memset(buf, 0, sizeof(buf)) ; if (root->next_cmd) { strncpy(buf, root->next_cmd, sizeof(buf)) ; read_flag = 1 ; free(root->next_cmd) ; root->next_cmd = 0; } else if(fgets( buf, sizeof(buf), stdin ) ) { read_flag = 1 ; } if (read_flag) { ret = _parse_input_and_run(root, buf) ; if(ret == -1) { fprintf(stderr, "bad command: %s\n", buf ) ; } if (root->exit_stat) { break ; } root->last_retval =ret ; fprintf(stdout, ">%s>", root->tips ) ; fflush(stdout) ; } read_flag = 0 ; } return 0; }
/* entry of timer update client map*/ int update_remote_connect(void *param) { ProxySession *psession ; NDInstanceSrv *pinst = static_cast<NDInstanceSrv *> (param) ; NDCmIterator cm_it(pinst) ; NDOStreamMsg sendmsg(MAXID_SYS, SYM_TEST) ; if(!cm_it.CheckValid()) { nd_sleep(100) ; return 0 ; } for (psession=(ProxySession *) cm_it.First(); psession; psession=(ProxySession *)cm_it.Next()) { psession->UpdateRemote() ; } nd_sleep(10) ; return 0 ; }
int checksum_test() { int ret = 0, send_times =0; udt_pocketbuf packet; u_32 check_sum,cs_tmp ; int nReadNum = rand() %(_READ_SIZE-10) +1 ; char *paddr ; FILE *pf = fopen("3.pdf", "r+b") ; if(!pf) { printf("open file error!\n") ; return -1; } init_udt_pocket(&(packet.pocket)) ; paddr =pocket_data(&(packet.pocket)); POCKET_TYPE(&(packet.pocket)) = 3 ; while(nReadNum=fread(paddr,1,nReadNum,pf)) { calc_cs(&packet ,nReadNum) ; nd_sleep(1); check_sum = POCKET_CHECKSUM(&(packet.pocket)) ; POCKET_CHECKSUM(&(packet.pocket)) = 0 ; nReadNum += ndt_header_size(&(packet.pocket)) ; cs_tmp = nd_checksum((NDUINT16*)&(packet.pocket),nReadNum) ; if(cs_tmp!=check_sum) { ndprintf("test checksum error check_sum=%d cs_tmp=%d\n", check_sum,cs_tmp); getch() ; exit(1); } else{ ndprintf("test check OK\n", ++send_times,ret); } nReadNum = rand() %(_READ_SIZE-10) +1 ; } fclose(pf) ; //nd_connector_send(connect_handle,&msg_buf,ESF_URGENCY) ; return 0; }