From ae0bac563ee2aeb730bcaf7299d75353267280d8 Mon Sep 17 00:00:00 2001 From: Tatsuhiro Tsujikawa Date: Sun, 26 Feb 2012 18:13:56 +0900 Subject: [PATCH] Added -3, --spdy3 option to spdycat. --- examples/spdycat.cc | 15 +++++++++++++-- examples/spdylay_ssl.cc | 17 +++++++++++------ 2 files changed, 24 insertions(+), 8 deletions(-) diff --git a/examples/spdycat.cc b/examples/spdycat.cc index 1d3d902c..500a3ddb 100644 --- a/examples/spdycat.cc +++ b/examples/spdycat.cc @@ -61,7 +61,9 @@ struct Config { bool null_out; bool remote_name; bool verbose; - Config():null_out(false), remote_name(false), verbose(false) {} + bool spdy3_only; + Config():null_out(false), remote_name(false), verbose(false), + spdy3_only(false) {} }; struct Request { @@ -145,6 +147,9 @@ int communicate(const std::string& host, uint16_t port, return -1; } std::string next_proto; + if(config.spdy3_only) { + next_proto = "spdy/3"; + } setup_ssl_ctx(ssl_ctx, &next_proto); SSL *ssl = SSL_new(ssl_ctx); if(!ssl) { @@ -275,6 +280,8 @@ void print_help(std::ostream& out) << " The filename is dereived from URI. If URI\n" << " ends with '/', 'index.html' is used as a\n" << " filename. Not implemented yet.\n" + << " -3, --spdy3 Only use SPDY/3.\n" + << "\n" << std::endl; } @@ -285,11 +292,12 @@ int main(int argc, char **argv) {"verbose", no_argument, 0, 'v' }, {"null-out", no_argument, 0, 'n' }, {"remote-name", no_argument, 0, 'O' }, + {"spdy3", no_argument, 0, '3' }, {"help", no_argument, 0, 'h' }, {0, 0, 0, 0 } }; int option_index = 0; - int c = getopt_long(argc, argv, "Onhv", long_options, &option_index); + int c = getopt_long(argc, argv, "Onhv3", long_options, &option_index); if(c == -1) { break; } @@ -306,6 +314,9 @@ int main(int argc, char **argv) case 'v': config.verbose = true; break; + case '3': + config.spdy3_only = true; + break; case '?': exit(EXIT_FAILURE); default: diff --git a/examples/spdylay_ssl.cc b/examples/spdylay_ssl.cc index 7b764de2..339b51c3 100644 --- a/examples/spdylay_ssl.cc +++ b/examples/spdylay_ssl.cc @@ -470,13 +470,18 @@ int select_next_proto_cb(SSL* ssl, std::cout << std::endl; } } - if(spdylay_select_next_protocol(out, outlen, in, inlen) != 1) { - std::cerr << "Server did not advertise spdy/2 or spdy/3 protocol." - << std::endl; - abort(); + std::string& next_proto = *(std::string*)arg; + if(next_proto.empty()) { + if(spdylay_select_next_protocol(out, outlen, in, inlen) != 1) { + std::cerr << "Server did not advertise spdy/2 or spdy/3 protocol." + << std::endl; + abort(); + } else { + next_proto.assign(&(*out)[0], &(*out)[*outlen]); + } } else { - std::string& next_proto = *(std::string*)arg; - next_proto.assign(&(*out)[0], &(*out)[*outlen]); + *out = (unsigned char*)(next_proto.c_str()); + *outlen = next_proto.size(); } if(ssl_debug) { std::cout << " NPN selected the protocol: "