Пример #1
0
int
main(int argc, char *argv[])
{
	char    *command;

	command = argv[1];
	/* TODO: do some error handling here */
	if (1 < argc && 0 == strncmp(command, "server",  6)) {
		switch (argc) {
			case 4:
				start_server(argv[2], (int) strtol(argv[3],NULL,10));
				break;
			case 3:
				start_server(argv[2], APP_PORT);
				break;
			default:
				start_server(APP_ROOT, APP_PORT);
		}
	}
	else if (1 < argc && 0 == strncmp(command, "shell",  5)) {
		printf("Shell functionality is not yet implemented\n");
	}
	else {
		start_server(APP_ROOT, APP_PORT);
	}
	return 0;
}
Пример #2
0
int main(int argc, char **argv)
{
	struct sockaddr_in addr4;
	struct sockaddr_in6 addr6;
	int server = -1;
	int server_v6 = -1;
	int results = -1;
	int err = 0;

	if (argc < 2) {
		fprintf(stderr, "Usage: %s prog_id\n", argv[0]);
		exit(1);
	}

	results = get_map_fd_by_prog_id(atoi(argv[1]));
	if (results < 0) {
		log_err("Can't get map");
		goto err;
	}

	memset(&addr4, 0, sizeof(addr4));
	addr4.sin_family = AF_INET;
	addr4.sin_addr.s_addr = htonl(INADDR_LOOPBACK);
	addr4.sin_port = 0;

	memset(&addr6, 0, sizeof(addr6));
	addr6.sin6_family = AF_INET6;
	addr6.sin6_addr = in6addr_loopback;
	addr6.sin6_port = 0;

	server = start_server((const struct sockaddr *)&addr4, sizeof(addr4));
	if (server == -1)
		goto err;

	server_v6 = start_server((const struct sockaddr *)&addr6,
				 sizeof(addr6));
	if (server_v6 == -1)
		goto err;

	if (run_test(server, results))
		goto err;

	if (run_test(server_v6, results))
		goto err;

	printf("ok\n");
	goto out;
err:
	err = 1;
out:
	close(server);
	close(server_v6);
	close(results);
	return err;
}
Пример #3
0
int main(int argc, char* argv [])
{
	//Program initialized
	char* device;
	device = "/dev/graphics/fb0";
	int server_socket = start_server();
	if (server_socket < 0)
	    device = "/dev/fb0";
	start_server();
	
}
Пример #4
0
void
F::start ()
{
  int retries = 0;

  std::unique_lock <std::mutex> lock (mutex);

  id = 0;

  start_server();
  BOOST_REQUIRE_MESSAGE (pid > 0, "Error launching mediaserver");

  clientThread = std::thread (std::bind (&F::start_client, this) );

  while (!initialized && retries < MAX_RETRIES) {
    lock.unlock();
    std::this_thread::sleep_for (std::chrono::milliseconds (100 * (retries + 1) ) );
    lock.lock();

    if (!initialized) {
      GST_INFO ("Waiting, %d times", retries);
      retries++;
    }
  }

  if (!initialized) {
    stop_client (lock);
    lock.unlock();

    stop_server ();
  }

  BOOST_REQUIRE_MESSAGE (initialized, "Cannot connect to the server");
}
Пример #5
0
Файл: tcp.cpp Проект: webjb/bbb
int s_tcp_t::start()
{
	if( m_is_server )
		start_server();
	s_object_t::start();
	return 0;
}
Пример #6
0
int main(int argc, char **argv) {
    int c;
    int option_index = 0;
    int count = -1;
    int server = 0;
    static struct option long_options[] = {
        {"count", required_argument, 0, 'c'},
        {"server", no_argument, 0, 's'},
        {0, 0, 0, 0 }
    };
    while (1) {
        c = getopt_long(argc, argv, "c:s", long_options, &option_index);
        if (c == -1)
            break;
        switch (c) {
        case 'c':
            count = atoi(optarg);
            break;
        case 's':
            server = 1;
            break;
        }
    }
    if (server) start_server();
    else start_client(count);
    return 0;
}
Пример #7
0
int main () {
    int i;
    for (i = 0; i < 1000; i++) {
        useridlist[i] = -1;
    }
    for (i = 0; i < 10000; i++) {
        islive[i] = time(NULL);
    }
    int sockfd;
    struct sockaddr_in addr;
    sockfd = socket(AF_INET, SOCK_DGRAM, 0);
    if (sockfd < 0) {
        fprintf(stderr, "Socket Error: %s\n", strerror(errno));
        exit(1);
    }
    bzero(&addr, sizeof(struct sockaddr_in));
    addr.sin_family = AF_INET;
    addr.sin_addr.s_addr = htonl(INADDR_ANY);
    addr.sin_port = htons(SERVER_PORT);
    if (bind(sockfd, (struct sockaddr *)&addr, sizeof(struct sockaddr_in)) < 0) {
        fprintf(stderr, "Bind Error: %s\n", strerror(errno));
        exit(1);
    }
    start_server(sockfd);
    close(sockfd);
    return 0;
}
Пример #8
0
int main(int argc, char** argv){
    
    if (argc != 3){ 
        printf("Usage: ./ppclient <port> <katalog>\n");
        exit(1);
    }
    
    int port = atoi(argv[1]); // przygotuj argumenty wywołania
    char* dir = argv[2];
    
    int sd = start_server(port, MAX_CONNECTIONS); // wystartuj serwer
    while(1){ // serwer może zostać zabity tylko odpowiednim sygnałem
        int new_sd = pp_accept(sd); // przyjmij przychodzące połączenie
        int pid = pp_fork(); // nowy fork
        
        if(pid){
            pp_close(new_sd); // jesteśmy w głównej pętli
        }
        else{
            pp_close(sd); // jesteśmy w forku
            serve(new_sd, dir); // obsłuż klienta
            
            pp_close(new_sd);
            exit(0);
        }
    }
    
    pp_close(sd);
    
    return 0;
}
Пример #9
0
int main(int argc, char* argv[])
{
	gettimeofday(&start_time,0);

	g_type_init();
	notify_init(PACKAGE_NAME);

	g_set_application_name("学生成绩管理系统");

	g_log_set_default_handler(myLog,NULL);


	//寻找并打开配置文件

	gkeyfile = g_key_file_new();

	//创建数据库访问对象
	dbclient = sqlconnect_new();
	//设置各种参数

	g_object_set(dbclient, "file", PACKAGE_NAME ".sqlite", NULL);

	//打开数据库
	g_sql_connect_real_connect(dbclient,0);

	//开启服务
	start_server(8000);
	/*主循环*/
	GMainLoop * loop = g_main_loop_new(g_main_context_default(),0);
	g_main_loop_run(loop);
	return 0;
}
Пример #10
0
void run_ssl_test(void test_fn(int port, const char *hostname)) {
  char private_key_file[] = "/tmp/web100srv_test_key.pem-XXXXXX";
  char certificate_file[] = "/tmp/web100srv_test_cert.pem-XXXXXX";
  char hostname[1024];
  char tls_port_string[6];  // Max port # has 5 digits and then a NULL
  int port;
  int tls_port;
  pid_t server_pid;
  int server_exit_code;
  int err;
  char *server_args[] = {"--tls_port", tls_port_string, "--private_key", private_key_file, "--certificate", certificate_file, NULL};
  // Set up certificates
  make_certificate_files(private_key_file, certificate_file);
  // Start the server with the right mode
  choose_random_ports(&port, &tls_port);
  sprintf(tls_port_string, "%d", tls_port);
  server_pid = start_server(port, server_args);
  ndt_gethostname(hostname, sizeof(hostname) - 1);
  // Run the passed-in test
  (*test_fn)(tls_port, hostname);
  // Free our resources
  unlink(private_key_file);
  unlink(certificate_file);
  kill(server_pid, SIGKILL);
  waitpid(server_pid, &server_exit_code, 0);
}
Пример #11
0
int main(int argc,char **argv)
{
   int s,port;

   if (argc<2){
      printf("Usage: %s port\n",argv[0]);
      exit(1);
   }
   
   port=atoi(argv[1]);
   
   /* start server up */
   s = start_server(port);
   if (s>=0){
      printf("Server started on port %i\n",port);
      process_requests(s);
   }
   if (s==-1){
      printf("Port reserved or out-of-range\n");
      exit(1);
   }
   if (s==-2){
      printf("Error creating socket\n");
      exit(1);
   }

   fprintf(stderr,"udpft server exiting!\n");
   return(1);
}
int main(int argc, char* argv[])
{
	init_environment();
	//return test_dispatch(argc,argv);
	return start_server();
	return 0;
}
Пример #13
0
END_TEST

