示例#1
0
void main()
{
	int flag;       //标记扩展是否成功	
	for( ; ; )
	{
		initiate();
		flag = search ();
		if(flag == 1)
		{
			recorder();
			releasemem();
			showresult();
			goon();
		}
		else
		{
			printf("无法找到符合条件的解");
			releasemem();
			goon();
		}
	}
}
示例#2
0
int main(int argc, char *argv[])
{
    if(!goon())
    {
        printf("process exist!\n");
        return 1;
    }
    #ifndef DEBUG_P
    //init_daemon();
    #endif // DEBUG_P
    int ret = 0;
    int  auth_flag=0;
    if(argc>1)
    {
        sleep(40);
    }
    mask_sig();
    //Initsem();
    InitQueue(&Q_cmd,&Q_respond);
    MakeEmpty(L_cmd);//init linked list

    set_dconfig_flag();           //set the default auth flag in file
    ret = pthread_create(&thread_id, NULL, (void*)read_switch, NULL);//read web  config switch
    if (ret)
    {
        DEBUG_printf("Create pthread error!\n");
        return 1;
    }
    sleep(1);
    if(1==SW)
    {
        DEBUG_printf("Web  Switch is OFF!\n");
        exit(1);
    }
    while(sock_connect_server() == -1)
    {
        sleep(30);
    }
    if(encrypt_connect_server()==-1)
    {
        receivedata = sockreceivedata;
        senddata = socksenddata;
        DEBUG_printf("encrypt connect failed.\n");
        close(sockfd);
        sock_connect_server();
    }
    else
    {
        receivedata = encryptreceivedata;
        senddata = encryptsenddata;
    }
    signal_check(30);
    signal(SIGUSR1,sig_handle);
    signal(SIGUSR2,sig_handle);
    signal(SIGINT, Stop);
    signal(SIGTERM, Stop);
    pthr_rev_id = pthread_create(&thread_deal_cmd_id,NULL,(void*)pthr_deal_cmd,NULL);
    if (pthr_rev_id)
    {
        DEBUG_printf("Create pthread error!\n");
        return 1;
    }
    pthr_rev_id = pthread_create(&thread_deal_response_id,NULL,(void*)pthr_deal_response,NULL);
    if (pthr_rev_id)
    {
        DEBUG_printf("Create pthread error!\n");
        return 1;
    }
    //receive the data
    while(p_n_over)
    {
        if((Q_cmd.rear+1)%MAXQSIZE!=Q_cmd.front && (Q_respond.rear+1)%MAXQSIZE!=Q_respond.front)
        {
            if(-1==recv_serpkg_struct())
            {
                DEBUG_printf("Bad Package REV!\n");
                sleep(1);
                continue;
            }
            if(package.pkg_cmd[0]!='f')
            {
                DEBUG_printf("this is command\n");
                EnQueue(&Q_cmd,package);
            }
            else
            {
                DEBUG_printf("this is respond \n");
                EnQueue(&Q_respond,package);
            }
        }
        else
        {
            DEBUG_printf("the queue is full\n");
            sleep(5);
        }
    }
    return 1;
}