예제 #1
0
int main(int c, char**a) {
#if DEBUG_TO_UDP
  strcpy(mdg_debug_log_target_ip, "77.66.11.94");
  mdg_debug_log_target_port = 9999;
  mdg_debug_log_target = 0;
#endif

  mdg_chat_output_fprintf("Welcome to TDG-lib chat demo.\n");
  setup_callbacks();
  chatclient_parse_cmd_args(c, a);
  if (c == 3) {
    // Use TCP based IO instead of stdIO
    io_port = atoi(a[2]);
  }

  if (c == 5) {
    // Server config from cmd-line args.
    configure_server(a[2], atoi(a[3]), a[4]);
  }
  // mdg_set_configuration(&mdg_configuration_test);
  // mdg_set_configuration(&mdg_configuration_tmdg82);
  // mdg_set_configuration(&mdg_configuration_localhost);
  // mdg_set_configuration(&mdg_configuration_prod01);
  // mdg_set_configuration(&mdg_configuration_danfoss_prod);
  // mdg_set_configuration(&mdg_configuration_danfoss_qa);

  load_demo_email();
  if (client_email[0] == 0) {
      mdg_chat_output_fprintf("Please provide e-mail using \"/email [email protected]\"\n");
  }
  mdg_chat_output_fprintf("Type \"/h\" for list of commands. All commands start with \"/\"\n");
  mdg_demo_start();
  return 0;
}
예제 #2
0
int main(int argc,char *argv[])
{	
	strategy_t server_operation;
	int sfd;
	server_operation = (strategy_t)configure_server(argc,argv);		
	sfd              = initialize_server();
	server_operation(sfd);  				//start server
	if(close(sfd)==-1)					//close server
		print_log(WARNING,"\nError while closing");

	return 0;
}
예제 #3
0
// ========== The Main Function ============
int main (int argc, char *argv[])
{
	configure_server(config);

	signalHandling();

#if DEBUG
	printf("Checking if transmission directory exists...\n");
#endif // if DEBUG
	dirChkCreate(BISON_TRANSFER_DIR.c_str(), "transfer");

	printf("Server Starting Up...\n");

	// Insert PID file management stuff here

	// keep on preparing the connection until it is prepared.
	while (1) {
		if (!prepare_connection())
			break;
		for (int i = 0; i > ERROR_WAIT; i++)
			usleep(1000);
	}

#if DEBUG
	printf("Server ready, waiting for connection.\n");
#endif // if DEBUG

	// Loop to keep accepting connections
	while (1) {
		const char* ret = update_filetable(BISON_TRANSFER_DIR, filetable);
		if (ret) {
			std::cerr << "Error on filetable update: " << ret << std::endl;
		}
		handle_connection();
		usleep(5000);					// wait a bit so that we won't -
		// overload the system
	}

	return 0;
}
void graph::httpservops::do_configure_server ()
{
  G_OPS_BAIL_IF_ERROR (configure_server (),
                       "Unable to set OMX_TizoniaIndexParamHttpServer");
}
예제 #5
0
파일: main.c 프로젝트: drcrane/pfwd
int main(int argc, char *argv[]) {
	SOCKET svrSock;
	SOCKET cliSock;
	SOCKET svcSock;
	struct service_thread_args * svc_thr;

#ifdef __COMPILE_FOR_WIN32
	DWORD tid;
	HANDLE threadHandle;
#endif
#ifdef __COMPILE_FOR_LINUX
	pthread_t tid;
	pthread_attr_t * thattr;
#endif

	char * listenIp;
	unsigned short listenPort;
	char * destIp;
	unsigned short destPort;

	if (argc != 5) {
		fprintf(stderr, "Usage:\n   %s <listenIp> <listenPort> <destIp> <destPort>\n   %s 0.0.0.0 5000 192.168.1.104 2030\n", "pfwd", "pfwd");
		return 1;
	}
	
	listenIp = argv[1];
	listenPort = atoi(argv[2]);
	destIp = argv[3];
	destPort = atoi(argv[4]);

	app_initialise();

	svrSock = configure_server(listenIp, listenPort);

#ifdef __COMPILE_FOR_LINUX
	signal(SIGPIPE, SIG_IGN);
#endif

	while (1 == 1) {
		svcSock = accept(svrSock, NULL, NULL);
		fprintf(stdout, "CLIENT CONNECTED\n"); fflush(stdout);
		
		cliSock = connect_client(destIp, destPort);
		fprintf(stdout, "SOCKETS %d %d\n", (int)cliSock, (int)svcSock); fflush(stdout);
		
		svc_thr = (struct service_thread_args *)malloc(sizeof(struct service_thread_args));
		svc_thr->svcSock = svcSock;
		svc_thr->cliSock = cliSock;

#ifdef __COMPILE_FOR_WIN32
		threadHandle = CreateThread((LPSECURITY_ATTRIBUTES)NULL, (SIZE_T)65536, (LPTHREAD_START_ROUTINE)service_thread, (LPVOID)svc_thr, 0, (LPDWORD)&tid);
		CloseHandle(threadHandle);
#endif
#ifdef __COMPILE_FOR_LINUX
		thattr = NULL;
		pthread_create(&tid, thattr, service_thread, (void *)svc_thr);
#endif
	}
	
	app_shutdown();
	return 0;
}
int main(int argc, char *argv[])
{

    pid_t pid, sid; /* Process- and Session-ID */
    struct server_conf_s server_conf;

    FILE *pidf; /* The PID file */

    if (argc < 2) {
        printf("Please specify a configuration file.\n");
        exit(EXIT_FAILURE);
    }

    server_conf = configure_server(argv[1]);

    /* initialize networking
    bind to ip 0.0.0.0:PORT */
    IP ip;
    ip.i = 0;
    DHT *dht = new_DHT(new_net_crypto(new_networking(ip, server_conf.port)));
    /* Read the config file */
    printf("PID file: %s\n", server_conf.pid_file);
    printf("Key file: %s\n", server_conf.keys_file);

    if (server_conf.err == -1)
        printf("Config file not read.\n");

    if (server_conf.err == -2)
        printf("No valid servers in list.\n");

    /* Open PID file for writing - if an error happens,
    it will be caught down the line */
    pidf = fopen(server_conf.pid_file, "w");

    /* Manage the keys */
    /* for now, just ignore any errors after this call. */
    int tmperr = errno;
    manage_keys(dht, server_conf.keys_file);
    errno = tmperr;

    /* Public key */
    int i;
    printf("\nPublic Key: ");

    for (i = 0; i < 32; ++i) {
        uint8_t ln, hn;
        ln = 0x0F & dht->c->self_public_key[i];
        hn = 0xF0 & dht->c->self_public_key[i];
        hn = hn >> 4;
        printf("%X%X", hn, ln);
    }

    printf("\n");

    /* Bootstrap the DHT
    This one throws odd errors, too. Ignore. I assume they come
    from somewhere in the core. */
    tmperr = errno;
    connect_to_servers(dht, server_conf.info);
    errno = tmperr;

    if (!DHT_isconnected(dht)) {
        puts("Could not establish DHT connection. Check server settings.\n");
        exit(EXIT_FAILURE);
    } else {
        printf("Connected to DHT successfully.\n");
    }

    /* If there's been an error, exit before forking off */
    if (errno != 0) {
        perror("Error");
        printf("Error(s) occured during start-up. Exiting.\n");
        exit(EXIT_FAILURE);
    }

    /* Things that make the daemon work come past here.
    There should be nothing here but the daemon code and
    the main loop. */

    /* Fork off from the parent process */
    pid = fork();

    if (pid < 0) {
        printf("Forking failed.\n");
        exit(EXIT_FAILURE);
    }

    /* If we got a good PID, then
    we can exit the parent process. */
    if (pid > 0) {
        printf("Forked successfully: %d\n", pid);

        /* Write the PID file */
        fprintf(pidf, "%d\n", pid);
        fclose(pidf);

        /* Exit parent */
        exit(EXIT_SUCCESS);
    }

    /* Change the file mode mask */
    umask(0);

    /* Create a new SID for the child process */
    sid = setsid();

    if (sid < 0) {
        printf("SID creation failure.\n");
        exit(EXIT_FAILURE);
    }

    /* Change the current working directory */
    if ((chdir("/")) < 0) {
        exit(EXIT_FAILURE);
    }

    /* Go quiet */
    close(STDOUT_FILENO);
    close(STDIN_FILENO);
    close(STDERR_FILENO);

    while (1) {
        do_DHT(dht);

        networking_poll(dht->c->lossless_udp->net);
        usleep(10000);
    }

    shutdown_networking();
    exit(EXIT_SUCCESS);
}
예제 #7
0
// ======= Configuration Reloading ========
void configuration_reload(int sig)
{
	configure_server(config);
}