#include "options.hfa" #define _GNU_SOURCE #define __USE_GNU extern "C" { #include #include #include } #include #include #include #include #include #include Options options @= { false, // log { // file_cache 0, // path 0, // open_flags; 42u, // hash_seed; 0, // size; false, // list; false // fixed_fds }, { // socket 8080, // port 10, // backlog 1024 // buflen }, { // cluster 1, // nprocs; 1, // nworkers; {}, // params; false, // procstats false, // viewhalts 0, // instance; } }; void parse_options( int argc, char * argv[] ) { // bool fixedfd = false; // bool sqkpoll = false; // bool iokpoll = false; unsigned nentries = 16; static cfa_option opt[] = { { 'p', "port", "Port the server will listen on", options.socket.port}, { 'c', "cpus", "Number of processors to use", options.clopts.nprocs}, { 't', "threads", "Number of worker threads to use", options.clopts.nworkers}, {'\0', "log", "Enable logs", options.log, parse_settrue}, {'\0', "accept-backlog", "Maximum number of pending accepts", options.socket.backlog}, {'\0', "request_len", "Maximum number of bytes in the http request, requests with more data will be answered with Http Code 414", options.socket.buflen}, {'\0', "seed", "seed to use for hashing", options.file_cache.hash_seed }, {'\0', "cache-size", "Size of the cache to use, if set to small, will uses closes power of 2", options.file_cache.size }, {'\0', "list-files", "List the files in the specified path and exit", options.file_cache.list, parse_settrue }, // { 'f', "fixed-fds", "If set, files are open eagerly and pre-registered with the cluster", fixedfd, parse_settrue}, // { 'k', "kpollsubmit", "If set, cluster uses IORING_SETUP_SQPOLL, implies -f", sqkpoll, parse_settrue }, // { 'i', "kpollcomplete", "If set, cluster uses IORING_SETUP_IOPOLL", iokpoll, parse_settrue }, {'e', "numentries", "Number of I/O entries", nentries }, }; int opt_cnt = sizeof(opt) / sizeof(cfa_option); char **left; parse_args( argc, argv, opt, opt_cnt, "[OPTIONS]... [PATH]\ncforall http server", left ); if( !is_pow2(nentries) ) { unsigned v = nentries; v--; v |= v >> 1; v |= v >> 2; v |= v >> 4; v |= v >> 8; v |= v >> 16; v++; serr | "Warning: num_entries not a power of 2" | '(' | nentries | ')' | "raising to " | v; nentries = v; } options.clopts.params.num_entries = nentries; // if( fixedfd ) { // options.file_cache.fixed_fds = true; // } // if( sqkpoll ) { // options.file_cache.fixed_fds = true; // } // if( iokpoll ) { // options.file_cache.open_flags |= O_DIRECT; // } if( left[0] == 0p ) { return; } const char * path = left[0]; left++; if( left[0] != 0p ) { serr | "Too many trailing arguments!" | '\'' | path | '\''; while(left[0] != 0p) { serr | " - " | left[0]; left++; } exit(EXIT_FAILURE); } options.file_cache.path = path; }