h2load: Read URIs from stdin if -i- is used

This commit is contained in:
Tatsuhiro Tsujikawa 2014-10-22 22:51:00 +09:00
parent af5bedd45f
commit a9ecdca08a
1 changed files with 30 additions and 16 deletions

View File

@ -651,6 +651,19 @@ std::vector<std::string> parse_uris(Iterator first, Iterator last)
} }
} // namespace } // namespace
namespace {
std::vector<std::string> read_uri_from_file(std::istream& infile)
{
std::vector<std::string> uris;
std::string line_uri;
while(std::getline(infile, line_uri)) {
uris.push_back(line_uri);
}
return uris;
}
} // namespace
namespace { namespace {
void print_version(std::ostream& out) void print_version(std::ostream& out)
{ {
@ -690,12 +703,13 @@ Options:
-i, --input-file=<FILE> -i, --input-file=<FILE>
Path of a file with multiple URIs are seperated Path of a file with multiple URIs are seperated
by EOLs. This option will disable URIs getting by EOLs. This option will disable URIs getting
from command-line. URIs are used in this order from command-line. If '-' is given as <FILE>,
for each client. All URIs are used, then first URIs will be read from stdin. URIs are used in
URI is used and then 2nd URI, and so on. The this order for each client. All URIs are used,
scheme, host and port in the subsequent URIs, if then first URI is used and then 2nd URI, and so
present, are ignored. Those in the first URI are on. The scheme, host and port in the subsequent
used solely. URIs, if present, are ignored. Those in the
first URI are used solely.
-m, --max-concurrent-streams=(auto|<N>) -m, --max-concurrent-streams=(auto|<N>)
Max concurrent streams to issue per session. If Max concurrent streams to issue per session. If
"auto" is given, the number of given URIs is "auto" is given, the number of given URIs is
@ -932,17 +946,17 @@ int main(int argc, char **argv)
std::copy(&argv[optind], &argv[argc], std::back_inserter(uris)); std::copy(&argv[optind], &argv[argc], std::back_inserter(uris));
reqlines = parse_uris(std::begin(uris), std::end(uris)); reqlines = parse_uris(std::begin(uris), std::end(uris));
} else { } else {
std::ifstream uri_file(config.ifile); std::vector<std::string> uris;
if(config.ifile == "-") {
if(!uri_file) { uris = read_uri_from_file(std::cin);
} else {
std::ifstream infile(config.ifile);
if(!infile) {
std::cerr << "cannot read input file: " << config.ifile << std::endl; std::cerr << "cannot read input file: " << config.ifile << std::endl;
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
std::vector<std::string> uris; uris = read_uri_from_file(infile);
std::string line_uri;
while(std::getline(uri_file, line_uri)) {
uris.push_back(line_uri);
} }
reqlines = parse_uris(std::begin(uris), std::end(uris)); reqlines = parse_uris(std::begin(uris), std::end(uris));