Exemplo n.º 1
0
int ndInitNet()
{
    if (__bInit) {
        return 0;
    }
    const char *argv[] = {"ndNetCAPI"} ;
    
    printf("test byte order is : %s \n" , nd_byte_order()?"little":"big") ;
    
    nd_arg(1, argv);
    
    nd_common_init() ;
    nd_net_init() ;
    //RSAinit_random(&__rsa_contex.randomStruct);
    nd_net_set_crypt((nd_netcrypt)nd_TEAencrypt, (nd_netcrypt)nd_TEAdecrypt, sizeof(tea_v)) ;
    __bInit =1 ;
	__terminate_entry = 0 ;
    return 0 ;
}
Exemplo n.º 2
0
int NDInstanceBase::Create(int argc,const char *argv[])
{
	int i ;
	const char *logfileName = NULL ;
	if (m_bCreated)	{
		return 0;
	}

    system_signals_init() ;
    
	nd_arg(argc, argv);	
	
	//get config file 	
	for (i=1; i<argc; i++){
		if(0 == strcmp(argv[i],"-f" ) && i< argc-1) {
			NDInstanceBase::config_file = argv[++i] ;
		}
		else if(0== strcmp(argv[i], "-c") && i< argc-1) {
			m_config_name = argv[++i] ;
		}
		else if(0==strcmp(argv[i],"-nodev")) {
			m_un_develop = 1;
		}
		
		else if(0==strcmp(argv[i],"-log") && i<argc -1) {
			logfileName = argv[++i];
		}
		else if(0==strcmp(argv[i],"-workdir") &&i<argc -1 ) {
			nd_chdir(argv[++i]) ;
		}
		else if(0==strcmp(argv[i],"-v") || 0==strcmp(argv[i],"--version") ) {
			fprintf(stdout, "version : %s \n" , __g_version_desc) ;
			exit(0) ;
		}
		else if(0==strcmp(argv[i],"-l") || 0==strcmp(argv[i],"--rlimit") ) {
			char buf[1024] ;
			fprintf(stdout, "rlimit: \n %s\n" , get_rlimit_info(buf, sizeof(buf)) ) ;
			exit(0) ;
		}

        else if(0==strcmp(argv[i],"-pid") && i<argc -1){
            FILE *pf = fopen(argv[i+1], "w") ;
            if (pf) {
                fprintf(pf, "%d", nd_processid()) ;
                fclose(pf) ;
            }
            else {
                fprintf(stderr,"write pid error %s file not exist\n", argv[i+1]) ;
                exit(1) ;
            }
        }
	}

	if(!config_file|| !m_config_name) {
		printf("usage: -f config-file -c config-name\n press ANY key to continue\n") ;
		//getch() ;
		exit(1) ;
		//return -1 ;
	}

	if(-1==ReadConfig(m_config_name) ) {
		printf("Read config %s file error \n press ANY key to continue\n", m_config_name) ;
		//getch() ;
		exit(1) ;
	}
	
	nd_set_exit_callback(applib_exit_callback) ;

	if (m_config.i_cfg.open_dump){
#ifndef ND_UNIX
		::SetUnhandledExceptionFilter((LPTOP_LEVEL_EXCEPTION_FILTER)nd_unhandler_except);
#else
		enable_core_dump() ;
#endif
	}
	size_t max_connector = m_config.l_cfg.max_connect ;
	if ( max_connector > get_maxopen_fd() ) {
		size_t new_fd_num = set_maxopen_fd(max_connector) ;
		nd_logmsg("set max connect %d real max connect =%d\n",m_config.l_cfg.max_connect, (int) new_fd_num);
	}
	
	if(logfileName && logfileName[0]) {
		strncpy(m_config.i_cfg.log_file, logfileName, sizeof(m_config.i_cfg.log_file)) ;
	}
	if (m_config.i_cfg.log_file[0]){
		set_log_file(m_config.i_cfg.log_file) ;
		if (m_config.i_cfg.log_file_size > 0) {
			nd_setlog_maxsize(m_config.i_cfg.log_file_size) ;
		}
		nd_setlog_func(nd_default_filelog) ;
	}

	if (m_config.i_cfg.callstack_file[0]){
		if(CALLSTACK_INIT(m_config.i_cfg.callstack_file)==-1) {
			nd_logfatal("create map file %s error!\n" AND m_config.i_cfg.callstack_file) ;
			return -1 ;
		}
	}

	nd_net_set_crypt((nd_netcrypt)nd_TEAencrypt, (nd_netcrypt)nd_TEAdecrypt, sizeof(tea_v)) ;
	
// 	if (g_base_inst==NULL){
// 		g_base_inst = this ;
// 	}

	OnCreate();

	m_bCreated = 1;
	return 0 ;

}