コード例 #1
0
ファイル: clientcontrol.cpp プロジェクト: drtrev/geo
void Clientcontrol::go()
  // main loop
{
  // client stats
  timer.update(); // to set current time for stats
  timeval statProgramStart = timer.getCurrent();

  // loop frequencies in Hz (calls per second)
  // these are not shared (i.e. not in controller.cpp) - might want them different on client and server
  // (not sure why, but might!) - also most aren't relevant to server
  int inputfreq = 20; // if too low then press and release will be processed in same loop and key will be ignored
  int networkfreq = 30; // if too low then graphics appear jerky without dead reckoning
  int physicsfreq = 100;
  int graphicsfreq = 60; // was 60
  int soundfreq = 40;
  int transferfreq = 10;

  int inputdelay = (int) round(1000000.0/inputfreq); // delay in microseconds
  int networkdelay = (int) round(1000000.0/networkfreq);
  int physicsdelay = (int) round(1000000.0/physicsfreq);
  int graphicsdelay = (int) round(1000000.0/graphicsfreq);
  int sounddelay = (int) round(1000000.0/soundfreq);
  int transferdelay = (int) round(1000000.0/transferfreq);

  timeval inputtime, networktime, physicstime, graphicstime, soundtime, transfertime;

  // timer updated above
  inputtime = timer.getCurrent();
  networktime = timer.getCurrent();
  physicstime = timer.getCurrent();
  graphicstime = timer.getCurrent();
  soundtime = timer.getCurrent();
  transfertime = timer.getCurrent();

  while (!(keys & KEYS_QUIT) && client.getConnected()) {
    timer.update();

    doloop(inputdelay, inputtime, &Clientcontrol::inputloop);
    doloop(networkdelay, networktime, &Clientcontrol::networkloop);
    doloop(physicsdelay, physicstime, &Clientcontrol::physicsloop);
    if (graphicsActive) doloop(graphicsdelay, graphicstime, &Clientcontrol::graphicsloop);
    doloop(sounddelay, soundtime, &Clientcontrol::soundloop);
    doloop(transferdelay, transfertime, &Clientcontrol::transferloop);

#ifdef _MSC_VER
	Sleep(1); // bit longer
#else
    usleep(1000);
#endif
  }

  timeval statProgramDuration = timer.elapsed(statProgramStart);
  double statProgramDurationDbl = statProgramDuration.tv_sec + statProgramDuration.tv_usec / 1000000.0;
  int bytesRecv = client.getStatRecvd();
  int bytesSend = client.getStatSent();
  int total = bytesRecv + bytesSend;
  double rate = total / statProgramDurationDbl;
  std::cerr << "Stats.\nRecv: " << bytesRecv << "\nSent: " << bytesSend << "\nTotal: " << total
    << "\nDuration: " << statProgramDurationDbl << "\nRate: " << rate << "\n";
}
コード例 #2
0
ファイル: main.c プロジェクト: prophile/dim3
int main(int argc,char *argv[])
{
	app_init();
	
	menu_start();
    open_model_xml();
	
	doloop();

	app_shutdown();
    
    return(0);
}
コード例 #3
0
ファイル: simple_txn.c プロジェクト: kanbang/Colt
int
main(int argc, char *argv[])
{
    extern char *optarg;
    DB_ENV *dbenv;
    const char *home;
    char ch;
    int ret;

    dbenv = NULL;

    ret = 0;
    home = NULL;

    /* Create and configure the environment handle. */
    if ((ret = create_env(progname, &dbenv)) != 0)
	goto err;

    /* Collect the command line options. */
    while ((ch = getopt(argc, argv, "h:")) != EOF)
	switch (ch) {
	case 'h':
	    home = optarg;
	    break;
	case '?':
	default:
	    usage();
	}

    /* Error check command line. */
    if (home == NULL)
	usage();

    /* Open the environment. */
    if ((ret = env_init(dbenv, home)) != 0)
      goto err;

    if ((ret = doloop(dbenv)) != 0) {
	dbenv->err(dbenv, ret, "Application failed");
	goto err;
    }

err: if (dbenv != NULL)
	(void)dbenv->close(dbenv, 0);

    return (ret);
}
コード例 #4
0
ファイル: CourseDesign.c プロジェクト: jinjaysnow/Jay
char *semanticAnalysis(int *i){
	char *temp;
	temp = (char*)malloc(BUFSIZ*sizeof(char));
	switch(wordIndex[*i]){
		case 10:sprintf(temp,"%s%s",temp,assignment(i));break;
		case 6 :sprintf(temp,"%s%s",temp,condition(i));break;
		case 8 :sprintf(temp,"%s%s",temp,doloop(i));break;
		case 29:return NULL;
		default:return NULL;
	};
	if(ifNumber){
		sprintf(temp,"%s%s",temp,semanticAnalysis(i));
		return temp;
	}
	else{
		semanticAnalysis(i);
		return NULL;
	}
}
コード例 #5
0
ファイル: doloop.c プロジェクト: eribul/survival
int doloop (int nloops, int *index) {
    register int i;

    if (firsttime ==1) {
	for (i=0; i<nloops; i++)  index[i] =minval+i;
	firsttime =0;
	if (maxval >= (minval+i)) return (minval+i-1);
	    else                  return (minval-1);
	}

    nloops--;
    index[nloops]++;    /*increment the lastmost index */

    if (index[nloops] <= (maxval-depth)) return(index[nloops]);
    else if (nloops ==0)                 return(minval - depth);
	 else {
	    depth++;
	    index[nloops] = doloop(nloops, index) +1;
	    depth--;
	    return(index[nloops]);
	    }
    }
