Update of /cvsroot/boost/boost/boost/asio/ip
In directory sc8-pr-cvs3.sourceforge.net:/tmp/cvs-serv17073/boost/asio/ip
Modified Files:
address.hpp address_v4.hpp address_v6.hpp basic_endpoint.hpp
basic_resolver.hpp host_name.hpp resolver_service.hpp
Log Message:
Change error handling to match TR2 proposal.
Index: address.hpp
===================================================================
RCS file: /cvsroot/boost/boost/boost/asio/ip/address.hpp,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -d -r1.1 -r1.2
--- address.hpp 14 Jun 2006 22:26:31 -0000 1.1
+++ address.hpp 8 Nov 2006 05:32:12 -0000 1.2
@@ -24,9 +24,9 @@
#include <boost/asio/detail/pop_options.hpp>
#include <boost/asio/error.hpp>
-#include <boost/asio/error_handler.hpp>
#include <boost/asio/ip/address_v4.hpp>
#include <boost/asio/ip/address_v6.hpp>
+#include <boost/asio/detail/throw_error.hpp>
namespace boost {
namespace asio {
@@ -120,9 +120,9 @@
{
if (type_ != ipv4)
{
- boost::asio::error error(
+ boost::system::system_error e(
boost::asio::error::address_family_not_supported);
- boost::throw_exception(error);
+ boost::throw_exception(e);
}
return ipv4_address_;
}
@@ -132,9 +132,9 @@
{
if (type_ != ipv6)
{
- boost::asio::error error(
+ boost::system::system_error e(
boost::asio::error::address_family_not_supported);
- boost::throw_exception(error);
+ boost::throw_exception(e);
}
return ipv6_address_;
}
@@ -148,53 +148,47 @@
}
/// Get the address as a string in dotted decimal format.
- template <typename Error_Handler>
- std::string to_string(Error_Handler error_handler) const
+ std::string to_string(boost::system::error_code& ec) const
{
if (type_ == ipv6)
- return ipv6_address_.to_string(error_handler);
- return ipv4_address_.to_string(error_handler);
+ return ipv6_address_.to_string(ec);
+ return ipv4_address_.to_string(ec);
}
/// Create an address from an IPv4 address string in dotted decimal form,
/// or from an IPv6 address in hexadecimal notation.
static address from_string(const char* str)
{
- return from_string(str, boost::asio::throw_error());
+ boost::system::error_code ec;
+ address addr = from_string(str, ec);
+ boost::asio::detail::throw_error(ec);
+ return addr;
}
/// Create an address from an IPv4 address string in dotted decimal form,
/// or from an IPv6 address in hexadecimal notation.
- template <typename Error_Handler>
- static address from_string(const char* str, Error_Handler error_handler)
+ static address from_string(const char* str, boost::system::error_code& ec)
{
- boost::asio::error error;
boost::asio::ip::address_v6 ipv6_address =
- boost::asio::ip::address_v6::from_string(str,
- boost::asio::assign_error(error));
- if (!error)
+ boost::asio::ip::address_v6::from_string(str, ec);
+ if (!ec)
{
address tmp;
tmp.type_ = ipv6;
tmp.ipv6_address_ = ipv6_address;
- error_handler(error);
return tmp;
}
- error = boost::asio::error();
boost::asio::ip::address_v4 ipv4_address =
- boost::asio::ip::address_v4::from_string(str,
- boost::asio::assign_error(error));
- if (!error)
+ boost::asio::ip::address_v4::from_string(str, ec);
+ if (!ec)
{
address tmp;
tmp.type_ = ipv4;
tmp.ipv4_address_ = ipv4_address;
- error_handler(error);
return tmp;
}
- error_handler(error);
return address();
}
@@ -202,16 +196,15 @@
/// or from an IPv6 address in hexadecimal notation.
static address from_string(const std::string& str)
{
- return from_string(str.c_str(), boost::asio::throw_error());
+ return from_string(str.c_str());
}
/// Create an address from an IPv4 address string in dotted decimal form,
/// or from an IPv6 address in hexadecimal notation.
- template <typename Error_Handler>
static address from_string(const std::string& str,
- Error_Handler error_handler)
+ boost::system::error_code& ec)
{
- return from_string(str.c_str(), error_handler);
+ return from_string(str.c_str(), ec);
}
/// Compare two addresses for equality.
Index: address_v4.hpp
===================================================================
RCS file: /cvsroot/boost/boost/boost/asio/ip/address_v4.hpp,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -d -r1.2 -r1.3
--- address_v4.hpp 4 Nov 2006 07:14:09 -0000 1.2
+++ address_v4.hpp 8 Nov 2006 05:32:12 -0000 1.3
@@ -24,9 +24,9 @@
#include <boost/asio/detail/pop_options.hpp>
#include <boost/asio/error.hpp>
-#include <boost/asio/error_handler.hpp>
#include <boost/asio/detail/socket_ops.hpp>
#include <boost/asio/detail/socket_types.hpp>
+#include <boost/asio/detail/throw_error.hpp>
namespace boost {
namespace asio {
@@ -97,63 +97,54 @@
/// Get the address as a string in dotted decimal format.
std::string to_string() const
{
- return to_string(boost::asio::throw_error());
+ boost::system::error_code ec;
+ std::string addr = to_string(ec);
+ boost::asio::detail::throw_error(ec);
+ return addr;
}
/// Get the address as a string in dotted decimal format.
- template <typename Error_Handler>
- std::string to_string(Error_Handler error_handler) const
+ std::string to_string(boost::system::error_code& ec) const
{
char addr_str[boost::asio::detail::max_addr_v4_str_len];
const char* addr =
boost::asio::detail::socket_ops::inet_ntop(AF_INET, &addr_, addr_str,
- boost::asio::detail::max_addr_v4_str_len);
+ boost::asio::detail::max_addr_v4_str_len, 0, ec);
if (addr == 0)
- {
- boost::asio::error e(boost::asio::detail::socket_ops::get_error());
- error_handler(e);
return std::string();
- }
- boost::asio::error e;
- error_handler(e);
return addr;
}
/// Create an address from an IP address string in dotted decimal form.
static address_v4 from_string(const char* str)
{
- return from_string(str, boost::asio::throw_error());
+ boost::system::error_code ec;
+ address_v4 addr = from_string(str, ec);
+ boost::asio::detail::throw_error(ec);
+ return addr;
}
/// Create an address from an IP address string in dotted decimal form.
- template <typename Error_Handler>
- static address_v4 from_string(const char* str, Error_Handler error_handler)
+ static address_v4 from_string(const char* str, boost::system::error_code& ec)
{
address_v4 tmp;
if (boost::asio::detail::socket_ops::inet_pton(
- AF_INET, str, &tmp.addr_) <= 0)
- {
- boost::asio::error e(boost::asio::detail::socket_ops::get_error());
- error_handler(e);
+ AF_INET, str, &tmp.addr_, 0, ec) <= 0)
return address_v4();
- }
- boost::asio::error e;
- error_handler(e);
return tmp;
}
/// Create an address from an IP address string in dotted decimal form.
static address_v4 from_string(const std::string& str)
{
- return from_string(str.c_str(), boost::asio::throw_error());
+ return from_string(str.c_str());
}
/// Create an address from an IP address string in dotted decimal form.
- template <typename Error_Handler>
static address_v4 from_string(const std::string& str,
- Error_Handler error_handler)
+ boost::system::error_code& ec)
{
- return from_string(str.c_str(), error_handler);
+ return from_string(str.c_str(), ec);
}
/// Determine whether the address is a class A address.
@@ -275,9 +266,9 @@
std::basic_ostream<Elem, Traits>& operator<<(
std::basic_ostream<Elem, Traits>& os, const address_v4& addr)
{
- boost::asio::error e;
- std::string s = addr.to_string(boost::asio::assign_error(e));
- if (e)
+ boost::system::error_code ec;
+ std::string s = addr.to_string(ec);
+ if (ec)
os.setstate(std::ios_base::failbit);
else
for (std::string::iterator i = s.begin(); i != s.end(); ++i)
Index: address_v6.hpp
===================================================================
RCS file: /cvsroot/boost/boost/boost/asio/ip/address_v6.hpp,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -d -r1.2 -r1.3
--- address_v6.hpp 4 Nov 2006 07:14:09 -0000 1.2
+++ address_v6.hpp 8 Nov 2006 05:32:12 -0000 1.3
@@ -27,9 +27,9 @@
#include <boost/asio/detail/pop_options.hpp>
#include <boost/asio/error.hpp>
-#include <boost/asio/error_handler.hpp>
#include <boost/asio/detail/socket_ops.hpp>
#include <boost/asio/detail/socket_types.hpp>
+#include <boost/asio/detail/throw_error.hpp>
#include <boost/asio/ip/address_v4.hpp>
namespace boost {
@@ -106,63 +106,54 @@
/// Get the address as a string.
std::string to_string() const
{
- return to_string(boost::asio::throw_error());
+ boost::system::error_code ec;
+ std::string addr = to_string(ec);
+ boost::asio::detail::throw_error(ec);
+ return addr;
}
/// Get the address as a string.
- template <typename Error_Handler>
- std::string to_string(Error_Handler error_handler) const
+ std::string to_string(boost::system::error_code& ec) const
{
char addr_str[boost::asio::detail::max_addr_v6_str_len];
const char* addr =
boost::asio::detail::socket_ops::inet_ntop(AF_INET6, &addr_, addr_str,
- boost::asio::detail::max_addr_v6_str_len, scope_id_);
+ boost::asio::detail::max_addr_v6_str_len, scope_id_, ec);
if (addr == 0)
- {
- boost::asio::error e(boost::asio::detail::socket_ops::get_error());
- error_handler(e);
return std::string();
- }
- boost::asio::error e;
- error_handler(e);
return addr;
}
/// Create an address from an IP address string.
static address_v6 from_string(const char* str)
{
- return from_string(str, boost::asio::throw_error());
+ boost::system::error_code ec;
+ address_v6 addr = from_string(str, ec);
+ boost::asio::detail::throw_error(ec);
+ return addr;
}
/// Create an address from an IP address string.
- template <typename Error_Handler>
- static address_v6 from_string(const char* str, Error_Handler error_handler)
+ static address_v6 from_string(const char* str, boost::system::error_code& ec)
{
address_v6 tmp;
if (boost::asio::detail::socket_ops::inet_pton(
- AF_INET6, str, &tmp.addr_, &tmp.scope_id_) <= 0)
- {
- boost::asio::error e(boost::asio::detail::socket_ops::get_error());
- error_handler(e);
+ AF_INET6, str, &tmp.addr_, &tmp.scope_id_, ec) <= 0)
return address_v6();
- }
- boost::asio::error e;
- error_handler(e);
return tmp;
}
/// Create an address from an IP address string.
static address_v6 from_string(const std::string& str)
{
- return from_string(str.c_str(), boost::asio::throw_error());
+ return from_string(str.c_str());
}
/// Create an address from an IP address string.
- template <typename Error_Handler>
static address_v6 from_string(const std::string& str,
- Error_Handler error_handler)
+ boost::system::error_code& ec)
{
- return from_string(str.c_str(), error_handler);
+ return from_string(str.c_str(), ec);
}
/// Converts an IPv4-mapped or IPv4-compatible address to an IPv4 address.
@@ -387,9 +378,9 @@
std::basic_ostream<Elem, Traits>& operator<<(
std::basic_ostream<Elem, Traits>& os, const address_v6& addr)
{
- boost::asio::error e;
- std::string s = addr.to_string(boost::asio::assign_error(e));
- if (e)
+ boost::system::error_code ec;
+ std::string s = addr.to_string(ec);
+ if (ec)
os.setstate(std::ios_base::failbit);
else
for (std::string::iterator i = s.begin(); i != s.end(); ++i)
Index: basic_endpoint.hpp
===================================================================
RCS file: /cvsroot/boost/boost/boost/asio/ip/basic_endpoint.hpp,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -d -r1.2 -r1.3
--- basic_endpoint.hpp 4 Nov 2006 07:14:09 -0000 1.2
+++ basic_endpoint.hpp 8 Nov 2006 05:32:12 -0000 1.3
@@ -204,7 +204,7 @@
{
if (size > size_type(sizeof(data_)))
{
- boost::asio::error e(boost::asio::error::invalid_argument);
+ boost::system::system_error e(boost::asio::error::invalid_argument);
boost::throw_exception(e);
}
}
Index: basic_resolver.hpp
===================================================================
RCS file: /cvsroot/boost/boost/boost/asio/ip/basic_resolver.hpp,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -d -r1.1 -r1.2
--- basic_resolver.hpp 4 Nov 2006 07:14:09 -0000 1.1
+++ basic_resolver.hpp 8 Nov 2006 05:32:12 -0000 1.2
@@ -19,8 +19,8 @@
#include <boost/asio/basic_io_object.hpp>
#include <boost/asio/error.hpp>
-#include <boost/asio/error_handler.hpp>
#include <boost/asio/ip/resolver_service.hpp>
+#include <boost/asio/detail/throw_error.hpp>
namespace boost {
namespace asio {
@@ -34,9 +34,6 @@
* @par Thread Safety:
* @e Distinct @e objects: [EMAIL PROTECTED]
* @e Shared @e objects: Unsafe.
- *
- * @par Concepts:
- * Async_Object, Error_Source.
*/
template <typename Protocol, typename Service = resolver_service<Protocol> >
class basic_resolver
@@ -55,9 +52,6 @@
/// The iterator type.
typedef typename Protocol::resolver_iterator iterator;
- /// The type used for reporting errors.
- typedef boost::asio::error error_type;
-
/// Constructor.
/**
* This constructor creates a basic_resolver.
@@ -90,7 +84,7 @@
* @returns A forward-only iterator that can be used to traverse the list
* of endpoint entries.
*
- * @throws boost::asio::error Thrown on failure.
+ * @throws boost::system::system_error Thrown on failure.
*
* @note A default constructed iterator represents the end of the list.
*
@@ -99,7 +93,10 @@
*/
iterator resolve(const query& q)
{
- return this->service.resolve(this->implementation, q, throw_error());
+ boost::system::error_code ec;
+ iterator i = this->service.resolve(this->implementation, q, ec);
+ boost::asio::detail::throw_error(ec);
+ return i;
}
/// Resolve a query to a list of entries.
@@ -112,22 +109,16 @@
* of endpoint entries. Returns a default constructed iterator if an error
* occurs.
*
- * @param error_handler A handler to be called when the operation completes,
- * to indicate whether or not an error has occurred. Copies will be made of
- * the handler as required. The function signature of the handler must be:
- * @code void error_handler(
- * const boost::asio::error& error // Result of operation.
- * ); @endcode
+ * @param ec Set to indicate what error occurred, if any.
*
* @note A default constructed iterator represents the end of the list.
*
* @note A successful call to this function is guaranteed to return at least
* one entry.
*/
- template <typename Error_Handler>
- iterator resolve(const query& q, Error_Handler error_handler)
+ iterator resolve(const query& q, boost::system::error_code& ec)
{
- return this->service.resolve(this->implementation, q, error_handler);
+ return this->service.resolve(this->implementation, q, ec);
}
/// Asynchronously resolve a query to a list of entries.
@@ -141,9 +132,10 @@
* completes. Copies will be made of the handler as required. The function
* signature of the handler must be:
* @code void handler(
- * const boost::asio::error& error, // Result of operation.
- * resolver::iterator iterator // Forward-only iterator that can be used to
- * // traverse the list of endpoint entries.
+ * const boost::system::error_code& error, // Result of operation.
+ * resolver::iterator iterator // Forward-only iterator that
can
+ * // be used to traverse the list
+ * // of endpoint entries.
* ); @endcode
* Regardless of whether the asynchronous operation completes immediately or
* not, the handler will not be invoked from within this function. Invocation
@@ -172,7 +164,7 @@
* @returns A forward-only iterator that can be used to traverse the list
* of endpoint entries.
*
- * @throws boost::asio::error Thrown on failure.
+ * @throws boost::system::system_error Thrown on failure.
*
* @note A default constructed iterator represents the end of the list.
*
@@ -181,7 +173,10 @@
*/
iterator resolve(const endpoint_type& e)
{
- return this->service.resolve(this->implementation, e, throw_error());
+ boost::system::error_code ec;
+ iterator i = this->service.resolve(this->implementation, e, ec);
+ boost::asio::detail::throw_error(ec);
+ return i;
}
/// Resolve an endpoint to a list of entries.
@@ -196,22 +191,16 @@
* of endpoint entries. Returns a default constructed iterator if an error
* occurs.
*
- * @param error_handler A handler to be called when the operation completes,
- * to indicate whether or not an error has occurred. Copies will be made of
- * the handler as required. The function signature of the handler must be:
- * @code void error_handler(
- * const boost::asio::error& error // Result of operation.
- * ); @endcode
+ * @param ec Set to indicate what error occurred, if any.
*
* @note A default constructed iterator represents the end of the list.
*
* @note A successful call to this function is guaranteed to return at least
* one entry.
*/
- template <typename Error_Handler>
- iterator resolve(const endpoint_type& e, Error_Handler error_handler)
+ iterator resolve(const endpoint_type& e, boost::system::error_code& ec)
{
- return this->service.resolve(this->implementation, e, error_handler);
+ return this->service.resolve(this->implementation, e, ec);
}
/// Asynchronously resolve an endpoint to a list of entries.
@@ -226,9 +215,10 @@
* completes. Copies will be made of the handler as required. The function
* signature of the handler must be:
* @code void handler(
- * const boost::asio::error& error, // Result of operation.
- * resolver::iterator iterator // Forward-only iterator that can be used to
- * // traverse the list of endpoint entries.
+ * const boost::system::error_code& error, // Result of operation.
+ * resolver::iterator iterator // Forward-only iterator that
can
+ * // be used to traverse the list
+ * // of endpoint entries.
* ); @endcode
* Regardless of whether the asynchronous operation completes immediately or
* not, the handler will not be invoked from within this function. Invocation
Index: host_name.hpp
===================================================================
RCS file: /cvsroot/boost/boost/boost/asio/ip/host_name.hpp,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -d -r1.1 -r1.2
--- host_name.hpp 14 Jun 2006 22:26:31 -0000 1.1
+++ host_name.hpp 8 Nov 2006 05:32:12 -0000 1.2
@@ -21,8 +21,9 @@
#include <string>
#include <boost/asio/detail/pop_options.hpp>
-#include <boost/asio/error_handler.hpp>
+#include <boost/asio/error.hpp>
#include <boost/asio/detail/socket_ops.hpp>
+#include <boost/asio/detail/throw_error.hpp>
namespace boost {
namespace asio {
@@ -32,24 +33,25 @@
std::string host_name();
/// Get the current host name.
-template <typename Error_Handler>
-std::string host_name(Error_Handler error_handler);
+std::string host_name(boost::system::error_code& ec);
inline std::string host_name()
{
- return host_name(boost::asio::throw_error());
+ char name[1024];
+ boost::system::error_code ec;
+ if (boost::asio::detail::socket_ops::gethostname(name, sizeof(name), ec) !=
0)
+ {
+ boost::asio::detail::throw_error(ec);
+ return std::string();
+ }
+ return std::string(name);
}
-template <typename Error_Handler>
-std::string host_name(Error_Handler error_handler)
+inline std::string host_name(boost::system::error_code& ec)
{
char name[1024];
- if (boost::asio::detail::socket_ops::gethostname(name, sizeof(name)) != 0)
- {
- boost::asio::error error(boost::asio::detail::socket_ops::get_error());
- error_handler(error);
+ if (boost::asio::detail::socket_ops::gethostname(name, sizeof(name), ec) !=
0)
return std::string();
- }
return std::string(name);
}
Index: resolver_service.hpp
===================================================================
RCS file: /cvsroot/boost/boost/boost/asio/ip/resolver_service.hpp,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -d -r1.1 -r1.2
--- resolver_service.hpp 4 Nov 2006 07:14:09 -0000 1.1
+++ resolver_service.hpp 8 Nov 2006 05:32:12 -0000 1.2
@@ -17,6 +17,7 @@
#include <boost/asio/detail/push_options.hpp>
+#include <boost/asio/error.hpp>
#include <boost/asio/io_service.hpp>
#include <boost/asio/detail/resolver_service.hpp>
@@ -85,11 +86,10 @@
}
/// Resolve a query to a list of entries.
- template <typename Error_Handler>
iterator_type resolve(implementation_type& impl, const query_type& query,
- Error_Handler error_handler)
+ boost::system::error_code& ec)
{
- return service_impl_.resolve(impl, query, error_handler);
+ return service_impl_.resolve(impl, query, ec);
}
/// Asynchronously resolve a query to a list of entries.
@@ -101,11 +101,10 @@
}
/// Resolve an endpoint to a list of entries.
- template <typename Error_Handler>
iterator_type resolve(implementation_type& impl,
- const endpoint_type& endpoint, Error_Handler error_handler)
+ const endpoint_type& endpoint, boost::system::error_code& ec)
{
- return service_impl_.resolve(impl, endpoint, error_handler);
+ return service_impl_.resolve(impl, endpoint, ec);
}
/// Asynchronously resolve an endpoint to a list of entries.
-------------------------------------------------------------------------
Using Tomcat but need to do more? Need to support web services, security?
Get stuff done quickly with pre-integrated technology to make your job easier
Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
_______________________________________________
Boost-cvs mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/boost-cvs