Exemplo n.º 1
0
static void timescale () {
    // timer with timescale
    int id = ex_add_timer( ex_timespan_from(0,2000), _callback1, NULL, 0 );

    ex_start_timer(id); ex_log("start!");
    ex_sleep(4000);
    ex_set_timescale(0.5f);
    ex_sleep(5000);
    ex_set_timescale(1.0f);
    ex_remove_timer(id); ex_log("stop!");
}
Exemplo n.º 2
0
static void normal () {
    // uint32 start,counter;
    int id = ex_add_timer( ex_timespan_from(0,500), _callback1, NULL, 0 );
    ex_start_timer(id);

    ex_sleep(2000);
    ex_pause_timer(id);
    ex_sleep(2000);
    ex_resume_timer(id);

    ex_sleep(4000);

    // start = counter = ex_timer_get_ticks();
    // while (1) {
    //     counter = ex_timer_get_ticks() - start;
    //     // printf( "seconds %f\n", (float)counter/1000.0f );
    //     ex_sleep(10);
    // }
}
Exemplo n.º 3
0
static int thread_func1 ( void *_data ) {
    int counter = 20;
    ex_log ("this is thread1");
    while ( counter > 0 ) {
        ex_log ("thread1 tick");
        ex_sleep(1000);
        --counter;
    }
    ex_log ("thread1 ended");
	return 1;
}
Exemplo n.º 4
0
static void normal () {
    int counter = 5;
    ex_thread_t *thread1 = ex_create_thread ( thread_func1, NULL );
    while ( counter > 0 ) {
        ex_log ("main tick");
        ex_sleep(1000);
        --counter;
    }
    ex_log ("main waiting thread1");
    ex_wait_thread ( thread1, NULL );
    ex_log ("main thread ended");
}
Exemplo n.º 5
0
static void lifetime () {
    uint32 start,counter;
    int id = ex_add_timer( ex_timespan_from(0,500), _callback1, NULL, 0 );
    ex_start_timer(id);

    start = counter = ex_timer_get_ticks();
    ex_sleep(5000);
    // while (1) {
    //     counter = ex_timer_get_ticks() - start;
    //     // printf( "seconds %f\n", (float)counter/1000.0f );
    //     ex_sleep(10);
    // }
}
Exemplo n.º 6
0
int ex_uninit()
{
	ExContext.quitFlag = 1;
	while (ExContext.threadCnt > 0)
		ex_sleep(EX_SOCK_RTT);

	cgi_uninit();

	ex_hash_clear(&ExContext.mimeMap);
	ex_hash_clear(&ExContext.pageMap);
	printf("eServ terminated.\n");
	return 0;
}
Exemplo n.º 7
0
int main(void)
{
	
  ex_init( ) ;
  char buf[16] ;
  while ( scanf( "%16s", buf )>0 ) {
    if ( strncmp( "quit", buf, 4 )==0 )
      break ;
    ex_sleep( 200 ) ;
  }
  ex_uninit( ) ;
  return 0 ;
}
Exemplo n.º 8
0
static int ex_http_start()
{
	SOCKET ser_fd, cli_fd;  /* listen on sock_fd, new connection on new_fd */
	struct sockaddr_in ser_addr, cli_addr; /* connector's address information */
	int opt, sin_size;

	/* Setup the default values */
	struct timeval tv;
	tv.tv_sec = 0;
	tv.tv_usec = EX_SOCK_RTT * 1000;

	/*
	* Setup the sockets and wait and process connections
	*/
	if ((ser_fd = socket(AF_INET, SOCK_STREAM, 0)) == -1) {
		perror("socket");
		exit(1);
	}

	/* Let the kernel reuse the socket address. This lets us run
	   twice in a row without waiting for the (ip, port) tuple
	   to time out. */
	opt = 1;
	setsockopt(ser_fd, SOL_SOCKET, SO_REUSEADDR, (char *)&opt, sizeof(opt));
	setsockopt(ser_fd, SOL_SOCKET, SO_RCVTIMEO, (char *)&tv, sizeof(tv));

	ser_addr.sin_family = AF_INET;		/* host byte order */
	ser_addr.sin_port = htons(PORT);	/* short, network byte order */
	ser_addr.sin_addr.s_addr = INADDR_ANY;	/* auto-fill with my IP */

	if (bind(ser_fd, (struct sockaddr *) &ser_addr,
	         sizeof(struct sockaddr)) == -1) {
		perror("bind");
		exit(1);
	}

	if (listen(ser_fd, EX_SOCK_BACKLOG) == -1) {
		perror("listen");
		exit(1);
	}

	if (chdir(RootPath) != 0) {
		perror("chdir");
		exit(1);
	}

	DBG("\n " SERVER " is running.  Port: %d\n", PORT);

	sin_size = sizeof(struct sockaddr_in);
	while (1) {  /* main accept() loop */
		if (ExContext.quitFlag == 1)
			break;
		if ((cli_fd = accept(ser_fd,
		                     (struct sockaddr *) & cli_addr,
				     (socklen_t *) &sin_size)) == -1)
			continue;
		while (1) {
			if (ExContext.threadCnt < EX_MAX_THREADS) {
				start_thread((void *) requestHandler,
				             (void *) &cli_fd);
				break;
			} else
				ex_sleep(50);
		}
	}
	return 0;
}