START_TEST (test_configerror_negsize)
{
	int serverpid = start_server("conf-negsize.conf", NULL, "test_configerror_negsize.serverout");
	fail_unless(serverpid == -1, "Server should exit due to error in config file.");
}
Пример #14
0
END_TEST

START_TEST (test_error_mixed) //Added 4
{
	int serverpid = start_server("conf-mixed.conf", NULL, "test_error_mixed.serverout");
	fail_unless(serverpid == -1, "Server should exit due to error in config file.");
}
Пример #15
0
int test() {
    pthread_t thread;
    importtmp_n("tests/functional/fixtures/add_event/0/data.json", 4);
    start_server(1, &thread);
    send_msg("tests/functional/fixtures/add_event/0/input");
    pthread_join(thread, NULL);

    mu_assert_msg("tests/functional/fixtures/add_event/0/output");

    void *data;
    size_t data_length;
    sky_table *table = sky_table_create();
    table->path = bfromcstr("tmp");
    sky_table_open(table);
    sky_tablet_get_path(table->tablets[2], 10, &data, &data_length);
    mu_assert_mem(data, 
        "\x03\xe8\x03\x00\x00\x00\x00\x00\x00\x05\x00\x1f\x00\x00\x00\xff"
        "\xa6\x7a\x7a\x7a\x7a\x7a\x7a\xfe\x0a\x01\xa3\x78\x79\x7a\x02\xd1"
        "\x00\xc8\x03\xcb\x40\x59\x0c\xcc\xcc\xcc\xcc\xcd\x04\xc3\x01\x00"
        "\x00\x10\x00\x00\x00\x00\x00\x01\x00\x01\x00\x00\x20\x00\x00\x00"
        "\x00\x00\x02\x00\x01\x00\x00\x30\x00\x00\x00\x00\x00\x03\x00",
        data_length
    );
    sky_table_free(table);
    free(data);
    return 0;
}
Пример #16
0
END_TEST

