////////////////////////////////////////////////////////////////////////// Parse the configurations for the TXN limiter.
| 111 | // Parse the configurations for the TXN limiter. |
| 112 | // |
| 113 | bool |
| 114 | TxnRateLimiter::initialize(int argc, const char *argv[]) |
| 115 | { |
| 116 | static const struct option longopt[] = { |
| 117 | {const_cast<char *>("limit"), required_argument, nullptr, 'l' }, |
| 118 | {const_cast<char *>("queue"), required_argument, nullptr, 'q' }, |
| 119 | {const_cast<char *>("error"), required_argument, nullptr, 'e' }, |
| 120 | {const_cast<char *>("retry"), required_argument, nullptr, 'r' }, |
| 121 | {const_cast<char *>("header"), required_argument, nullptr, 'h' }, |
| 122 | {const_cast<char *>("maxage"), required_argument, nullptr, 'm' }, |
| 123 | {const_cast<char *>("prefix"), required_argument, nullptr, 'p' }, |
| 124 | {const_cast<char *>("tag"), required_argument, nullptr, 't' }, |
| 125 | {const_cast<char *>("conntrack"), no_argument, nullptr, 'c' }, |
| 126 | {const_cast<char *>("rate"), required_argument, nullptr, 'R' }, |
| 127 | // EOF |
| 128 | {nullptr, no_argument, nullptr, '\0'}, |
| 129 | }; |
| 130 | optind = 1; |
| 131 | std::string prefix = RATE_LIMITER_METRIC_PREFIX; |
| 132 | std::string tag = ""; |
| 133 | |
| 134 | while (true) { |
| 135 | int opt = getopt_long(argc, const_cast<char *const *>(argv), "", longopt, nullptr); |
| 136 | |
| 137 | switch (opt) { |
| 138 | case 'l': |
| 139 | this->_limit = strtol(optarg, nullptr, 10); |
| 140 | break; |
| 141 | case 'q': |
| 142 | this->_max_queue = strtol(optarg, nullptr, 10); |
| 143 | break; |
| 144 | case 'e': |
| 145 | this->_error = strtol(optarg, nullptr, 10); |
| 146 | break; |
| 147 | case 'r': |
| 148 | this->_retry = strtol(optarg, nullptr, 10); |
| 149 | break; |
| 150 | case 'm': |
| 151 | this->_max_age = std::chrono::milliseconds(strtol(optarg, nullptr, 10)); |
| 152 | break; |
| 153 | case 'h': |
| 154 | this->_header = optarg; |
| 155 | break; |
| 156 | case 'p': |
| 157 | prefix = optarg; |
| 158 | break; |
| 159 | case 't': |
| 160 | tag = optarg; |
| 161 | break; |
| 162 | case 'c': |
| 163 | this->_conntrack = true; |
| 164 | break; |
| 165 | case 'R': |
| 166 | this->_rate = strtol(optarg, nullptr, 10); |
| 167 | break; |
| 168 | } |
| 169 | if (opt == -1) { |
| 170 | break; |
no test coverage detected