[2ecbd7b] | 1 | #include "options.hfa" |
---|
| 2 | |
---|
| 3 | #define _GNU_SOURCE |
---|
| 4 | #define __USE_GNU |
---|
| 5 | extern "C" { |
---|
| 6 | #include <sys/types.h> |
---|
| 7 | #include <sys/stat.h> |
---|
| 8 | #include <fcntl.h> |
---|
| 9 | } |
---|
| 10 | |
---|
[b57db73] | 11 | #include <fstream.hfa> |
---|
[2ecbd7b] | 12 | #include <kernel.hfa> |
---|
[42f1d739] | 13 | #include <parseargs.hfa> |
---|
[2ecbd7b] | 14 | |
---|
[b57db73] | 15 | #include <stdlib.h> |
---|
[5ad381b] | 16 | #include <string.h> |
---|
| 17 | |
---|
[2ecbd7b] | 18 | Options options @= { |
---|
[481ee28] | 19 | false, // log |
---|
[5ad381b] | 20 | |
---|
[2ecbd7b] | 21 | { // file_cache |
---|
[b57db73] | 22 | 0, // path |
---|
[2ecbd7b] | 23 | 0, // open_flags; |
---|
| 24 | 42u, // hash_seed; |
---|
| 25 | 0, // size; |
---|
| 26 | false, // list; |
---|
| 27 | false // fixed_fds |
---|
| 28 | }, |
---|
| 29 | |
---|
| 30 | { // socket |
---|
| 31 | 8080, // port |
---|
[03ed863] | 32 | 10, // backlog |
---|
| 33 | 1024 // buflen |
---|
[2ecbd7b] | 34 | }, |
---|
| 35 | |
---|
| 36 | { // cluster |
---|
| 37 | 1, // nprocs; |
---|
| 38 | 1, // nworkers; |
---|
[b57db73] | 39 | {}, // params; |
---|
[2ecbd7b] | 40 | false, // procstats |
---|
| 41 | false, // viewhalts |
---|
| 42 | 0, // instance; |
---|
| 43 | } |
---|
| 44 | }; |
---|
| 45 | |
---|
[b57db73] | 46 | void parse_options( int argc, char * argv[] ) { |
---|
[2ecbd7b] | 47 | bool subthrd = false; |
---|
| 48 | bool eagrsub = false; |
---|
| 49 | bool fixedfd = false; |
---|
| 50 | bool sqkpoll = false; |
---|
| 51 | bool iokpoll = false; |
---|
| 52 | unsigned sublen = 16; |
---|
| 53 | |
---|
| 54 | static cfa_option opt[] = { |
---|
[bdbc24d] | 55 | { 'p', "port", "Port the server will listen on", options.socket.port}, |
---|
| 56 | { 'c', "cpus", "Number of processors to use", options.clopts.nprocs}, |
---|
| 57 | { 't', "threads", "Number of worker threads to use", options.clopts.nworkers}, |
---|
| 58 | {'\0', "log", "Enable logs", options.log, parse_settrue}, |
---|
| 59 | {'\0', "accept-backlog", "Maximum number of pending accepts", options.socket.backlog}, |
---|
| 60 | {'\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}, |
---|
| 61 | {'\0', "seed", "seed to use for hashing", options.file_cache.hash_seed }, |
---|
| 62 | {'\0', "cache-size", "Size of the cache to use, if set to small, will uses closes power of 2", options.file_cache.size }, |
---|
| 63 | {'\0', "list-files", "List the files in the specified path and exit", options.file_cache.list, parse_settrue }, |
---|
| 64 | { 's', "submitthread", "If set, cluster uses polling thread to submit I/O", subthrd, parse_settrue }, |
---|
| 65 | { 'e', "eagersubmit", "If set, cluster submits I/O eagerly but still aggregates submits", eagrsub, parse_settrue}, |
---|
| 66 | { 'f', "fixed-fds", "If set, files are open eagerly and pre-registered with the cluster", fixedfd, parse_settrue}, |
---|
| 67 | { 'k', "kpollsubmit", "If set, cluster uses IORING_SETUP_SQPOLL, implies -f", sqkpoll, parse_settrue }, |
---|
| 68 | { 'i', "kpollcomplete", "If set, cluster uses IORING_SETUP_IOPOLL", iokpoll, parse_settrue }, |
---|
| 69 | {'\0', "submitlength", "Max number of submitions that can be submitted together", sublen }, |
---|
[2ecbd7b] | 70 | |
---|
| 71 | }; |
---|
| 72 | int opt_cnt = sizeof(opt) / sizeof(cfa_option); |
---|
| 73 | |
---|
| 74 | char **left; |
---|
| 75 | parse_args( argc, argv, opt, opt_cnt, "[OPTIONS]... [PATH]\ncforall http server", left ); |
---|
| 76 | |
---|
[d11d6eb] | 77 | options.clopts.params.poller_submits = subthrd; |
---|
| 78 | options.clopts.params.eager_submits = eagrsub; |
---|
[2ecbd7b] | 79 | |
---|
| 80 | if( fixedfd ) { |
---|
| 81 | options.file_cache.fixed_fds = true; |
---|
| 82 | } |
---|
| 83 | |
---|
| 84 | if( sqkpoll ) { |
---|
[d11d6eb] | 85 | options.clopts.params.poll_submit = true; |
---|
[2ecbd7b] | 86 | options.file_cache.fixed_fds = true; |
---|
| 87 | } |
---|
| 88 | |
---|
| 89 | if( iokpoll ) { |
---|
[d11d6eb] | 90 | options.clopts.params.poll_complete = true; |
---|
[2ecbd7b] | 91 | options.file_cache.open_flags |= O_DIRECT; |
---|
| 92 | } |
---|
| 93 | |
---|
[d11d6eb] | 94 | options.clopts.params.num_ready = sublen; |
---|
[2ecbd7b] | 95 | |
---|
| 96 | if( left[0] == 0p ) { return "."; } |
---|
| 97 | |
---|
| 98 | const char * path = left[0]; |
---|
| 99 | left++; |
---|
| 100 | |
---|
| 101 | if( left[0] != 0p ) { |
---|
[b57db73] | 102 | serr | "Too many trailing arguments!"; |
---|
| 103 | exit(EXIT_FAILURE); |
---|
[2ecbd7b] | 104 | } |
---|
| 105 | |
---|
[b57db73] | 106 | options.file_cache.path = path; |
---|
[2ecbd7b] | 107 | } |
---|