int main(int args, char** argsv) { configuration config; config.http_listen_address = "0.0.0.0"; if (args > 1) { config.http_listen_port = atoi(argsv[1]); } else { config.http_listen_port = 8000; } if (args > 2) { config.thread_count = atoi(argsv[2]); } else { config.thread_count = 0; } hw_init_with_config(&config); hw_http_add_route("/plaintext", get_plaintext, NULL); hw_http_open(); return 0; }
int main(int args, char** argsv) { char route[] = "/"; configuration config; config.http_listen_address = "0.0.0.0"; if (args > 1) { config.http_listen_port = atoi(argsv[1]); } else { config.http_listen_port = 8000; } if (args > 2) { config.thread_count = atoi(argsv[2]); } else { config.thread_count = 0; } /* hw_init_from_config("hello_world.conf"); */ hw_init_with_config(&config); hw_http_add_route(route, get_root, NULL); hw_http_open(); return 0; }
int main(int args, char** argsv) { char root_route[] = "/"; char ping_route[] = "/ping"; configuration config; config.http_listen_address = "0.0.0.0"; struct opt_config *conf; conf = opt_config_init(); opt_flag_int(conf, &config.http_listen_port, "port", 8000, "Port to listen on."); opt_flag_int(conf, &config.thread_count, "threads", 0, "Number of threads to use."); opt_flag_string(conf, &config.parser, "parser", "http_parser", "HTTP parser to use"); opt_flag_int(conf, &config.max_request_size, "max_request_size", 1048576, "Maximum request size. Defaults to 1MB."); opt_flag_bool(conf, &config.tcp_nodelay, "tcp_nodelay", "If present, enables tcp_nodelay (i.e. disables Nagle's algorithm)."); opt_flag_int(conf, &config.listen_backlog, "listen_backlog", 0, "Maximum size of the backlog when accepting connection. Defaults to SOMAXCONN."); args = opt_config_parse(conf, args, argsv); hw_init_with_config(&config); hw_http_add_route(ping_route, get_ping, NULL); hw_http_add_route(root_route, get_root, NULL); hw_http_open(); opt_config_free(conf); return 0; }
int hw_init_from_config(char* configuration_filename) { configuration* config = load_configuration(configuration_filename); if (config == NULL) { return 1; } return hw_init_with_config(config); }
int main() { char route[] = "/"; configuration config; config.http_listen_address = "0.0.0.0"; config.http_listen_port = 8000; /* hw_init_from_config("hello_world.conf"); */ hw_init_with_config(&config); hw_http_add_route(route, get_root); hw_http_open(); return 0; }