vector<int> exclusiveTime(int n, vector<string>& logs) {
    vector<int> ret(n,0); //func id as index, time is value
    stack<pair<int,int>> s; //func id, current execution time, when start, push, when end, pop

    for(int i=0;i<logs.size();i++){
        int index = 0;
        int id = checkid(logs[i],index);
        int label = checklabel(logs[i],index);
        int t = checktime(logs[i],index);
        if(label==0){
            s.push(make_pair(id,t));
        }else{
            pair<int,int> cur = s.top();
            int last = t-cur.second+1;
            ret[cur.first]+=last;
            s.pop();
            if (!s.empty()) {
              //to remove over count, not time for s.top().first id 
                ret[s.top().first] -= last;
            }
        }
    }


    return ret;
}
예제 #2
0
파일: client.c 프로젝트: torque/reki
static void Client_cleanup( uv_handle_t *handle ) {
	ClientConnection *client = handle->data;
	checktime( client, "Close connection." );
	HttpParser_free( client->parserInfo );
	Client_free( client );
	// this is the client tcp handle.
	free( handle );
}
예제 #3
0
bool RTCPScheduler::IsTime()
{
    if (firstcall)
    {
        firstcall = false;
        prevrtcptime = RTPTime::CurrentTime();
        pmembers = sources.GetActiveMemberCount();
        CalculateNextRTCPTime();
        return false;
    }

    RTPTime currenttime = RTPTime::CurrentTime();

//	// TODO: for debugging
//	double diff = nextrtcptime.GetDouble() - currenttime.GetDouble();
//
//	std::cout << "Delay till next RTCP interval: " << diff << std::endl;

    if (currenttime < nextrtcptime) // timer has not yet expired
        return false;

    RTPTime checktime(0,0);

    if (!byescheduled)
    {
        bool aresender = false;
        RTPSourceData *srcdat;

        if ((srcdat = sources.GetOwnSourceInfo()) != 0)
            aresender = srcdat->IsSender();

        checktime = CalculateTransmissionInterval(aresender);
    }
    else
        checktime = CalculateBYETransmissionInterval();

//	std::cout << "Calculated checktime: " << checktime.GetDouble() << std::endl;

    checktime += prevrtcptime;

    if (checktime <= currenttime) // Okay
    {
        byescheduled = false;
        prevrtcptime = currenttime;
        pmembers = sources.GetActiveMemberCount();
        CalculateNextRTCPTime();
        return true;
    }

//	std::cout << "New delay: " << nextrtcptime.GetDouble() - currenttime.GetDouble() << std::endl;

    nextrtcptime = checktime;
    pmembers = sources.GetActiveMemberCount();

    return false;
}
예제 #4
0
파일: rules.c 프로젝트: CitiLogics/EPANET
int  checkpremise(struct Premise *p)
/*
**----------------------------------------------------------
**    Checks if a particular premise is true
**----------------------------------------------------------
*/
{
    if (p->variable == r_TIME || p->variable == r_CLOCKTIME)
       return(checktime(p));
    else if (p->status > IS_NUMBER)
       return(checkstatus(p));
    else
       return(checkvalue(p));
}
예제 #5
0
static void
mcastpulse( tr_natpmp_t * pmp )
{
    struct sockaddr_in sin;
    uint8_t            buf[16];
    int                res;
    char               dbgstr[INET_ADDRSTRLEN];
    tr_natpmp_parse_t  parse;

    res = tr_netRecvFrom( pmp->mcastfd, buf, sizeof( buf ), &sin );
    if( TR_NET_BLOCK & res )
    {
        return;
    }
    else if( TR_NET_CLOSE & res )
    {
        tr_err( "error reading nat-pmp multicast message" );
        killsock( &pmp->mcastfd );
        return;
    }

    tr_netNtop( &sin.sin_addr, dbgstr, sizeof( dbgstr ) );
    tr_dbg( "nat-pmp read %i byte multicast packet from %s", res, dbgstr );

    if( pmp->dest.s_addr != sin.sin_addr.s_addr )
    {
        tr_dbg( "nat-pmp ignoring multicast packet from unknown host %s",
                dbgstr );
        return;
    }

    if( TR_NET_OK == parseresponse( buf, res, -1, &parse ) )
    {
        if( checktime( &pmp->uptime, parse.seconds ) )
        {
            pmp->renew = 0;
            tr_inf( "detected nat-pmp device reset" );
            if( NULL != pmp->req )
            {
                resetreq( pmp->req );
            }
        }
        if( PMP_STATE_NOBODYHOME == pmp->state )
        {
            tr_dbg( "nat-pmp state notfound -> idle" );
            pmp->state = PMP_STATE_IDLE;
        }
    }
}
예제 #6
0
int main(int argc, char *argv[])
{
    pid_t   pid;
    char    *s;
    int     nzero, ret;
    int     adj = 0;

    setbuf(stdout, NULL);
#if defined(NZERO)
    nzero = NZERO;
#elif defined(_SC_NZERO)
    nzero = sysconf(_SC_NZERO);
#else
#error NZERO undefined
#endif
    printf("NZERO = %d\n", nzero);
    if (argc == 2)
        adj = strtol(argv[1], NULL, 10);
    gettimeofday(&end, NULL);
    end.tv_sec += 10;   /* run for 10 seconds */

    if ((pid = fork()) < 0) {
        fprintf(stderr, "fork error\n");
        exit(1);
    } else if (pid == 0) {  /* child */
        s = "child";
        printf("current nice value in child is %d, adjusting by %d\n",
          nice(0)+nzero, adj);
        errno = 0;
        if ((ret = nice(adj)) == -1 && errno != 0) {
            fprintf(stderr, "child set scheduling priority");
            exit(1);
        }
        printf("now child nice value is %d\n", ret+nzero);
    } else {        /* parent */
        s = "parent";
        printf("current nice value in parent is %d\n", nice(0)+nzero);
    }
    for(;;) {
        if (++count == 0) {
            printf("%s counter wrap\n", s);
            exit(0);
        }
        checktime(s);
    }

    return 0;
}
예제 #7
0
파일: test.cpp 프로젝트: Chronoes/ttu-cpp
} END_TEST

