Beispiel #1
0
/**
 * \brief Entry point for the hub
 *
 * Entry point for the hub. Parses command line arguments and calls init routines of all subsystems before calling Hub_Net_mainLoop
 *
 * \param argc Size of argv array
 * \param argv Array of command line arguments
 * \return 0 on success, a non-zero value is returned upon error
 */
int main(int argc, char** argv) {
    int opt;
    char* conf_file = NULL;

    /* Parse arguments list */
    while((opt = getopt(argc, argv, ":hc:")) != -1) {
        switch(opt) {
        case 'h':
            Hub_usage(argv[0]);
            exit(EXIT_SUCCESS);
            break;
        case 'c':
            conf_file = optarg;
            break;
        case ':':
            fprintf(stderr, "Option '%c' requires an argument\n", optopt);
            Hub_usage(argv[0]);
            exit(EXIT_FAILURE);
        default:
            /* Invalid option */
            fprintf(stderr, "Invalid option '%c'\n", optopt);
            Hub_usage(argv[0]);
            exit(EXIT_FAILURE);
            break;
        }
    }

    /* Please *ignore* SIGPIPE. It will cause the program to close in the case
       of writing to a closed socket. We handle this ourselves. */
    signal(SIGPIPE, SIG_IGN);

    /* Catch common siginals and insure proper shutdown */
    signal(SIGINT, Hub_catchSignal);
    signal(SIGHUP, Hub_catchSignal);
    signal(SIGTERM, Hub_catchSignal);

    /* Use argument as configuration file */
    if(conf_file) {
        Hub_Config_loadConfig(conf_file);
    }

    /* Process configuration file */
    Hub_Config_init();
    Hub_Var_init();
    Hub_Logging_init();
    Hub_Net_init();

    MemPool_init();

    /* Ensure shutdown during normal exit */
    atexit(Hub_close);

    /* Run the main network loop */
    Hub_Net_mainLoop();

    /* Shutdown or wait for shutdown to complete */
    Hub_close();

    return 0;
}
Beispiel #2
0
MemoryPool*
MemPool_new(uint32_t arena_size) {
    MemoryPool *self = (MemoryPool*)Class_Make_Obj(MEMORYPOOL);
    return MemPool_init(self, arena_size);
}