# # patch "ChangeLog" # from [d975e96baab064b053f56997fd12287654bd8770] # to [dd2068ccabfda7a0bb20ea835e7adad671f574de] # # patch "netsync.cc" # from [23798e72a6683bd620594f459f08ea19de8acdbe] # to [5f217cbacb87f31da40471d97a3a68565211e152] # # patch "netxx/address.cxx" # from [5727f6190658dc429fefc13790e29083b2e08c3d] # to [d10a78dd01637cc991e2bc3ab35c4570443d042d] # # patch "netxx/datagram.cxx" # from [9387724054a92667ff9de312b8ab53be0b75e4bf] # to [ffef08e25afb734472d40f80ffc604cabad71de0] # # patch "netxx/resolve_getaddrinfo.cxx" # from [b26dd1cb3cd3235735f135cf722ac9a0301c915c] # to [5ac3791fe2751ae78f121e9aad0027d301c3d1a0] # # patch "netxx/resolve_gethostbyname.cxx" # from [f5e84d139c1c80dc7a8817153f63b78a7ee1f2fa] # to [2978e83cbb2327e1e3cf0eac745172b038be551d] # # patch "netxx/serverbase.cxx" # from [cc32f641e2b296cd94b2f4d7d646aa0489e1abfa] # to [c08af53ff373665f71dcd30bba28f41354daf388] # # patch "netxx/streambase.cxx" # from [b3ff067cb7f892ee33dc47edbd0f261a5cd25b59] # to [33f2fe8674145f789fdb7a4645a820e08288e07c] # # patch "netxx/types.h" # from [08a0a67568607000b66b18c71d2d129fe1cf77d5] # to [6415da38ce23a946cf1d24ef5aa84cbe077e45cf] # --- ChangeLog +++ ChangeLog @@ -1,3 +1,18 @@ +2005-04-29 Grahame Bowland + + * netxx/types.h: Add new NetworkException type network + issue not caused by calling program + * netsync.cc: Catch Netxx::NetworkException and display + as informative_error. + * netxx/address.cxx: NetworkException for unparsable URIs. + * netxx/datagram.cxx: NetworkException for connection failure. + * netxx/resolve_getaddrinfo.cxx, resolve_gethostbyname.cxx: + NetworkException when DNS resolution fails. + * netxx/serverbase.cxx: NetworkException if unable to bind + to server port. + * netxx/streambase.cxx: NetworkException if unable to + connect. + 2005-04-28 Matt Johnston * tests/t_merge_6.at: narrow the testcase down considerably. --- netsync.cc +++ netsync.cc @@ -3453,6 +3453,11 @@ guard.commit(); } } + catch (Netxx::NetworkException & e) + { + end_platform_netsync(); + throw informative_failure((F("network exception: %s") % e.what()).str()); + } catch (Netxx::Exception & e) { end_platform_netsync(); --- netxx/address.cxx +++ netxx/address.cxx @@ -134,7 +134,7 @@ if (!parse_uri(uri, protocol, name_, tmp_port, path_)) { std::string error("can't parse URI: "); error += uri; - throw Exception(error); + throw NetworkException(error); } if (!protocol.empty() && std::strcmp(protocol.c_str(), const_local_service) == 0) { --- netxx/datagram.cxx +++ netxx/datagram.cxx @@ -291,7 +291,7 @@ if (connect(socket.get_socketfd(), sa, sa_size) != 0) { std::string error("connect(2) failed: "); error += strerror(Netxx::get_last_error()); - throw Netxx::Exception(error); + throw Netxx::NetworkException(error); } } //#################################################################### @@ -315,7 +315,7 @@ if (bind(socket.get_socketfd(), reinterpret_cast(saun), saun_size) != 0) { std::string error("bind(2) error: "); error += strerror(Netxx::get_last_error()); - throw Netxx::Exception(error); + throw Netxx::NetworkException(error); } /* @@ -338,7 +338,7 @@ if ( (fd = mkstemp(buffer)) < 0) { std::string error("can't create temporary file: "); error += strerror(Netxx::get_last_error()); - throw Netxx::Exception(error); + throw Netxx::NetworkException(error); } /* --- netxx/resolve_getaddrinfo.cxx +++ netxx/resolve_getaddrinfo.cxx @@ -83,7 +83,7 @@ if (getaddrinfo(hostname, 0, &flags, &info) != 0) { std::string error("name resolution failure for "); error += hostname; - throw Exception(error); + throw NetworkException(error); } // auto clean up @@ -128,7 +128,7 @@ if (getaddrinfo(0, service, &flags, &info) != 0) { std::string error("service name resolution failed for: "); error += service; - throw Exception(error); + throw NetworkException(error); } auto_addrinfo ai(info); --- netxx/resolve_gethostbyname.cxx +++ netxx/resolve_gethostbyname.cxx @@ -80,7 +80,7 @@ hostent *he; // WARNING not MT safe if ( (he = gethostbyname(hostname)) == 0) { std::string error("name resolution failure for "); error += hostname; - throw Exception(error); + throw NetworkException(error); } for (char **ii = he->h_addr_list; *ii != 0; ++ii) { --- netxx/serverbase.cxx +++ netxx/serverbase.cxx @@ -133,7 +133,7 @@ if (bind(socketfd, sa, sa_size) != 0) { std::string error("bind(2) error: "); error += strerror(Netxx::get_last_error()); - throw Exception(error); + throw NetworkException(error); } sockets_map_[socketfd] = &(sockets_[current_socket]); --- netxx/streambase.cxx +++ netxx/streambase.cxx @@ -87,7 +87,7 @@ if (!connected) { std::string error("failed to connect: "); error += message; - throw Exception(error); + throw NetworkException(error); } } //#################################################################### --- netxx/types.h +++ netxx/types.h @@ -56,6 +56,18 @@ typedef signed int socket_type; /** + * The Netxx::NetworkException class is used by the Netxx library to signal + * an error condition associated with a network issue that would not result + * from a bug in the calling program. It is derived from std::runtime_error + * which is derived from std::exception. This makes it suitable to only catch + * std::exception objects if you wish. + **/ + struct NetworkException : public std::runtime_error { + NetworkException (const std::string &what_arg) : + std::runtime_error(what_arg) { } + }; // end Netxx::NetworkException + + /** * The Netxx::Exception class is used by the Netxx library to signal * some error condition. It is derived from std::runtime_error which is * dervied from std::exception. This makes it suitable to only catch