TEST_CASE(CheckTimeFaulty) {
    std::vector<std::string> cases({
        "15:60",
        "300:3",
        "20:5:59",
        "4002:02:19,23",
        "30.3"
    });

    for (size_t i = 0; i < cases.size(); i++) {
        if (checktime(cases[i])) {
            test.fail(cases[i]);
        }
    }
} END_TEST
예제 #8
0
파일: nice_test.c 프로젝트: dellsun/unix
int main(int argc, const char *argv[]) {
	pid_t pid;
	char *s;
	int nzero, ret;
	int adj = 0;
	
	setbuf(stdout, NULL);
#if defined(NZERO)
	nzero = NZERO;
#elif defined(_SC_NZERO)
	nzero = sysconf(_SC_NZERO);
#else
#error NZERO undefined
#endif
	printf("NZERO = %d\n", nzero);
	if (argc == 2)
		adj = strtol(argv[1], NULL, 10);
	gettimeofday(&end, NULL);
	end.tv_sec += 10;
	
	if ((pid = fork()) < 0) {
		err_sys("fork failed");
	} else if (pid == 0) {
		s = "child";
		printf("current nice value in child is %d, adjusting by %d\n",
			nice(0)+nzero, adj);
		errno = 0;
		
		if ((ret = nice(adj)) == -1 && errno != 0)
			err_sys("child set scheduling priority");
		printf("now child nice value is %d\n", ret + nzero);
	} else {
		s = "parent";
		printf("current nice value in parent is %d\n", nice(0) + nzero);
	}
	
	while (1) {
		if (++count == 0) 
			err_quit("%s counter wrap", s);
		checktime(s);
	}
}
예제 #9
0
파일: test.cpp 프로젝트: Chronoes/ttu-cpp
} END_TEST

