void shutDown() {
	cout << "System shutting down." << endl;
	websocket_server.close(currentState.client, 0, "shutdown");
	websocket_server.stop();
	gpioTerminate();
	std::exit(EXIT_SUCCESS);
	//system("shutdown -P now");
	return;
}
예제 #2
0
파일: main.cpp 프로젝트: oeo4b/Cframes
int main(int argc, char **argv) {
  /* Program start */
  /*
   * 
   *
   */
  int i;
  int port = 5000;
  char *bind = (char *)"0.0.0.0";
  bool daemon = false;

  /* Help info */
  for(i=0;i<argc;i++) {
    if(strcmp(argv[i],"-h")==0||strcmp(argv[i],"--help")==0) {
      out("Usage: cframes [options]\n");
      out("\t-p, --port PORT\tBind server socket to specified PORT\n");
      out("\t\t\tDefault: 5000\n");
      out("\t-b, --bind IP\tBind server to specified IP\n");
      out("\t\t\tDefault: 0.0.0.0\n");
      out("\t-d, --daemon\tForks server process\n");
      out("\t-h, --help\tDisplay this help and exit\n");
      out("\t-v, --version\tDisplay version information and exit\n");
      return 0;
    }
  }

  /* Version info */
  for(i=0;i<argc;i++) {
    if(strcmp(argv[i],"-v")==0||strcmp(argv[i],"--version")==0) {
      out("cframes 1.0.1\n");
      return 0;
    }
  }

  /* Program arguments */
  for(i=0;i<argc;i++) {
    if(strcmp(argv[i],"-p")==0||strcmp(argv[i],"--port")==0) {
      port = (int)argv[i+1];
    }
    if(strcmp(argv[i],"-b")==0||strcmp(argv[i],"--bind")==0) {
      bind = (char *)argv[i+1];
    }
    if(strcmp(argv[i],"-d")==0||strcmp(argv[i],"--daemon")==0) {
      daemon = true;
    }
  }

  /* Start the server */
  out("Starting cframes server...........");
  s.start(port);
  out("OK\n");
  out("Listening on http://");
  out(bind);out(":");out("5000");out("\n\n");

  /* Single-threaded forever loop to handle requests -- NOTE: eventually will have a daemon option -d */
  for(i=0;i<50;i++) { www(); }

  /* Stop the server */
  s.stop();
	
  return 0;
}