示例#1
0
文件: main.cpp 项目: Hefting/HarmonIQ
int main()
{
    /* Create instances of needed components */
    auto msg_center =
        std::make_shared<messaging::message_center>();


    /* Start socket listeners managed by server_manager */
    auto sess_iface =
        std::static_pointer_cast<messaging::session_interface>(msg_center);
    auto serv_mgr = std::make_unique<network::server_manager>(sess_iface);
    serv_mgr->start_serving();


    /* Block thread until interrupted by a signal, then clean up and exit */
    boost::asio::io_service io_service;
    boost::asio::signal_set signals(io_service);
    signals.add(SIGINT);
    signals.add(SIGTERM);
    signals.async_wait(signal_handler);

    io_service.run();

    serv_mgr->stop_serving();
}
示例#2
0
文件: main.c 项目: nats/nbdkit
int
main (int argc, char *argv[])
{
  int c;
  int option_index;
  int help = 0, version = 0;

  tls_init ();

  for (;;) {
    c = getopt_long (argc, argv, short_options, long_options, &option_index);
    if (c == -1)
      break;

    switch (c) {
    case 0:                     /* options which are long only */
      if (strcmp (long_options[option_index].name, "dump-config") == 0) {
        dump_config ();
        exit (EXIT_SUCCESS);
      }
      else if (strcmp (long_options[option_index].name, "run") == 0) {
        run = optarg;
        foreground = 1;
      }
      else {
        fprintf (stderr, "%s: unknown long option: %s (%d)\n",
                 program_name, long_options[option_index].name, option_index);
        exit (EXIT_FAILURE);
      }
      break;

    case 'f':
      foreground = 1;
      break;

    case 'g':
      group = optarg;
      break;

    case 'i':
      ipaddr = optarg;
      break;

    case 'n':
      newstyle = 1;
      break;

    case 'o':
      /* XXX When we add support for exportnames, we will need to
       * ensure that the user does not use -o + --export.
       */
      newstyle = 0;
      break;

    case 'P':
      pidfile = nbdkit_absolute_path (optarg);
      if (pidfile == NULL)
        exit (EXIT_FAILURE);
      break;

    case 'p':
      port = optarg;
      break;

    case 'r':
      readonly = 1;
      break;

    case 's':
      listen_stdin = 1;
      break;

    case 'U':
      if (strcmp (optarg, "-") == 0)
        unixsocket = make_random_fifo ();
      else
        unixsocket = nbdkit_absolute_path (optarg);
      if (unixsocket == NULL)
        exit (EXIT_FAILURE);
      break;

    case 'u':
      user = optarg;
      break;

    case 'v':
      verbose = 1;
      break;

    case 'V':
      version = 1;
      break;

    case HELP_OPTION:
      help = 1;
      break;

    default:
      usage ();
      exit (EXIT_FAILURE);
    }
  }

  /* No extra parameters. */
  if (optind >= argc) {
    if (help) {
      usage ();
      exit (EXIT_SUCCESS);
    }
    if (version) {
      display_version ();
      exit (EXIT_SUCCESS);
    }

    /* Otherwise this is an error. */
    fprintf (stderr,
             "%s: no plugins given on the command line.\nRead nbdkit(1) for documentation.\n",
             program_name);
    exit (EXIT_FAILURE);
  }

  /* Remaining command line arguments define the plugins and plugin
   * configuration.  If --help or --version was specified, we still
   * partially parse these in order that we can display the per-plugin
   * help/version information.  In future (when the new protocol and
   * export names are permitted) we will allow multiple plugins to be
   * given, but at the moment only one plugin is allowed.
   */
  while (optind < argc) {
    const char *filename = argv[optind];
    char *p;

    open_plugin_so (filename);

    /* Find key=value configuration parameters for this plugin. */
    ++optind;
    while (optind < argc && (p = strchr (argv[optind], '=')) != NULL) {
      if (help || version)
        continue;

      *p = '\0';
      plugin_config (argv[optind], p+1);

      ++optind;
    }

    if (help) {
      usage ();
      printf ("\n%s:\n\n", filename);
      plugin_usage ();
      exit (EXIT_SUCCESS);
    }

    if (version) {
      display_version ();
      plugin_version ();
      exit (EXIT_SUCCESS);
    }

    plugin_config_complete ();

    /* If we supported export names, then we'd continue in the loop
     * here, but at the moment only one plugin may be used per server
     * so exit if there are any more.
     */
    ++optind;
    if (optind < argc) {
      fprintf (stderr, "%s: this server only supports a single plugin\n",
               program_name);
      exit (EXIT_FAILURE);
    }
  }

  start_serving ();

  plugin_cleanup ();

  free (unixsocket);
  free (pidfile);

  if (random_fifo) {
    unlink (random_fifo);
    free (random_fifo);
  }

  if (random_fifo_dir) {
    rmdir (random_fifo_dir);
    free (random_fifo_dir);
  }

  exit (EXIT_SUCCESS);
}
示例#3
0
/* Executes the SQL CREATE queries, opens the sqlite 
 * database connection and calls swill or pico_ql_test 
 * depending on the compile flag TEST.
 */
int register_table(int argc,
		   int view_index, 
		   const char **q, 
		   const char **sqlite_names, 
		   int port_number) {
  /* This definition implicitly constraints a table name 
   * to 140 characters. It should be more than enough.
   */
  char sqlite_query[200];
  int re, i=0;
  sqlite3 *db;
/* Virtual table schema will be in-memory and will not
   persist. Views can be included in the DSL */
  re = sqlite3_open(":memory:", &db); 
  if (re) {
    printf("can't open database\n");
    sqlite3_close(db);
    return re;
  }

#ifdef PICO_QL_DEBUG
  for (i = 0; i < argc; i++) {
    printf("\nquery to be executed: %s.\n", q[i]);
  }
#endif
  sqlite3_module *mod;
  mod = (sqlite3_module *)sqlite3_malloc(sizeof(sqlite3_module));
  fill_module(mod);
  int output = sqlite3_create_module(db, "PicoQL", mod, NULL);
  if (output == 1) 
    printf("Error while registering module\n");
#ifdef PICO_QL_DEBUG
  else if (output == 0) 
    printf("Module registered successfully\n");
#endif
  // sqlite3_create_function() calls
  for (i = 0; i < argc; i++) {
    char sqlite_type[10];
    if (i < view_index)
      strcpy(sqlite_type, "table");
    else
      strcpy(sqlite_type, "view");
    sprintf(sqlite_query, "SELECT * FROM sqlite_master WHERE type='%s' AND name='%s';", sqlite_type, sqlite_names[i]);
    if (prep_exec(NULL, db, (const char *)sqlite_query, NULL) != SQLITE_ROW) {
      re = prep_exec(NULL, db, (const char *)q[i], NULL);
#ifdef PICO_QL_DEBUG
      printf("Query %s returned %i\n", q[i], re);
#endif
      if (re != 101) {
	printf("Extended error code: %i.\n", sqlite3_extended_errcode(db));
	printf("Extended error message:\n%s.\n", sqlite3_errmsg(db));
	return re;
      }
    }
  }
  start_serving();
#ifndef PICO_QL_TEST
  printf("Please visit http://localhost:%i to be served\n", port_number);
  call_swill(db, port_number);
#else
  re = call_test(db);
#endif
  sqlite3_free(mod);
  return re;
}