From 355ee77086655278fbf7e0fd386521218f1a1482 Mon Sep 17 00:00:00 2001 From: Mikko Rasa Date: Wed, 10 Aug 2011 22:31:26 +0300 Subject: [PATCH] Make httpget handle socket errors --- examples/httpget.cpp | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/examples/httpget.cpp b/examples/httpget.cpp index 70942b7..e0c051c 100644 --- a/examples/httpget.cpp +++ b/examples/httpget.cpp @@ -1,5 +1,6 @@ #include #include +#include #include #include #include @@ -18,6 +19,8 @@ public: HttpGet(int, char **); virtual int main(); +private: + void socket_error(const exception &); }; HttpGet::HttpGet(int argc, char **argv): @@ -37,6 +40,7 @@ HttpGet::HttpGet(int argc, char **argv): int HttpGet::main() { Http::Client client; + client.signal_socket_error.connect(sigc::mem_fun(this, &HttpGet::socket_error)); if(verbose) { @@ -45,8 +49,11 @@ int HttpGet::main() IO::print(client.get_request()->str()); client.wait_response(); const Http::Response *response = client.get_response(); - IO::print("=== Got response ===\n"); - IO::print(response->str()); + if(response) + { + IO::print("=== Got response ===\n"); + IO::print(response->str()); + } } else { @@ -56,3 +63,10 @@ int HttpGet::main() return 1; } + +void HttpGet::socket_error(const exception &e) +{ + IO::print("=== Error ===\n"); + IO::print("%s\n", Debug::demangle(typeid(e).name())); + IO::print("%s\n", e.what()); +} -- 2.45.2