START_TEST (test_error_notcomma) //Added 3
{
	int serverpid = start_server("conf-notcomma.conf", NULL, "test_error_notcomma.serverout");
	fail_unless(serverpid == -1, "Server should exit due to error in config file.");
}
Пример #17
0
END_TEST

START_TEST (test_config_threetables)
{
	int serverpid = start_server(THREETABLES_CONF, NULL, "test_config_threetables.serverout");
	fail_unless(serverpid > 0, "Server didn't run properly.");
}
Пример #18
0
END_TEST


/*
 * Test how the server processes the configuration file.
 *
 * Config file (server start) tests:
 * 	start server with no config file (fail)
 * 	start server with non existent config file (fail)
 * 	start server with no port (fail)
 * 	start server with invalid port (fail)
 * 	start server with occupied port (fail)
 * 	start server with no directory specified (fail)
 * 	start server with occupied data directory (fail)
 * 	start server with non-existent directory (pass)
 * 	start server with no tables specified (pass)
 * 	start server with 1/2/3 tables specified (pass)
 * 	start server with invalid table name (fail)
 *	start server with duplicate table names (fail)
 *      start server with duplicate port numbers (fail)
 *      start server with duplicate host addresses (fail)
 */

START_TEST (test_config_onetable)
{
	int serverpid = start_server(ONETABLE_CONF, NULL, "test_config_onetable.serverout");
	fail_unless(serverpid > 0, "Server didn't run properly.");
}
Пример #19
0
int main(int argc, char *argv[]) 
{
  MLOG_init( MLOG_LEVEL_INFO, MLOG_ACTION_CONSOLE, 0);
  parse_cmd_line( argc, argv );
  start_server();
  return 0;
}
Пример #20
0
void setup(void)
{
	TEST_PAUSE;		/* if -p option specified */

	/* initialize sockaddr's */
	sin1.sin_family = AF_INET;
	sin1.sin_port = htons((getpid() % 32768) + 11000);
	sin1.sin_addr.s_addr = INADDR_ANY;
	pid = start_server(&sin1);

	sin2.sin_family = AF_INET;
	/* this port must be unused! */
	sin2.sin_port = htons((getpid() % 32768) + 10000);
	sin2.sin_addr.s_addr = INADDR_ANY;

	sin3.sin_family = AF_INET;
	sin3.sin_port = 0;
	/* assumes no route to this network! */
	sin3.sin_addr.s_addr = htonl(0x0AFFFEFD);

	sin4.sin_family = 47;	/* bogus address family */
	sin4.sin_port = 0;
	sin4.sin_addr.s_addr = htonl(0x0AFFFEFD);

}
Пример #21
0
END_TEST

