コード例 #1
0
ファイル: MainTest.c プロジェクト: FHV-ITM13/C-CPP
int testNormalizer() {
	printf("\n\nNormalizer test:\n\n");
	nInit(0, 10, 5, -1);

	nAddValue(1);
	nAddValue(2);
	nAddValue(3);
	printf("normalize: %f\n", nNormalize());

	nAddValue(12);
	printf("normalize: %f\n", nNormalize());

	nAddValue(7);
	printf("normalize: %f\n", nNormalize());

	nFree();
	return 0;
}
コード例 #2
0
ファイル: StlmDateSvr.c プロジェクト: iocoo/ApsOnlWS
//Main Funtion
int main(int argc,char *argv[])
{
    int status=0;
    status=nInit();
    sprintf(sLogfile,"%s",argv[0]);
    SOAP_SOCKET m,s;
    int i=0;
    struct soap Onlsoap; 
    soap_init(&Onlsoap);
    Onlsoap.fget = http_get;
    Onlsoap.fpost = http_post;
    struct soap * soap_thr[MAX_THR];
    pthread_t tid[MAX_THR];

    sigset(SIGUSR1, signalHandle);
    sigset(SIGTERM, signalHandle);
    sigset(SIGSEGV, signalHandle);

    // 设置UTF-8编码方式
    //soap_set_mode(&Onlsoap, SOAP_C_UTFSTRING);
    
    soap_set_mode(&Onlsoap, SOAP_C_MBSTRING);
    soap_set_namespaces(&Onlsoap, namespaces);
    // ----------
    m = soap_bind(&Onlsoap,NULL,lPort,BACKLOG);
    //循环直至服务套接字合法
    while (!soap_valid_socket(m))
    {
        dzlog_error("Bind port error!");
        m = soap_bind(&Onlsoap,NULL,lPort,BACKLOG);
        sleep(2);
    }
    //锁和条件变量初始化
    pthread_mutex_init(&queue_cs,NULL);
    pthread_cond_init(&queue_cv,NULL);
    //生成服务线程
    for(i = 0; i <MAX_THR; i++)
    {
      soap_thr[i] = soap_copy(&Onlsoap);
      dzlog_info("Starting thread %d ",i);
      pthread_create(&tid[i],NULL,(void*(*)(void*))process_queue,(void*)soap_thr[i]);
      
    }
   
   for(;;)
   {

       s=soap_accept(&Onlsoap);
       if(!soap_valid_socket(s))
       {
            if (Onlsoap.errnum) 
            { 
                 soap_print_fault(&Onlsoap,stderr);
                 continue;
            } 
            else
            {
                dzlog_error("Server timed out.");
                break;
            }
       }
     
       dzlog_info("Main Process[%d] accepted connection from IP=%d.%d.%d.%d", getpid(),
              (Onlsoap.ip >> 24)&0xFF, (Onlsoap.ip >> 16)&0xFF, (Onlsoap.ip >> 8)&0xFF, Onlsoap.ip&0xFF);

        while(enqueue(s) == SOAP_EOM)
         sleep(1);
   }
   
    //服务结束后的清理工作
    for(i = 0; i < MAX_THR; i++)
    {
       while (enqueue(SOAP_INVALID_SOCKET) == SOAP_EOM) 
       {
           sleep(1);
       }
    }
    for(i=0; i< MAX_THR; i++)
    {
        pthread_join(tid[i],NULL);
        dzlog_debug("terminated[%d] ",i);
        soap_done(soap_thr[i]);
        free(soap_thr[i]);
    }
   
    pthread_mutex_destroy(&queue_cs);
    pthread_cond_destroy(&queue_cv);
    soap_done(&Onlsoap);
    DbPoolFree(&conn_pool);
	zlog_fini();
    return 0;
}