Ejemplo n.º 1
0
char *test_Server_adds()
{
    int rc = 0;

    Server *srv = Server_create(
            bfromcstr("uuid"),
            bfromcstr("localhost"),
            bfromcstr("0.0.0.0"),
            8080,
            bfromcstr("chroot"),
            bfromcstr("access_log"),
            bfromcstr("error_log"),
            bfromcstr("pid_file"),
            NULL,
            0);
    mu_assert(srv != NULL, "Failed to make the server, something on 8090?");

    Host *host = Host_create(bfromcstr("zedshaw.com"), bfromcstr("zedshaw.com"));
    mu_assert(host != NULL, "Failed to make host.");

    rc = Server_add_host(srv, host);
    mu_assert(rc == 0, "Failed to add host to server.");

    Server_set_default_host(srv, host);

    Host *zedshaw = Server_match_backend(srv, host->name);
    mu_assert(zedshaw == host, "Didn't get the right one back.");

    mu_assert(Server_match_backend(srv, bfromcstr("NOWAY")) == host, "Didn't fall back to default_host");

    Server_destroy(srv);

    return NULL;
}
Ejemplo n.º 2
0
char *test_Server_create_destroy()
{
    Server *server = Server_create("uuid", "8080", "chroot", "access_log", "error_log", "pid_file");
    mu_assert(server != NULL, "Failed to make the server, something on 8090?");

    Server_destroy(server);

    return NULL;
}
Ejemplo n.º 3
0
char *test_Server_adds()
{
    int rc = 0;

    Server *srv = Server_create("uuid", "8080", "chroot", "access_log", "error_log", "pid_file");
    mu_assert(srv != NULL, "Failed to make the server, something on 8090?");

    Host *host = Host_create("zedshaw.com");
    mu_assert(host != NULL, "Failed to make host.");

    rc = Server_add_host(srv, bstrcpy(host->name), host);
    mu_assert(rc == 0, "Failed to add host to server.");

    Server_destroy(srv);

    return NULL;
}
Ejemplo n.º 4
0
char *test_Server_create_destroy()
{
    Server *server = Server_create(
            bfromcstr("uuid"),
            bfromcstr("localhost"),
            bfromcstr("0.0.0.0"),
            8080,
            bfromcstr("chroot"),
            bfromcstr("access_log"),
            bfromcstr("error_log"),
            bfromcstr("pid_file"), 0);
    mu_assert(server != NULL, "Failed to make the server, something on 8090?");

    Server_destroy(server);

    return NULL;
}
Ejemplo n.º 5
0
Archivo: main.c Proyecto: jdp/ephemeron
int
main(int argc, char **argv) 
{
	Server *server;
	
	/* Start up the server */
	server = Server_create();
	if (server == NULL) {
		ERROR("server create failed\n");
		return 1;
	}
	if (!Server_configure(server)) {
		ERROR("server configure failed\n");
		return 1;
	}
	Server_serve(server);
		
	return 0;
}
Ejemplo n.º 6
0
/*
 *  ======== smain ========
 */
Void smain(UArg arg0, UArg arg1)
{
    Int                 status = 0;

    Log_print0(Diags_ENTRY | Diags_INFO, "--> smain:");

    /* initialize modules */
    Server_init();

    /* turn on Diags_INFO trace */
    Diags_setMask("Server+F");

    /* server setup phase */
    status = Server_create();

    if (status < 0) {
        goto leave;
    }

    /* server execute phase */
    status = Server_exec();

    if (status < 0) {
        goto leave;
    }

    /* server shutdown phase */
    status = Server_delete();

    if (status < 0) {
        goto leave;
    }

    /* finalize modules */
    Server_exit();

leave:
    Log_print1(Diags_EXIT, "<-- smain: %d", (IArg)status);
    return;
}
Ejemplo n.º 7
0
int main(int argc, char *argv[]){
    logging_init();
    logmsg(LOG_INFO, "Server started and logging started.");
    int xsize = DEFAULT_X_SIZE;
    int zsize = DEFAULT_Z_SIZE;
    char *filename = NULL;
    char *out_name = NULL;
    for(int i=0; i < argc; i++){
	if (strcmp("-s", argv[i])== 0){
	    xsize = atoi(argv[i+1]);
	    zsize = atoi(argv[i+2]);
	    i += 2;
	} else if (strcmp("-f", argv[i]) == 0){
	    filename = argv[i+1];
	} else if (strcmp("-o", argv[i]) == 0){
	    out_name = argv[i+1];
	}
    }
    
    Map *map;
    if (filename == NULL){
	map = Map_new_air(xsize,zsize);
	Block b;
	b.id = 1;
	b.metadata = 0;
    
	Map_set_below(map, b, 60);
    
	b.id=20; map->chunks[0]->blocks[0] = b; //Debugging

	if (out_name != NULL){
	    filename = out_name;
	}
    } else {
	map = Map_read(filename);
    }
    
    Server *server = Server_create(map, 10);
    sigint_server = server;
    server->is_running = 1;
    server->filename = filename;
    signal(SIGINT, catch_sigint);
    
    pthread_create(&(server->distributor_thread),
		   NULL, &connection_distributor_thread, server);
    
    logmsg(LOG_INFO, "Distributor thread started.");

    struct timespec sleeptime;
    sleeptime.tv_sec = 0;
    sleeptime.tv_nsec = 50000000; // 50 ms.
    while (server->is_running){
	pthread_rwlock_wrlock(&server->state_lock);
	pthread_rwlock_wrlock(&server->players_lock);
	Server_tick(server);
	pthread_rwlock_unlock(&server->state_lock);
	pthread_rwlock_unlock(&server->players_lock);
	nanosleep(&sleeptime, NULL);
    }
    pthread_join(server->distributor_thread, NULL);
    logmsg(LOG_INFO, "Server shutting down!");

    return 0;
}