示例#1
0
int main(int argc, char *argv[]) { 
  allegro_init();

  if (argc < 2) {
    allegro_message("Usage: %s files ...\n", argv[0]);
    return 1;
  }

  install_timer();
  install_keyboard();

  if (set_gfx_mode(GFX_SAFE, 640, 480, 0, 0) < 0) {
    allegro_message("Error setting video mode.\n");
    return 1;
  }
  clear_to_color(screen, makecol(255, 255, 255));

  /* to achieve the max possible volume */
  set_volume_per_voice(0);

  if (install_sound(DIGI_AUTODETECT, MIDI_NONE, 0) < 0) {
    set_gfx_mode(GFX_TEXT, 0, 0, 0, 0);
    allegro_message("Error installing sound.\n");
    return 1;
  }

  do_example(argc-1, argv+1);

  allegro_exit();

  return 0;
}
int
main(int argc, char **argv)
{
	config g_config;
	memset(&g_config, 0, sizeof(g_config));
	
	g_config.host = "127.0.0.1";
	g_config.port = 3000;
	g_config.ns = "test";
	g_config.set = "example_set";
	g_config.verbose = false;
	g_config.follow = true;
	
	bool use_shm = false;
	int	c;
	
	printf("example of the C citrusleaf library\n");
	
	while ((c = getopt(argc, argv, "h:p:n:s:b:m:vr")) != -1)
	{
		switch (c)
		{
		case 'h':
			g_config.host = strdup(optarg);
			break;
		
		case 'p':
			g_config.port = atoi(optarg);
			break;
		
		case 'n':
			g_config.ns = strdup(optarg);
			break;
			
		case 's':
			g_config.set = strdup(optarg);
			break;

		case 'm':
			g_config.timeout_ms = atoi(optarg);
			break;
			
		case 'v':
			g_config.verbose = true;
			break;

		case 'f':
			g_config.follow = false;
			break;
			
		case 'r':
			use_shm = true;
			break;

		default:
			usage();
			return(-1);
			
		}
	}

	fprintf(stderr, "example: host %s port %d ns %s set %s\n",
		g_config.host,g_config.port,g_config.ns,g_config.set);

	if (use_shm) {
		citrusleaf_use_shm(10,788722985);
	}

	// init the unit before creating any clusters
	int rv = citrusleaf_init();
	if(rv!=0) {
		fprintf(stderr,"Citrusleaf init failed\n");
	}
	
	// Create a citrusleaf cluster object for subsequent requests
	g_config.asc = citrusleaf_cluster_create();
	if (!g_config.asc) {
		fprintf(stderr, "could not create cluster, internal error\n");
		return(-1);
	}
	if (g_config.follow == false)
		citrusleaf_cluster_follow(g_config.asc, false);
	
	citrusleaf_cluster_add_host(g_config.asc, g_config.host, g_config.port, 200 /*timeout*/);

	// Make some example requests against the cluster
	if (0 != do_example(&g_config)) {
		fprintf(stderr, "example failed!\n");
		return(-1);
	}
	fprintf(stderr, "example succeeded!\n");
	citrusleaf_shutdown();
	return(0);
}