START_TEST (test_error_alotnegsize) //Added 6
{
	int serverpid = start_server("conf-alotnegsize.conf", NULL, "test_error_doublenegsize.serverout");
	fail_unless(serverpid == -1, "Server should exit due to error in config file.");
}
int main(int argc, char *argv[]) {

printf(".:: FILE TRANSFER SERVER ::.\n");
if(!processArguments(argc, argv)) return -1;

start_server(port,baseDir);
}
Пример #23
0
// main loop
int main( int argc, char **argv )
{
	printf("Hello world\n");

	Management manager = new_manager();

	// add actions to the manager
	action_add_to_manager( manager );
	
	// add rooms to manager
	room_add_to_manager( manager );

	Server server = new_server();
	if( start_server( server, 5555 ) < 0 ){
		return 1;
	}

	environment_loop( server, manager );
	
	
	/* ---------------------------------------
	 * Clean up 
	 */
	
	close_server( server );
	destroy_server( server );


	destroy_manager( manager );

	return 0;
}
Пример #24
0
int		main(int argc, char **argv)
{
  int		fd;
  int		port;

  signal(SIGINT, &_handle_sigint);
  port = 5555;
  if (argc == 2)
    port = atoi(argv[1]);
  printf("Server listening on port %d\nPress [ENTER] to continue...\n", port);
  getchar();
  fd = start_server(port);
  if (fd == -1)
    return (EXIT_FAILURE);
  /* assert(libanio_init(&server, fd, 1000, NB_WORKERS, &on_accept, &on_read, &on_eof, NULL, ANIO_MODE_STREAM) == 0); */
  assert(libanio_init(&server, fd, 1000, NB_WORKERS, &on_accept, &on_read, &on_eof, NULL, ANIO_MODE_LINE, "\n") == 0);
  assert(libanio_start_monitor(&server) == 0);

  /* start libanio loop here */
  sleep(500);

  libanio_stop_monitor(&server);
  libanio_free(&server);
  close(fd);
  return (EXIT_SUCCESS);
}
Пример #25
0
static void start_poll_test(void) {
  int i, r;

#ifdef _WIN32
  {
    struct WSAData wsa_data;
    int r = WSAStartup(MAKEWORD(2, 2), &wsa_data);
    ASSERT(r == 0);
  }
#endif

  start_server();

  for (i = 0; i < NUM_CLIENTS; i++)
    start_client();

  r = uv_run(uv_default_loop(), UV_RUN_DEFAULT);
  ASSERT(r == 0);

  /* Assert that at most five percent of the writable wakeups was spurious. */
  ASSERT(spurious_writable_wakeups == 0 ||
         (valid_writable_wakeups + spurious_writable_wakeups) /
         spurious_writable_wakeups > 20);

  ASSERT(closed_connections == NUM_CLIENTS * 2);
  ASSERT(disconnects == NUM_CLIENTS * 2);

  MAKE_VALGRIND_HAPPY();
}
Пример #26
0
int main(int argc, char* argv [])
{
#ifdef DEBUG
	// optional logging to file
	if (argc >= 2) {
		logFile = fopen(argv[1], "a+");
	}
	else
		logFile = stderr;
#endif
	Log ("Program initialized");

	char* device;
	device = "/dev/graphics/fb0";

	int server_socket = start_server();
	if (server_socket < 0)
		Log ("Error while starting server");
	if (setup_signals() < 0)
		Log ("Error while setting up signals");

//	Log ("Going into background -- have nice day.");
//	if (setsid () < 0)	Log("Error while going into background");
	if (do_work (server_socket, device) < 0)
		Log ("Error in main loop");
}
Пример #27
0
static void init(void)
{
	const char *opt;
	char *host, *d;
	int port;

	opt = conf_get_opt("cli", "tcp");
	if (!opt)
		return;

	host = strdup(opt);
	d = strstr(host, ":");
	if (!d)
		goto err_fmt;

	*d = 0;
	port = atoi(d + 1);
	if (port <= 0)
		goto err_fmt;

	load_config();

	temp_buf = malloc(RECV_BUF_SIZE);

	start_server(host, port);

	triton_event_register_handler(EV_CONFIG_RELOAD, (triton_event_func)load_config);

	return;
err_fmt:
	log_emerg("cli: tcp: invalid format\n");
	free(host);
}
Пример #28
0
void TaskManager::run_thread()
{
	SLOG_INFO("TaskManager[ID=%d] is running...", get_thread_id());

	start_server();

	SLOG_INFO("TaskManager end...");
}
Пример #29
0
Файл: recv01.c Проект: Nudiv/ltp
void setup(void)
{
	TEST_PAUSE;

	pid = start_server(&sin1);

	(void)signal(SIGPIPE, SIG_IGN);
}
Пример #30
0
END_TEST


START_TEST (test_config_twotable) //Added 9
{
	int serverpid = start_server("twotable.conf", NULL, "test_config_onetable.serverout");
	fail_unless(serverpid > 0, "Server didn't run properly.");
}