コード例 #6
0
ファイル: rep_mgr_gsg.c プロジェクト: CompassHXM/h-store
int
main(int argc, char *argv[])
{
    DB_ENV *dbenv;
    DB_SITE *dbsite;
    extern char *optarg;
    const char *home;
    char ch, *host, *portstr;
    int local_is_set, ret, is_group_creator;
    u_int16_t port;
    /* Used to track whether this is a replica or a master. */
    APP_DATA my_app_data;

    dbenv = NULL;
    ret = local_is_set = is_group_creator = 0;
    home = NULL;

    my_app_data.is_master = 0;  /* Assume that we start as a replica */

    if ((ret = create_env(progname, &dbenv)) != 0)
	goto err;

    /* Make APP_DATA available through the environment handle. */
    dbenv->app_private = &my_app_data;

    /* Default priority is 100. */
    dbenv->rep_set_priority(dbenv, 100);
    /* Permanent messages require at least one ack. */
    dbenv->repmgr_set_ack_policy(dbenv, DB_REPMGR_ACKS_ONE);
    /* Give 500 microseconds to receive the ack. */
    dbenv->rep_set_timeout(dbenv, DB_REP_ACK_TIMEOUT, 500);

    /* Collect the command line options. */
    while ((ch = getopt(argc, argv, "h:l:L:p:r:")) != EOF)
	switch (ch) {
	case 'h':
	    home = optarg;
	    break;
	/* Set the host and port used by this environment. */
	case 'L':
	    is_group_creator = 1; /* FALLTHROUGH */
	case 'l':
	    host = strtok(optarg, ":");
	    if ((portstr = strtok(NULL, ":")) == NULL) {
		fprintf(stderr, "Bad host specification.\n");
		goto err;
	    }
	    port = (unsigned short)atoi(portstr);
	    if ((ret =
	      dbenv->repmgr_site(dbenv, host, port, &dbsite, 0)) != 0){
		fprintf(stderr, "Could not set local address %s:%d.\n",
		  host, port);
		goto err;
	    }
	    dbsite->set_config(dbsite, DB_LOCAL_SITE, 1);
	    if (is_group_creator)
		dbsite->set_config(dbsite, DB_GROUP_CREATOR, 1);

	    if ((ret = dbsite->close(dbsite)) != 0) {
		dbenv->err(dbenv, ret, "DB_SITE->close");
		goto err;
	}
	    local_is_set = 1;
	    break;
	/* Set this replica's election priority. */
	case 'p':
	    dbenv->rep_set_priority(dbenv, atoi(optarg));
	    break;
	/* Identify another site in the replication group. */
	case 'r':
	    host = strtok(optarg, ":");
	    if ((portstr = strtok(NULL, ":")) == NULL) {
		fprintf(stderr, "Bad host specification.\n");
		goto err;
	    }
	    port = (unsigned short)atoi(portstr);
	    if ((ret = dbenv->repmgr_site(dbenv, host, port, &dbsite, 0)) != 0) {
		dbenv->err(dbenv, ret, "DB_ENV->repmgr_site");
		goto err;
	    }
	    dbsite->set_config(dbsite, DB_BOOTSTRAP_HELPER, 1);
	    if ((ret = dbsite->close(dbsite)) != 0) {
		dbenv->err(dbenv, ret, "DB_SITE->close");
		goto err;
	    }
	    break;
	case '?':
	default:
	    usage();
	}

    /* Error check command line. */
    if (home == NULL || !local_is_set)
	usage();

    if ((ret = env_init(dbenv, home)) != 0)
	goto err;

    if ((ret = dbenv->repmgr_start(dbenv, 3, DB_REP_ELECTION)) != 0)
	goto err;

    if ((ret = doloop(dbenv)) != 0) {
	dbenv->err(dbenv, ret, "Application failed");
	goto err;
    }

err: if (dbenv != NULL)
	(void)dbenv->close(dbenv, 0);

    return (ret);

}
コード例 #7
0
ファイル: yersinia.c プロジェクト: digininja/yersinia
/*
 * Thread for handling command line attacks (TERM_TTY)
 * Use global variable struct term_tty *tty_tmp
 */
