Ejemplo n.º 1
0
int main(int argc, char **argv)
{
	int nthreads = 1;
	char *cachedir = "locals.txt";
	char option_char;

	while ((option_char = getopt_long(argc, argv, "t:c:h", gLongOptions, NULL)) != -1)
	{
		switch (option_char)
		{
			case 't': // thread-count
				nthreads = atoi(optarg);
				break;
			case 'c': //cache directory
				cachedir = optarg;
				break;
			case 'h': // help
				Usage();
				exit(0);
				break;
			default:
				Usage();
				exit(1);
		}
	}

	if (signal(SIGINT, _sig_handler) == SIG_ERR)
	{
		fprintf(stderr,"Can't catch SIGINT...exiting.\n");
		exit(EXIT_FAILURE);
	}

	if (signal(SIGTERM, _sig_handler) == SIG_ERR)
	{
		fprintf(stderr,"Can't catch SIGTERM...exiting.\n");
		exit(EXIT_FAILURE);
	}

	// Initialize cache
	simplecache_init(cachedir);

    // Initializing thread constructs
	InitializeThreadConstructs();
	InitializeThreadPool(nthreads);

	// Initializing synchronization queues
	InitializeSynchronizationQueues();

    HandleIncomingRequests();

    CleanupThreads();

	return 0;
}
Ejemplo n.º 2
0
/* Main ========================================================= */
int main(int argc, char **argv) {
    int option_char = 0;
    unsigned short port = 8888;
    char *content = "content.txt";
    gfserver_t *gfs;
    int threads = 2;

    // Parse and set command line arguments
    while ((option_char = getopt(argc, argv, "p:t:c:h")) != -1) {
        switch (option_char) {
        case 'p': // listen-port
            port = atoi(optarg);
            break;
        case 't': // number of threads
            threads = atoi(optarg);
            break;
        case 'c': // file-path
            content = optarg;
            break;
        case 'h': // help
            fprintf(stdout, "%s", USAGE);
            exit(0);
            break;
        default:
            fprintf(stderr, "%s", USAGE);
            exit(1);
        }
    }

    content_init(content);

    InitializeThreadConstructs();
    InitializeThreadPool(threads);

    /*Initializing server*/
    gfs = gfserver_create();

    /*Setting options*/
    gfserver_set_port(gfs, port);
    gfserver_set_maxpending(gfs, 100);
    gfserver_set_handler(gfs, handler_get);
    gfserver_set_handlerarg(gfs, NULL);

    /*Loops forever*/
    gfserver_serve(gfs);
    ThreadCleanup();
}
Ejemplo n.º 3
0
int main(int argc, char * argv[])
#endif
{
    bool threaded = false;
    ETERM *cmd_tuple;

#ifdef __WIN32__
    _setmode( _fileno( stdout ), _O_BINARY );
    _setmode( _fileno( stdin  ), _O_BINARY );
#endif

    erl_init(NULL, 0);
    log_flag = false;

    if (argc >= 2) {
        if (
#ifdef __WIN32__
            wcscmp(argv[1], L"true") == 0
#else
            strcmp(argv[1], "true") == 0
#endif
        ) log_flag = true;
    }

	if (argc >= 3) {
		int ListenPortNo = 
#ifdef __WIN32__
            _wtoi(argv[2]);
#else
            atoi(argv[2]);
#endif
		char * ret = connect_tcp(ListenPortNo);
		if(ret != NULL) {
			return -1;
		} else
			REMOTE_LOG("Logging over TCP, Voila!\n");
	}

    init_marshall();

    REMOTE_LOG("Port: OCI Process started...\n");

    threaded = InitializeThreadPool();
    if(threaded)
        REMOTE_LOG("Port: Thread pool created...\n");

    REMOTE_LOG("Port: Initialized Oracle OCI\n");

    while(!exit_loop && (cmd_tuple = (ETERM *)read_cmd()) != NULL) {
        if(threaded && ProcessCommand(cmd_tuple)) {
            //REMOTE_LOG("Port: Command sumitted to thread-pool for processing...");
        }
    }

    REMOTE_LOG("Port: Process oci terminating...\n");
	close_tcp();

    REMOTE_LOG("Port: Thread pool destroyed...\n");
    CleanupThreadPool();

    return 0;
}