TEST_CASE(CheckTime) {
    std::vector<std::string> cases({
        "200",
        "15:30",
        "300:30",
        "20:59:59",
        "4002:02:19",
        "30.330",
        "23:01,000",
        "11:09:24.888",
        "123121:50:10,132"
    });

    for (size_t i = 0; i < cases.size(); i++) {
        if (!checktime(cases[i])) {
            test.fail(cases[i]);
        }
    }
} END_TEST
예제 #10
0
파일: autoconf.c 프로젝트: nawawi/psybnc
int main()
{
    FILE *makefile;
    FILE *config;
    FILE *sslrnd;
    FILE *uran;
#ifndef SSLPATH
    char *sslblist[]={
	"/bin/openssl",
	"/usr/bin/openssl",
	"/usr/sbin/openssl",
	"/usr/local/bin/openssl",
	"/usr/local/ssl/bin/openssl",
	NULL
    };
#endif
    int sslin=0;
    int provi=0;
    unsigned char rchar,orchar;
    int ic;
#ifdef SSLPATH
    char mbuf[strlen(SSLPATH)+30];
    char ibuf[strlen(SSLPATH)+20];
#else
    char mbuf[200];
    char ibuf[200];
#endif
    bigopt[0]=0;
    sunosopt[0]=0;
    timeopt[0]=0;
    ipv6opt[0]=0;
    ssllib[0]=0;
    socklib[0]=0;
    snbuf[0]=0;
    snopt[0]=0;
    env[0]=0;
    sslbin[0]=0;
    sslopt[0]=0;
    dnsopt[0]=0;
    dnslib[0]=0;
    printf("System:");
    getos();    
    printf(" %s\n",os);
    if(strstr(os,"SunOS")==os) strcpy(sunosopt,"-DSUNOS ");
    printf("Socket Libs: ");
    fflush(stdout);
    needsock=checksocklib();
    if(needsock!=0)
    {
	/* in the case of external socket-libs, sol8 needs to check for lbind */
	strcpy(socklib,"-lnsl -ldl -lsocket ");
	needbind=checkbind();
	if(needbind!=0)
	{
	    strcat(socklib,"-lbind ");
	    printf("External, -lbind required.\n");
	} else
	    printf("External.\n");
    }
    else
	printf("Internal.\n");
    fflush(stdout);
    printf("Environment: ");
    fflush(stdout);
    extenv=checkenv();
    if(extenv!=0)
    {
	printf("No internal Routines.\n");
	strcpy(env," src/bsd-setenv.o ");
    }
    else
    {
	printf("Internal.\n");
    }
    fflush(stdout);
    printf("Time-Headers: ");
    fflush(stdout);
    off_time=checktime();
    if(off_time!=0)
    {
	printf("in time.h and sys/time.h\n");
	strcpy(timeopt," -DNOSYSTIME ");
    }
    else
    {
	printf("in sys/time.h.\n");
    }
    fflush(stdout);
    bigendian=checkendian();
    if(bigendian)
    {
	printf("Byte order: Big Endian.\n");
	strcpy(bigopt,"-DBIGENDIAN ");
    }
    else
	printf("Byte order: Low Endian.\n");
    printf("IPv6-Support: ");
    fflush(stdout);
    ipv6=checkipv6();
    if(ipv6==0)
    {
#ifdef AF_INET6
	ic=checkipv6usable();
	if(ic==0)
	{
	    printf("Yes.\n");
	    strcpy(ipv6opt,"-DIPV6 ");
	} else {
	    printf("Yes, general support. But no interface configured.\n");
	    ipv6=1;
	}
#else
	printf("No.\n");
	ipv6=1;
#endif
    }
    else
	printf("No.\n");
    printf("async-DNS-Support: ");
    fflush(stdout);
    dns=checkresolve();
    if(dns==0)
    {
    	printf("Yes.\n");
	strcpy(dnslib,"-lresolv ");
    }
    else
    {
	strcpy(dnsopt,"-DBLOCKDNS ");
	printf("No, using blocking DNS.\n");
    }
    printf("SSL-Support: ");
    fflush(stdout);
    ssl=checkssl();
    if(ssl==0)
    {
#ifndef SSLPATH
	while(sslblist[sslin]!=NULL)
	{
	    if(fexists(sslblist[sslin]))
		break;
	    sslin++;
	}
	if(sslblist[sslin]==NULL)
	{
	    printf("Yes, but no openssl binary found.");
	    ssl=-1;
	} else {
	    strcpy(sslbin,sslblist[sslin]);
	    printf("Yes.\n");
	    strcpy(sslopt,"-DHAVE_SSL ");
	    strcpy(ssllib,"-L/usr/local/ssl/lib -lssl -lcrypto ");
	}
#else
	if(strlen(SSLPATH)+13<sizeof(mbuf))
	{
	    strcpy(mbuf,SSLPATH);
	    if(mbuf[strlen(mbuf)-1]!='/')
		strcat(mbuf,"/");
	    strcpy(ibuf,mbuf);
	    strcat(mbuf,"bin/openssl");
	    if(fexists(mbuf)==0)
	    {
		printf("Yes, but no openssl binary found in \"%s\".",SSLPATH);
		ssl=-1;
	    } else {
		strcpy(sslbin,mbuf);
		printf("Yes.\n");
		strcpy(sslopt,"-DHAVE_SSL ");
		strcpy(ssllib,"-L");
		strcat(ssllib,ibuf);
		strcat(ssllib,"lib -lssl -lcrypto ");
	    }
	} else {
	    printf("Possibly. But the configured path \"%s\" is too long.\n",SSLPATH);
	}	
#endif
    }
    else
	printf("No openssl found. Get openssl at www.openssl.org\n");
    config=fopen("/psybnc/config.h","r");
    if(config!=NULL)
    {
	fclose(config);
	printf("Found Provider-Config - Using this for compilation\n");
	provi=1;
    }
    printf("Creating Makefile\n");
    makefile=fopen("makefile.out","w");
    if(makefile==NULL)
    {
	printf("Can't create makefile.out .. aborting\n");
	exit(0x1);
    }
    fprintf(makefile,"CC	= gcc\n");
    fprintf(makefile,"SRC	= src/\n");
#ifdef BOUNDCHECK
    fprintf(makefile,"CFLAGS  = -O -fbounds-checking -fno-builtin\n");
#else
    fprintf(makefile,"CFLAGS  = -O\n");
#endif
    fprintf(makefile,"LIBS	= -lm %s %s %s\n",socklib,ssllib,dnslib); /* math lib needed for snprintf of ap */
    if(ssl==0)
#ifdef SSLPATH
	fprintf(makefile,"INCLUDE = -I./src/ -I. -I%sinclude\n",SSLPATH);
#else
	fprintf(makefile,"INCLUDE = -I./src/ -I. -I/usr/local/ssl/include\n");
#endif
    else
예제 #11
0
// 将GPS数据转成GNSS
bool PConvert::convert_gps_info( MapString &mp, GnssData &gps )
{
	if ( mp.empty() )
		return false ;

	gps.state = 0x00 ;
	gps.alarm = 0x00 ;

	int nval = 0 ;
	if ( get_map_integer( mp, "1", nval ) ) {
		nval = nval * 10 / 6 ;
	}
	// 处理经度不在中国范围内 619066885
	if ( nval < 72000000 || nval > 140000000 ){  // 经度范围72-136
		OUT_ERROR( NULL, 0, NULL, "error lon %u", nval ) ;
		return false ;
	}
	gps.lon = ntouv32( nval ) ;

	if ( get_map_integer( mp, "2", nval ) ) {
		nval = nval * 10 / 6 ;
	}
	// 处理纬度不在中国范围内
	if ( nval < 18000000 || nval > 55000000 ) {  // 纬度范围18-54
		OUT_ERROR( NULL, 0, NULL, "error lat %u", nval ) ;
		return false ;
	}
	gps.lat = ntouv32( nval ) ;

	if ( get_map_integer( mp, "3", nval ) ) {
		nval = nval/10 ; // 速度808中为1/10km/h
	}
	// 处理速度不正确
	if ( nval > 220 )  {  // 220km/h
		OUT_ERROR( NULL, 0, NULL, "error speed %u", gps.vec1 ) ;
		return  false ;
	}
	gps.vec1 = ntouv16( nval ) ;

	if ( get_map_integer( mp, "7", nval ) ) {
		nval = nval/10 ; // 行驶记录仪速度808中为1/10km/h
	}
	gps.vec2 = ntouv16( nval ) ;
	if ( gps.vec2 == 0 ) {
		gps.vec2 = gps.vec1 ;
	}

	string sval ;
	if ( ! get_map_string( mp, "4", sval ) ) {
		OUT_ERROR( NULL, 0, NULL, "error time empty" ) ;
		// 如果没有时间就直接返回了
		return false ;
	}

	int nyear = 0 , nmonth = 0 , nday = 0 , nhour = 0 ,nmin = 0 , nsec = 0 ;

	sscanf( sval.c_str(), "%04d%02d%02d/%02d%02d%02d", &nyear, &nmonth, &nday, &nhour, &nmin, &nsec ) ;
	// 检测时间是否正确
	if ( ! checktime( nyear, nmonth, nday, nhour, nmin, nsec ) ) {
		OUT_ERROR( NULL, 0, NULL, "error time %s", sval.c_str() ) ;
		return false ;
	}

 	gps.date[3]   = nyear  % 256 ;
	gps.date[2]   = nyear / 256 ;
	gps.date[1]   = nmonth ;
	gps.date[0]   = nday ;

	gps.time[0]   = nhour ;
	gps.time[1]   = nmin ;
	gps.time[2]   = nsec ;

	if ( get_map_integer( mp, "5", nval ) ){
		gps.direction = ntouv16( nval ) ;
	}
	// 方向在0-360度之间
	if ( nval > 360 ) {
		OUT_ERROR( NULL,0, NULL, "error direction %d", nval ) ;
		return false ;
	}

	if ( get_map_integer( mp, "15", nval ) ) {
		gps.state = (nval) ? gps.state | 0x02 : gps.state ;
	}

	// 报警
	if ( get_map_integer( mp, "20" , nval ) ) {
		gps.alarm = nval ;
	}

	if ( get_map_integer( mp, "9" , nval ) ) {
		gps.vec3  = ntouv32( nval / 10 );
	}

	// 状态
	if ( get_map_integer( mp, "8" , nval ) ) {
		gps.state = nval ;
	}

	gps.state = ntouv32( gps.state ) ;
	gps.alarm = ntouv32( gps.alarm ) ;

	return true ;
}
예제 #12
0
파일: process.c 프로젝트: whr4935/apue
int test_control_priority()
{
	int nzero = 0;
	int pri = 0;
	int ret;
	int pri_min, pri_max;
	int policy;
	pthread_attr_t attr;
	pid_t pid;
	struct sched_param s_param;
	cpu_set_t cpu_set;
	int cpu_total;
	int i;
	pthread_t thr;
	unsigned long long count = 0;

#if 0
	//设置CPU亲和性
	cpu_total = get_nprocs();
	printf("total cpu number: %d\n", cpu_total);

	CPU_ZERO(&cpu_set);
	CPU_SET(0, &cpu_set);
//	CPU_SET(1, &cpu_set);
	ret = sched_setaffinity(0, sizeof(cpu_set_t), &cpu_set);
	if (ret < 0)
		err_sys("sched_setaffinity");

	CPU_ZERO(&cpu_set);
	ret = sched_getaffinity(0, sizeof(cpu_set_t), &cpu_set);
	for (i = 0; i < cpu_total; ++i) {
		if (CPU_ISSET(i, &cpu_set)) {
			printf("current process affinity cpu %d\n", i);
		}
	}
//	printf("sizeof(cpu_set_t) = %d\n", sizeof(cpu_set_t));
#endif
	
#if defined(NZERO)
	nzero = NZERO;
#elif defined(_SC_NZERO)
	nzero = sysconf(_SC_NZERO);
#else
#error NZERO undefined
#endif

	//设置非实时进程优先级
//	pri = getpriority(PRIO_PROCESS, 0);
//	printf("current priority: %d\n", pri);

// 	ret = setpriority(PRIO_PROCESS, 0, -1);		//优先级值越低,占有越多的CPU时间
// 	if (ret < 0)
// 		err_sys("setpriority");

//	pri = getpriority(PRIO_PROCESS, 0);
//	printf("current priority: %d\n", pri);

#if 1
	///////////////////////////////////
	//创建测试线程
	pthread_mutex_init(&priority_mutex, NULL);
	pthread_cond_init(&priority_cond, NULL);

	ret = pthread_barrier_init(&barrier, NULL, 2);
	if (ret != 0)
		err_exit(ret, "pthread_barrier_init");

	ret = pthread_attr_init(&attr);
	if (ret != 0)
		err_exit(ret, "pthread_attr_init");
	pthread_attr_setinheritsched(&attr, PTHREAD_EXPLICIT_SCHED);
	pthread_attr_setschedpolicy(&attr, SCHED_OTHER);
	s_param.__sched_priority = 0;//sched_get_priority_max(SCHED_RR)-11;
	pthread_attr_setschedparam(&attr, &s_param);

	gettimeofday(&end, NULL);
	end.tv_sec += 5;

	ret = pthread_create(&thr, &attr, priority_test_thread, NULL);
	if (ret != 0)
		err_exit(ret, "pthread_create");

	pthread_attr_destroy(&attr);


//	ret= pthread_barrier_wait(&barrier);
//	printf("pthread_barrier_wait return %d\n", ret);
//	printf("main thread continue...\n");

// 	pthread_mutex_lock(&priority_mutex);
// 	notify_signal = 1;
// 	pthread_mutex_unlock(&priority_mutex);
// 	ret = pthread_cond_signal(&priority_cond);
// 	if (ret != 0)
// 		err_exit(ret, "pthread_cond_signal");

	////////////////////////////
	//设置为实时进程
	s_param.__sched_priority = sched_get_priority_max(SCHED_RR) - 10;
	ret = sched_setscheduler(0, SCHED_RR, &s_param);
	if (ret < 0)
		err_sys("sched_setscheduler");

	policy = sched_getscheduler(0);
	if (policy < 0)
		err_sys("policy");

	printf("main thread ");
	switch (policy) {
	case SCHED_FIFO:
		printf("policy SCHED_FIFO!\n");
		break;

	case SCHED_RR:
		printf("policy SCHED_RR!\n");
		break;

	case SCHED_OTHER:
		printf("policy SCHED_OTHER!\n");
		break;

	default:
		printf("policy unknown!\n");
		break;
	}

	ret = sched_getparam(0, &s_param);
	if (ret < 0)
		err_sys("sched_getparam");
	printf("main thread priority: %d\n", s_param.__sched_priority);



	///////////////////////////
	printf("main begin test...\n");
	for (;;) {
		++count;
		if (count == 0)
			err_quit("main count wrap");
		if (checktime("main  ", count) < 0)
			break;
	}

	printf("main wait for exit...\n");
	pthread_join(thr, NULL);

	exit(0);
#endif

	////////////////////////////////////
	pri_max = sched_get_priority_max(SCHED_OTHER);		//pri_max和pri_min都是0,分时调度由nice值影响优先级
	pri_min = sched_get_priority_min(SCHED_OTHER);

	pri_max = sched_get_priority_max(SCHED_RR);
	pri_min = sched_get_priority_min(SCHED_RR);

	pri_max = sched_get_priority_max(SCHED_FIFO);
	pri_min = sched_get_priority_min(SCHED_FIFO);


	gettimeofday(&end, NULL);
	end.tv_sec += 10;
	pid = fork();
	if (pid < 0)
		err_sys("fork");
	else if (pid == 0) {
		policy = sched_getscheduler(0);
		printf("child process policy = %d\n", policy);
		ret = sched_getparam(0, &s_param);
		printf("child prirotiy: %d\n", s_param.__sched_priority);
		s_param.__sched_priority--;
		ret = sched_setparam(0, &s_param);
		if (ret < 0)
			err_sys("sched_setparam");
		ret = sched_getparam(0, &s_param);
		printf("reset child prirotiy: %d\n", s_param.__sched_priority);



// #if 1
// 		ret = setpriority(PRIO_PROCESS, 0, 19);
// 		if (ret < 0)
// 			err_sys("setpriority");
// #else
// 		errno = 0;
// 		if ((pri = nice(19)) == -1 && errno != 0)		//nice函数被setpriority取代
// 			err_sys("nice");
// #endif
// 
// 		errno = 0;
// 		pri = getpriority(PRIO_PROCESS, 0);
// 		if (pri == -1 && errno != 0) {
// 			err_sys("getpriority");
// 		}
// 		printf("child priority: %d\n", pri);

		for (;;) {
			++count;
			if (count == 0)
				err_quit("child count wrap");
			checktime("child ", count);
		}
	} else {
// 		errno = 0;
// 		pri = getpriority(PRIO_PROCESS, 0);
// 		if (pri == -1 && errno != 0) {
// 			err_sys("getpriority");
// 		}
// 		printf("parent priority: %d\n", pri);

		for (;;) {
			++count;
			if (count == 0)
				err_quit("parent count wrap");
			checktime("parent", count);
		}
	}


	return 0;
}
예제 #13
0
파일: dcp.c 프로젝트: swhobbit/UUPC
static KWBoolean master( const char recvGrade,
                       const KWBoolean overrideGrade,
                       const KWBoolean runUUXQT )
{

   CONN_STATE m_state = CONN_INITSTAT;
   CONN_STATE old_state = CONN_EXIT;

   char sendGrade = ALL_GRADES;

   KWBoolean contacted = KWFalse;
   KWBoolean needUUXQT = KWFalse;

/*--------------------------------------------------------------------*/
/*                    Validate the system to call                     */
/*--------------------------------------------------------------------*/

   if ( !equal( Rmtname, "any" ) && !equal( Rmtname, "all" ))
   {
      if ( checkreal( Rmtname ) == NULL )
      {
         printmsg(0,"%s is not \"any\", \"all\", or a valid system to call",
                     Rmtname);
         printmsg(0,"Run UUNAME for a list of callable systems");
         panic();
      }

   }

   if ((fsys = FOPEN(E_systems, "r",TEXT_MODE)) == nil(FILE))
   {
      printerr(E_systems);
      panic();
   }

   setvbuf( fsys, NULL, _IONBF, 0);

   while (m_state != CONN_EXIT )
   {
      printmsg(old_state == m_state ? 10 : 4 ,
               "M state = %c", m_state);
      old_state = m_state;

      switch (m_state)
      {
         case CONN_INITSTAT:
            HostStatus();
            m_state = CONN_INITIALIZE;
            break;

         case CONN_INITIALIZE:
            setTitle("Determining system to call");
            hostp = NULL;

            if ( locked )
               UnlockSystem();

            m_state = getsystem(recvGrade);
            if ( hostp != NULL )
               remote_stats.hstatus = hostp->status.hstatus;
            break;

         case CONN_CHECKTIME:
            sendGrade = checktime(flds[FLD_CCTIME]);

            if ( (overrideGrade && sendGrade) || callnow )
               sendGrade = recvGrade;

            if ( !CallWindow( sendGrade ))
               m_state = CONN_INITIALIZE;
            else if ( LockSystem( hostp->hostname , B_UUCICO))
            {
               dialed = KWTrue;
               time(&hostp->status.ltime);
                              /* Save time of last attempt to call  */
               hostp->status.hstatus = HS_AUTODIAL;
               m_state = CONN_MODEM;
            }
            else
               m_state = CONN_INITIALIZE;

            break;

         case CONN_NOGRADE:
            CallWindow( 0 );        /* Simply to update last time called */
            m_state = CONN_INITIALIZE;
            break;

         case CONN_MODEM:
            if (getmodem(flds[FLD_TYPE]))
               m_state = CONN_DIALOUT;
            else {
               hostp->status.hstatus = HS_INVALID_DEVICE;
               m_state = CONN_INITIALIZE;
            }
            break;

         case CONN_DIALOUT:
            if ( !IsNetwork() )
            {
               setTitle( "Allocating modem on %s", M_device);
               if (suspend_other(KWTrue, M_device ) < 0 )
               {
                  hostp->status.hstatus = HS_NODEVICE;
                  suspend_other(KWFalse, M_device );  /* Resume modem   */
                  m_state = CONN_INITIALIZE;    /* Try next system      */
                  break;
               }
            } /* if */

            setTitle( "Calling %s on %s", rmtname, M_device );
            m_state = callup( );
            break;

         case CONN_PROTOCOL:
            m_state = startup_server( (char)
                                       (bflag[F_SYMMETRICGRADES] ?
                                       sendGrade  : recvGrade) );
            break;

         case CONN_SERVER:
            if (bflag[F_MULTITASK])
               dcupdate();

            setTitle("%s connected to %s", securep->myname, hostp->via );
            m_state = process( POLL_ACTIVE, sendGrade );
            contacted = KWTrue;
            break;

         case CONN_TERMINATE:
            m_state = sysend();

            if ( hostp != NULL )
            {
               if (hostp->status.hstatus == HS_INPROGRESS)
                  hostp->status.hstatus = HS_CALL_FAILED;
               dcstats();
               needUUXQT = KWTrue;
            }
            break;

         case CONN_TIMESET:
            contacted = KWTrue;
            m_state = CONN_DROPLINE;
            break;

         case CONN_DROPLINE:
            setTitle("Closing port %s", M_device);
            shutDown();
            UnlockSystem();
            setTitle("Not connected");

            m_state = CONN_CLEANUP;
            break;

         case CONN_CLEANUP:
            if ( runUUXQT && needUUXQT )
               m_state = CONN_UUXQT;
            else
               m_state = CONN_INITIALIZE;
            break;

         case CONN_UUXQT:
            {
               char buf[100];
               sprintf( buf, "-s %s -x %d", rmtname, debuglevel );
               copylog();
               execute( "uuxqt", buf, NULL, NULL, KWFalse, KWFalse );
               openlog(NULL);
            }
            needUUXQT = KWFalse;
            m_state = CONN_INITIALIZE;
            break;

         case CONN_EXIT:
            break;

         default:
            printmsg(0,"dcpmain: Unknown master state = %c",m_state );
            panic();
            break;
      } /* switch */

      if ( terminate_processing )
         m_state = CONN_EXIT;

   } /* while */

   setTitle("Exiting");

   fclose(fsys);

   return contacted;

} /* master */
예제 #14
0
파일: dcp.c 프로젝트: swhobbit/UUPC
int dcpmain(int argc, char *argv[])
{

   char *logfile_name = NULL;
   KWBoolean  contacted = KWFalse;

   int option;
   int pollMode = POLL_ACTIVE;   /* Default = dial out to system     */
   time_t exitTime = LONG_MAX;

   char recvGrade = ALL_GRADES;
   KWBoolean overrideGrade = KWFalse;
   KWBoolean runUUXQT = KWFalse;

   char *hotUser = NULL;
   BPS  hotBPS = 0;
   int  hotHandle = -1;

   fwork = nil(FILE);

/*--------------------------------------------------------------------*/
/*                        Process our options                         */
/*--------------------------------------------------------------------*/

   while ((option = getopt(argc, argv, "d:g:h:m:l:r:s:tUw:x:z:n?")) != EOF)
      switch (option)
      {

      case 'd':
         exitTime = atoi( optarg );
         exitTime = time(NULL) + hhmm2sec(exitTime);
         pollMode = POLL_PASSIVE;  /* Implies passive polling       */
         break;

      case 'g':
         if (strlen(optarg) == 1 )
            recvGrade = *optarg;
         else {
            recvGrade = checktime( optarg );
                                 /* Get restriction for this hour */
            if ( ! recvGrade )   /* If no class, use the default  */
               recvGrade = ALL_GRADES;
         }
         overrideGrade = KWTrue;
         break;

      case 'h':
         hotHandle = atoi( optarg );   /* Handle opened for us       */
         pollMode = POLL_PASSIVE;  /* Implies passive polling       */
         break;

      case 'm':                     /* Override in modem name     */
         E_inmodem = optarg;
         pollMode = POLL_PASSIVE;  /* Implies passive polling       */
         break;

      case 'l':                     /* Log file name              */
         logfile_name = optarg;
         break;

      case 'n':
         callnow = KWTrue;
         break;

      case 'r':
         pollMode = atoi(optarg);
         break;

      case 's':
         Rmtname = optarg;
         break;

      case 't':
         traceEnabled = KWTrue;
         break;

      case 'U':
         runUUXQT = KWTrue;
         break;

      case 'x':
         debuglevel = atoi(optarg);
         break;

      case 'z':
         hotBPS = (BPS) atoi(optarg);
         pollMode = POLL_PASSIVE;  /* Implies passive polling       */
         break;

      case 'w':
         pollMode = POLL_PASSIVE;  /* Implies passive polling       */
         hotUser = optarg;
         break;

      case '?':
         puts("\nUsage:\tuucico\t"
         "[-s [all | any | sys]] [-r 1|0] [-d hhmm]\n"
         "\t\t[-l logfile] [-n] [-t] [-U] [-x debug]\n"
         "\t\t[-h handle] [-m modem] [-z bps]");
         return 4;
      }

/*--------------------------------------------------------------------*/
/*                Abort if any options were left over                 */
/*--------------------------------------------------------------------*/

   if (optind != argc) {
      puts("Extra parameter(s) at end.");
      return 4;
   }

/*--------------------------------------------------------------------*/
/*        Initialize logging and the name of the systems file         */
/*--------------------------------------------------------------------*/

   openlog( logfile_name );

   if (bflag[F_SYSLOG] && ! bflag[F_MULTITASK])
   {
      syslog = FOPEN(SYSLOG, "a",TEXT_MODE);
      if ((syslog == nil(FILE)) || setvbuf( syslog, NULL, _IONBF, 0))
      {
         printerr( SYSLOG );
         panic();
      }
   }

   PushDir(E_spooldir);
   atexit( PopDir );

   if ( terminate_processing )
      return 100;

/*--------------------------------------------------------------------*/
/*                        Initialize security                         */
/*--------------------------------------------------------------------*/

   if ( !LoadSecurity())
   {
      printmsg(0,"Unable to initialize security, see previous message");
      panic();
   }

   if ( terminate_processing )
      return 100;

#if defined(_Windows)
   atexit(CloseEasyWin);       /* Auto-close EasyWin window on exit   */
#endif

   atexit( shutDown );        /* Insure port is closed by panic()    */
   remote_stats.hstatus = HS_NOCALL;
                              /* Known state for automatic status
                                 update                              */

/*--------------------------------------------------------------------*/
/*                     Begin main processing loop                     */
/*--------------------------------------------------------------------*/

   if (pollMode == POLL_ACTIVE)
      contacted = master(recvGrade, overrideGrade, runUUXQT );
   else if (pollMode == POLL_PASSIVE)
      contacted = client(exitTime,
                         hotUser,
                         hotBPS,
                         hotHandle,
                         runUUXQT);
   else {
      printmsg(0,"Invalid -r flag, must be 0 or 1");
      panic();
   }

/*--------------------------------------------------------------------*/
/*                         Report our results                         */
/*--------------------------------------------------------------------*/

   if (!contacted && (pollMode == POLL_ACTIVE))
   {
      if (dialed)
         printmsg(0, "Could not connect to remote system.");
      else
         printmsg(0,
               "No work for requested system or wrong time to call.");
   }

   dcupdate();

   if (bflag[F_SYSLOG] && ! bflag[F_MULTITASK])
      fclose(syslog);

   return terminate_processing ? 100 : (contacted ? 0 : 5);

} /* dcpmain */
예제 #15
0
파일: Week1.c 프로젝트: daeken/Straylight
void render() {
	int i, x, y, off = 0;
	float prev = 0.0;
	
	checktime();
	
	glLoadIdentity();
	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
	
	glTranslatef(0.0, 5.0, -ZOOM);
	glRotatef(60, 1.0, 0.0, 0.0);
	
	glColor3f(0.0, 1.0, 0.0);
	for(i = 0; i < DROPCOUNT; ++i) {
		if(drops[i].offset == -1)
			continue;
		
		if(drops[i].height > 1.0) {
			int off = drops[i].offset;
			
			glPushMatrix();
			
			glTranslatef(((off % GRID_WIDTH) - GRID_HH) * SPACING, drops[i].height, (off / GRID_WIDTH - GRID_HW) * SPACING);
			glScalef(0.5, 1.1, 0.5);
			
			glCallList(sphere);
			
			glPopMatrix();
			drops[i].height -= 1.0;
		} else {
			if(grid[drops[i].offset] >= 0.1)
				grid[drops[i].offset] -= 0.5;
			else
				grid[drops[i].offset] += 0.5;
			drops[i].offset = -1;
		}
	}
	
	updateGrid();
	
	glColor3f(0.0, 0.0, 1.0);
	
	glTranslatef(GRID_HW * SPACING, 0.0, -GRID_HH * SPACING);
	for(y = 0; y < GRID_HEIGHT; ++y) {
		glTranslatef(-GRID_WIDTH * SPACING, -prev, SPACING);
		prev = 0.0;
		
		for(x = 0; x < GRID_WIDTH; ++x, ++off) {
			if(gridText[off] == 1)
				glColor4f(textColor, 0.0, 1.0 - textColor, 0.4 + (0.6 * textColor));
			else {
				if(gridText[off] != 0)
					--gridText[off];
				glColor4f(0.0, 0.0, 1.0, 0.4);
			}
			glTranslatef(SPACING, grid[off]-prev, 0.0);
			glCallList(sphere);
			
			prev = grid[off];
		}
	}
	
	if(textTransition && textColor > 0.0) {
		textColor -= 0.05;
		if(textColor < 0.0)
			textColor = 0.0;
	}
}
예제 #16
0
static tr_tristate_t
pulsereq( tr_natpmp_t * pmp )
{
    tr_natpmp_req_t  * req = pmp->req;
    struct sockaddr_in sin;
    uint8_t            buf[16];
    int                res;
    uint64_t           now;
    tr_tristate_t      ret;
    tr_natpmp_parse_t  parse;

    now = tr_date();
    /* check for timeout */
    if( now >= req->timeout )
    {
        tr_dbg( "nat-pmp request timed out" );
        req->nobodyhome = 1;
        return TR_NET_ERROR;
    }
    /* send another request  if it's been long enough */
    if( now >= req->retry && sendreq( req ) )
    {
        return TR_NET_ERROR;
    }

    /* check for incoming packets */
    res = tr_netRecvFrom( req->fd, buf, sizeof( buf ), &sin );
    if( TR_NET_BLOCK & res )
    {
        return TR_NET_WAIT;
    }
    else if( TR_NET_CLOSE & res )
    {
        if( ECONNRESET == errno || ECONNREFUSED == errno )
        {
            tr_dbg( "nat-pmp not supported by device" );
            req->nobodyhome = 1;
        }
        else
        {
            tr_inf( "error reading nat-pmp response (%s)", strerror( errno ) );
        }
        return TR_NET_ERROR;
    }

    /* parse the packet */
    tr_dbg( "nat-pmp read %i byte response", res );
    ret = parseresponse( buf, res, req->askport, &parse );
    req->tmpfail = parse.tmpfail;
    /* check for device reset */
    if( checktime( &pmp->uptime, parse.seconds ) )
    {
        pmp->renew = 0;
        tr_inf( "detected nat-pmp device reset" );
        resetreq( req );
        ret = TR_NET_WAIT;
    }
    if( TR_NET_OK == ret && req->adding )
    {
        if( req->askport != parse.port )
        {
            tr_dbg( "nat-pmp received %i for public port instead of %i",
                    parse.port, req->askport );
            req->gotport = parse.port;
        }
        tr_dbg( "nat-pmp set renew to half of %u", parse.lifetime );
        pmp->renew = now + ( parse.lifetime / 2 * 1000 );
    }

    return ret;
}
예제 #17
0
파일: process.c 프로젝트: whr4935/apue
//测试线程是否继承创建者的调度规则和优先级
static void* priority_test_thread(void* arg)
{
	cpu_set_t cpu_set;
	int ret;
	int policy;
	int priority;
	struct sched_param s_param;
	int i;
	int cpu_total = get_nprocs();
	int tid;
	unsigned long long count = 0;
	struct timespec t_spec;
	int id;
	pthread_attr_t attr;

	id = 0;
	//	id = getpid();
	id = gettid();
	//	id = pthread_self();

	//	printf("tid: %d, pthread_self id: %d\n", gettid(), pthread_self());

	//	pthread_detach(pthread_self());


	setpriority(PRIO_PROCESS, 0, -2);

	policy = sched_getscheduler(id);
	printf("thread ");
	switch (policy) {
	case SCHED_FIFO:
		printf("policy SCHED_FIFO!\n");
		break;

	case SCHED_RR:
		printf("policy SCHED_RR!\n");
		break;

	case SCHED_OTHER:
		printf("policy SCHED_OTHER!\n");
		break;

	default:
		printf("policy unknown!\n");
		break;
	}


	if (policy == SCHED_OTHER) {
		ret = getpriority(PRIO_PROCESS, 0);
		priority = ret;
	} else {
		ret = sched_getparam(id, &s_param);
		if (ret < 0)
			err_sys("sched_getparam");
		priority = s_param.__sched_priority;
	}

	printf("thread priority: %d\n", priority);
	
// 
// 
// 	tid = gettid();
//  	CPU_ZERO(&cpu_set);
//   	ret = sched_getaffinity(0, sizeof(cpu_set_t), &cpu_set);
// 	if (ret < 0)
// 		err_sys("ret");
// 	for (i = 0; i < cpu_total; ++i) {
// 		if (CPU_ISSET(i, &cpu_set)) {
// 			printf("thread affinity cpu %d\n", i);
// 		}
// 	}
	
// 	ret = pthread_barrier_wait(&barrier);
// 	if (ret != 0 && ret != PTHREAD_BARRIER_SERIAL_THREAD) {
// 		err_exit(ret, "pthread_barrier_wait");
// 	}

//	pthread_exit(0);

// 	t_spec.tv_sec = 2;
// 	t_spec.tv_nsec = 0;
// 	ret = pthread_mutex_lock(&priority_mutex);
// 	if (ret != 0)
// 		err_exit(ret, "pthread_mutex_lock");
// 	while (notify_signal == 0) {
// 		//pthread_cond_timedwait(&priority_cond, &priority_mutex, &t_spec);
// 		pthread_cond_wait(&priority_cond, &priority_mutex);
// 	}
// 	pthread_mutex_unlock(&priority_mutex);

	printf("thread begin test...\n");
	for (;;) {
		++count;
		if (count == 0)
			err_quit("thread count wrap");
		if (checktime("thread", count) < 0)
			break;
	}

	printf("thread exit...\n");
}