From: Mikko Rasa Date: Wed, 10 Aug 2011 19:31:26 +0000 (+0300) Subject: Make httpget handle socket errors X-Git-Url: http://git.tdb.fi/?a=commitdiff_plain;h=355ee77086655278fbf7e0fd386521218f1a1482;p=libs%2Fnet.git Make httpget handle socket errors --- 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()); +}