From ac7b87c7a5167fe581a6a85de1edd007b4c8c59e Mon Sep 17 00:00:00 2001 From: Jim Morrison Date: Fri, 2 Mar 2012 10:59:07 -0800 Subject: [PATCH] Check Return non-zero for failed spdy requests. --- examples/spdycat.cc | 25 ++++++++++++++++--------- tests/end_to_end.py | 7 +++++++ 2 files changed, 23 insertions(+), 9 deletions(-) diff --git a/examples/spdycat.cc b/examples/spdycat.cc index 500a3ddb..ea7e13d0 100644 --- a/examples/spdycat.cc +++ b/examples/spdycat.cc @@ -161,10 +161,13 @@ int communicate(const std::string& host, uint16_t port, } make_non_block(fd); set_tcp_nodelay(fd); - Spdylay sc(fd, ssl, - spdylay_npn_get_version(reinterpret_cast - (next_proto.c_str()), next_proto.size()), - callbacks); + int spdy_version = spdylay_npn_get_version( + reinterpret_cast(next_proto.c_str()), + next_proto.size()); + if (spdy_version <= 0) { + return -1; + } + Spdylay sc(fd, ssl, spdy_version, callbacks); nfds_t npollfds = 1; pollfd pollfds[1]; @@ -243,12 +246,15 @@ int run(char **uris, int n) std::vector reqvec; std::string prev_host; uint16_t prev_port = 0; + int failures = 0; for(int i = 0; i < n; ++i) { uri::UriStruct us; if(uri::parse(us, uris[i])) { if(prev_host != us.host || prev_port != us.port) { if(!reqvec.empty()) { - communicate(prev_host, prev_port, reqvec, &callbacks); + if (communicate(prev_host, prev_port, reqvec, &callbacks) != 0) { + ++failures; + } reqvec.clear(); } prev_host = us.host; @@ -258,9 +264,11 @@ int run(char **uris, int n) } } if(!reqvec.empty()) { - communicate(prev_host, prev_port, reqvec, &callbacks); + if (communicate(prev_host, prev_port, reqvec, &callbacks) != 0) { + ++failures; + } } - return 0; + return failures; } void print_usage(std::ostream& out) @@ -330,8 +338,7 @@ int main(int argc, char **argv) SSL_load_error_strings(); SSL_library_init(); reset_timer(); - run(argv+optind, argc-optind); - return 0; + return run(argv+optind, argc-optind); } } // namespace spdylay diff --git a/tests/end_to_end.py b/tests/end_to_end.py index b1996797..1fdcd1cd 100755 --- a/tests/end_to_end.py +++ b/tests/end_to_end.py @@ -76,6 +76,13 @@ class EndToEndSpdy2Tests(EndToEndSpdyTests): self.assertEquals(0, self.call('/', ['-v', '-3'])) self.assertIn('NPN selected the protocol: spdy/3', self.stdout) + def testFailedRequests(self): + self.assertEquals( + 2, self.call('/', ['https://localhost:25/', 'http://localhost:79'])) + + def testOneFailedRequest(self): + self.assertEquals(1, subprocess.call([self.client, 'http://localhost:2/'])) + class EndToEndSpdy3Tests(EndToEndSpdyTests): @classmethod