void *
th_tty_peer(void *args)
{
   int fail;
   time_t this_time;
   struct cl_args *arguments;
   struct term_tty *tty;
   struct term_node *term_node=NULL;
   sigset_t mask;
   
   terms->work_state = RUNNING;
   
write_log(0, "\n th_tty_peer thread = %d...\n",(int)pthread_self());
   
   sigfillset(&mask);
   
   if (pthread_sigmask(SIG_BLOCK, &mask,NULL))
   {
      thread_error("th_tty_peer pthread_sigmask()",errno);
      th_tty_peer_exit(NULL);
   }   

   if (pthread_mutex_lock(&terms->mutex) != 0)
   {
      thread_error("th_tty_peer pthread_mutex_lock",errno);
      th_tty_peer_exit(NULL);
   }
   
   fail = term_add_node(&term_node, TERM_TTY, (int)NULL, pthread_self());

   if (fail == -1)
   {
      if (pthread_mutex_unlock(&terms->mutex) != 0)
         thread_error("th_tty_peer pthread_mutex_unlock",errno);
      th_tty_peer_exit(term_node);
   }

   if (term_node == NULL)
   {
      write_log(1,"Ouch!! No more than %d %s accepted!!\n",
                  term_type[TERM_TTY].max, term_type[TERM_TTY].name);
      
      if (pthread_mutex_unlock(&terms->mutex) != 0)
         thread_error("th_tty_peer pthread_mutex_unlock",errno);
      th_tty_peer_exit(term_node);
   }

   tty = term_node->specific;

   memcpy(tty,tty_tmp,sizeof(struct term_tty));    

    this_time = time(NULL);
   
#ifdef HAVE_CTIME_R
#ifdef SOLARIS
    ctime_r(&this_time,term_node->since, sizeof(term_node->since));
#else
    ctime_r(&this_time,term_node->since);
#endif
#else
    pthread_mutex_lock(&mutex_ctime);
    strncpy(term_node->since, ctime(&this_time), sizeof(term_node->since));   
    pthread_mutex_unlock(&mutex_ctime);
#endif

    /* Just to remove the cr+lf...*/
    term_node->since[sizeof(term_node->since)-2] = 0;

    /* This is a tty so, man... ;) */
    strncpy(term_node->from_ip, "127.0.0.1", sizeof(term_node->from_ip));

   /* Parse config file */
   if (strlen(tty_tmp->config_file))
      if (parser_read_config_file(tty_tmp, term_node) < 0)
      {
         write_log(0, "Error reading configuration file\n");
         th_tty_peer_exit(term_node);
      }
   
    if (init_attribs(term_node) < 0)        
    {
       if (pthread_mutex_unlock(&terms->mutex) != 0)
         thread_error("th_tty_peer pthread_mutex_unlock",errno);
       th_tty_peer_exit(term_node);
    }

    arguments = args;
    
    /* In command line mode we initialize the values by default */
    if (protocols[arguments->proto_index].init_attribs)
    {
        fail = (*protocols[arguments->proto_index].init_attribs)
            (term_node);
    } else
        write_log(0, "Warning, proto %d has no init_attribs function!!\n", arguments->proto_index);

    /* Choose a parser */
    fail = parser_cl_proto(term_node, arguments->count, arguments->argv_tmp, arguments->proto_index);

   if (pthread_mutex_unlock(&terms->mutex) != 0)
      thread_error("th_tty_peer pthread_mutex_unlock",errno);
   
   if (fail < 0) {
       write_log(0, "Error when parsing...\n");
       th_tty_peer_exit(term_node);
   }
      
   write_log(0, "Entering command line mode...\n");
   /* Execute attack... */
   doloop(term_node, arguments->proto_index);
   
   th_tty_peer_exit(term_node);
   
   return(NULL);
}