Update of /cvsroot/boost/boost/boost/asio/ssl/detail
In directory
sc8-pr-cvs3.sourceforge.net:/tmp/cvs-serv17073/boost/asio/ssl/detail
Modified Files:
openssl_context_service.hpp openssl_operation.hpp
openssl_stream_service.hpp
Log Message:
Change error handling to match TR2 proposal.
Index: openssl_context_service.hpp
===================================================================
RCS file:
/cvsroot/boost/boost/boost/asio/ssl/detail/openssl_context_service.hpp,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -d -r1.3 -r1.4
--- openssl_context_service.hpp 4 Nov 2006 07:14:09 -0000 1.3
+++ openssl_context_service.hpp 8 Nov 2006 05:32:12 -0000 1.4
@@ -131,64 +131,58 @@
}
// Set options on the context.
- template <typename Error_Handler>
- void set_options(impl_type& impl, context_base::options o,
- Error_Handler error_handler)
+ boost::system::error_code set_options(impl_type& impl,
+ context_base::options o, boost::system::error_code& ec)
{
::SSL_CTX_set_options(impl, o);
- boost::asio::error e;
- error_handler(e);
+ ec = boost::system::error_code();
+ return ec;
}
// Set peer verification mode.
- template <typename Error_Handler>
- void set_verify_mode(impl_type& impl, context_base::verify_mode v,
- Error_Handler error_handler)
+ boost::system::error_code set_verify_mode(impl_type& impl,
+ context_base::verify_mode v, boost::system::error_code& ec)
{
::SSL_CTX_set_verify(impl, v, 0);
- boost::asio::error e;
- error_handler(e);
+ ec = boost::system::error_code();
+ return ec;
}
// Load a certification authority file for performing verification.
- template <typename Error_Handler>
- void load_verify_file(impl_type& impl, const std::string& filename,
- Error_Handler error_handler)
+ boost::system::error_code load_verify_file(impl_type& impl,
+ const std::string& filename, boost::system::error_code& ec)
{
if (::SSL_CTX_load_verify_locations(impl, filename.c_str(), 0) != 1)
{
- boost::asio::error e(boost::asio::error::invalid_argument);
- error_handler(e);
- return;
+ ec = boost::asio::error::invalid_argument;
+ return ec;
}
- boost::asio::error e;
- error_handler(e);
+ ec = boost::system::error_code();
+ return ec;
}
// Add a directory containing certification authority files to be used for
// performing verification.
- template <typename Error_Handler>
- void add_verify_path(impl_type& impl, const std::string& path,
- Error_Handler error_handler)
+ boost::system::error_code add_verify_path(impl_type& impl,
+ const std::string& path, boost::system::error_code& ec)
{
if (::SSL_CTX_load_verify_locations(impl, 0, path.c_str()) != 1)
{
- boost::asio::error e(boost::asio::error::invalid_argument);
- error_handler(e);
- return;
+ ec = boost::asio::error::invalid_argument;
+ return ec;
}
- boost::asio::error e;
- error_handler(e);
+ ec = boost::system::error_code();
+ return ec;
}
// Use a certificate from a file.
- template <typename Error_Handler>
- void use_certificate_file(impl_type& impl, const std::string& filename,
- context_base::file_format format, Error_Handler error_handler)
+ boost::system::error_code use_certificate_file(impl_type& impl,
+ const std::string& filename, context_base::file_format format,
+ boost::system::error_code& ec)
{
int file_type;
switch (format)
@@ -201,43 +195,39 @@
break;
default:
{
- boost::asio::error e(boost::asio::error::invalid_argument);
- error_handler(e);
- return;
+ ec = boost::asio::error::invalid_argument;
+ return ec;
}
}
if (::SSL_CTX_use_certificate_file(impl, filename.c_str(), file_type) != 1)
{
- boost::asio::error e(boost::asio::error::invalid_argument);
- error_handler(e);
- return;
+ ec = boost::asio::error::invalid_argument;
+ return ec;
}
- boost::asio::error e;
- error_handler(e);
+ ec = boost::system::error_code();
+ return ec;
}
// Use a certificate chain from a file.
- template <typename Error_Handler>
- void use_certificate_chain_file(impl_type& impl, const std::string& filename,
- Error_Handler error_handler)
+ boost::system::error_code use_certificate_chain_file(impl_type& impl,
+ const std::string& filename, boost::system::error_code& ec)
{
if (::SSL_CTX_use_certificate_chain_file(impl, filename.c_str()) != 1)
{
- boost::asio::error e(boost::asio::error::invalid_argument);
- error_handler(e);
- return;
+ ec = boost::asio::error::invalid_argument;
+ return ec;
}
- boost::asio::error e;
- error_handler(e);
+ ec = boost::system::error_code();
+ return ec;
}
// Use a private key from a file.
- template <typename Error_Handler>
- void use_private_key_file(impl_type& impl, const std::string& filename,
- context_base::file_format format, Error_Handler error_handler)
+ boost::system::error_code use_private_key_file(impl_type& impl,
+ const std::string& filename, context_base::file_format format,
+ boost::system::error_code& ec)
{
int file_type;
switch (format)
@@ -250,27 +240,25 @@
break;
default:
{
- boost::asio::error e(boost::asio::error::invalid_argument);
- error_handler(e);
- return;
+ ec = boost::asio::error::invalid_argument;
+ return ec;
}
}
if (::SSL_CTX_use_PrivateKey_file(impl, filename.c_str(), file_type) != 1)
{
- boost::asio::error e(boost::asio::error::invalid_argument);
- error_handler(e);
- return;
+ ec = boost::asio::error::invalid_argument;
+ return ec;
}
- boost::asio::error e;
- error_handler(e);
+ ec = boost::system::error_code();
+ return ec;
}
// Use an RSA private key from a file.
- template <typename Error_Handler>
- void use_rsa_private_key_file(impl_type& impl, const std::string& filename,
- context_base::file_format format, Error_Handler error_handler)
+ boost::system::error_code use_rsa_private_key_file(impl_type& impl,
+ const std::string& filename, context_base::file_format format,
+ boost::system::error_code& ec)
{
int file_type;
switch (format)
@@ -283,44 +271,39 @@
break;
default:
{
- boost::asio::error e(boost::asio::error::invalid_argument);
- error_handler(e);
- return;
+ ec = boost::asio::error::invalid_argument;
+ return ec;
}
}
if (::SSL_CTX_use_RSAPrivateKey_file(
impl, filename.c_str(), file_type) != 1)
{
- boost::asio::error e(boost::asio::error::invalid_argument);
- error_handler(e);
- return;
+ ec = boost::asio::error::invalid_argument;
+ return ec;
}
- boost::asio::error e;
- error_handler(e);
+ ec = boost::system::error_code();
+ return ec;
}
// Use the specified file to obtain the temporary Diffie-Hellman parameters.
- template <typename Error_Handler>
- void use_tmp_dh_file(impl_type& impl, const std::string& filename,
- Error_Handler error_handler)
+ boost::system::error_code use_tmp_dh_file(impl_type& impl,
+ const std::string& filename, boost::system::error_code& ec)
{
::BIO* bio = ::BIO_new_file(filename.c_str(), "r");
if (!bio)
{
- boost::asio::error e(boost::asio::error::invalid_argument);
- error_handler(e);
- return;
+ ec = boost::asio::error::invalid_argument;
+ return ec;
}
::DH* dh = ::PEM_read_bio_DHparams(bio, 0, 0, 0);
if (!dh)
{
::BIO_free(bio);
- boost::asio::error e(boost::asio::error::invalid_argument);
- error_handler(e);
- return;
+ ec = boost::asio::error::invalid_argument;
+ return ec;
}
::BIO_free(bio);
@@ -328,13 +311,12 @@
if (result != 1)
{
::DH_free(dh);
- boost::asio::error e(boost::asio::error::invalid_argument);
- error_handler(e);
- return;
+ ec = boost::asio::error::invalid_argument;
+ return ec;
}
- boost::asio::error e;
- error_handler(e);
+ ec = boost::system::error_code();
+ return ec;
}
static int password_callback(char* buf, int size, int purpose, void* data)
@@ -356,9 +338,9 @@
}
// Set the password callback.
- template <typename Password_Callback, typename Error_Handler>
- void set_password_callback(impl_type& impl, Password_Callback callback,
- Error_Handler error_handler)
+ template <typename Password_Callback>
+ boost::system::error_code set_password_callback(impl_type& impl,
+ Password_Callback callback, boost::system::error_code& ec)
{
// Allocate callback function object if not already present.
if (impl->default_passwd_callback_userdata)
@@ -379,8 +361,8 @@
SSL_CTX_set_default_passwd_cb(impl,
&openssl_context_service::password_callback);
- boost::asio::error e;
- error_handler(e);
+ ec = boost::asio::error::success;
+ return ec;
}
private:
Index: openssl_operation.hpp
===================================================================
RCS file: /cvsroot/boost/boost/boost/asio/ssl/detail/openssl_operation.hpp,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -d -r1.3 -r1.4
--- openssl_operation.hpp 4 Nov 2006 07:14:09 -0000 1.3
+++ openssl_operation.hpp 8 Nov 2006 05:32:12 -0000 1.4
@@ -34,7 +34,8 @@
namespace detail {
typedef boost::function<int (::SSL*)> ssl_primitive_func;
-typedef boost::function<void (const error&, int)> user_handler_func;
+typedef boost::function<void (const boost::system::error_code&, int)>
+ user_handler_func;
// Network send_/recv buffer implementation
//
@@ -156,15 +157,15 @@
if (is_shut_down_sent && is_shut_down_received && is_operation_done)
// SSL connection is shut down cleanly
- return handler_(boost::asio::error(), 1);
+ return handler_(boost::asio::error::success, 1);
if (is_shut_down_received && !is_write_needed)
- return handler_(boost::asio::error(boost::asio::error::eof), 0);
+ return handler_(boost::asio::error::eof, 0);
if (is_shut_down_received)
// Shutdown has been requested, while we were reading or writing...
// abort our action...
- return handler_(boost::asio::error(boost::asio::error::shut_down), 0);
+ return handler_(boost::asio::error::shut_down, 0);
if (!is_operation_done && !is_read_needed && !is_write_needed
&& !is_shut_down_sent)
@@ -172,9 +173,15 @@
// The operation has failed... It is not completed and does
// not want network communication nor does want to send shutdown out...
if (error_code == SSL_ERROR_SYSCALL)
- return handler_(boost::asio::error(sys_error_code), rc);
+ {
+ return handler_(boost::system::error_code(
+ sys_error_code, boost::system::native_ecat), rc);
+ }
else
- return handler_(boost::asio::error(error_code + 1000000), rc);
+ {
+ return handler_(boost::system::error_code(
+ error_code, boost::asio::error::ssl_ecat), rc);
+ }
}
if (!is_operation_done && !is_write_needed)
@@ -199,7 +206,7 @@
if (!BIO_should_retry(ssl_bio_))
{
// Some serios error with BIO....
- return
handler_(boost::asio::error(boost::asio::error::no_recovery), 0);
+ return handler_(boost::asio::error::no_recovery, 0);
}
}
@@ -213,7 +220,7 @@
// Private implementation
private:
- typedef boost::function<int (const boost::asio::error&, int)>
+ typedef boost::function<int (const boost::system::error_code&, int)>
int_handler_func;
typedef boost::function<int (bool, int)> write_func;
@@ -235,15 +242,15 @@
SSL* session_;
//
- int sync_user_handler(const boost::asio::error& error, int rc)
+ int sync_user_handler(const boost::system::error_code& error, int rc)
{
if (!error)
return rc;
- throw error;
+ throw boost::system::system_error(error);
}
- int async_user_handler(const boost::asio::error& error, int rc)
+ int async_user_handler(const boost::system::error_code& error, int rc)
{
user_handler_(error, rc);
return 0;
@@ -296,7 +303,7 @@
{
// Seems like fatal error
// reading from SSL BIO has failed...
- handler_(boost::asio::error(boost::asio::error::no_recovery), 0);
+ handler_(boost::asio::error::no_recovery, 0);
return 0;
}
}
@@ -304,7 +311,7 @@
if (is_operation_done)
{
// Finish the operation, with success
- handler_(boost::asio::error(), rc);
+ handler_(boost::asio::error::success, rc);
return 0;
}
@@ -316,7 +323,7 @@
}
void async_write_handler(bool is_operation_done, int rc,
- const boost::asio::error& error, size_t bytes_sent)
+ const boost::system::error_code& error, size_t bytes_sent)
{
if (!error)
{
@@ -324,7 +331,7 @@
send_buf_.data_removed(bytes_sent);
if (is_operation_done)
- handler_(boost::asio::error(), rc);
+ handler_(boost::asio::error::success, rc);
else
// Since the operation was not completed, try it again...
start();
@@ -350,7 +357,8 @@
);
}
- void async_read_handler(const boost::asio::error& error, size_t bytes_recvd)
+ void async_read_handler(const boost::system::error_code& error,
+ size_t bytes_recvd)
{
if (!error)
{
@@ -373,7 +381,7 @@
if (!BIO_should_retry(ssl_bio_))
{
// Some serios error with BIO....
- handler_(boost::asio::error(boost::asio::error::no_recovery), 0);
+ handler_(boost::asio::error::no_recovery, 0);
return;
}
}
@@ -417,7 +425,7 @@
{
// Seems like fatal error
// reading from SSL BIO has failed...
- throw boost::asio::error(boost::asio::error::no_recovery);
+ throw boost::system::system_error(boost::asio::error::no_recovery);
}
}
@@ -457,7 +465,7 @@
if (!BIO_should_retry(ssl_bio_))
{
// Some serios error with BIO....
- throw boost::asio::error(boost::asio::error::no_recovery);
+ throw boost::system::system_error(boost::asio::error::no_recovery);
}
}
Index: openssl_stream_service.hpp
===================================================================
RCS file:
/cvsroot/boost/boost/boost/asio/ssl/detail/openssl_stream_service.hpp,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -d -r1.4 -r1.5
--- openssl_stream_service.hpp 4 Nov 2006 07:14:09 -0000 1.4
+++ openssl_stream_service.hpp 8 Nov 2006 05:32:12 -0000 1.5
@@ -26,6 +26,7 @@
#include <boost/bind.hpp>
#include <boost/asio/detail/pop_options.hpp>
+#include <boost/asio/error.hpp>
#include <boost/asio/io_service.hpp>
#include <boost/asio/ssl/basic_context.hpp>
#include <boost/asio/ssl/stream_base.hpp>
@@ -46,7 +47,8 @@
class base_handler
{
public:
- typedef boost::function<void (const boost::asio::error&, size_t)> func_t;
+ typedef boost::function<
+ void (const boost::system::error_code&, size_t)> func_t;
base_handler(boost::asio::io_service& io_service)
: op_(NULL)
@@ -54,7 +56,7 @@
, work_(io_service)
{}
- void do_func(const boost::asio::error& error, size_t size)
+ void do_func(const boost::system::error_code& error, size_t size)
{
func_(error, size);
}
@@ -91,7 +93,7 @@
private:
Handler handler_;
- void handler_impl(const boost::asio::error& error, size_t size)
+ void handler_impl(const boost::system::error_code& error, size_t size)
{
handler_(error, size);
delete this;
@@ -115,7 +117,7 @@
private:
Handler handler_;
- void handler_impl(const boost::asio::error& error, size_t)
+ void handler_impl(const boost::system::error_code& error, size_t)
{
handler_(error);
delete this;
@@ -140,7 +142,7 @@
private:
Handler handler_;
- void handler_impl(const boost::asio::error& error, size_t)
+ void handler_impl(const boost::system::error_code& error, size_t)
{
handler_(error);
delete this;
@@ -202,9 +204,9 @@
}
// Perform SSL handshaking.
- template <typename Stream, typename Error_Handler>
- void handshake(impl_type& impl, Stream& next_layer,
- stream_base::handshake_type type, Error_Handler error_handler)
+ template <typename Stream>
+ boost::system::error_code handshake(impl_type& impl, Stream& next_layer,
+ stream_base::handshake_type type, boost::system::error_code& ec)
{
try
{
@@ -218,14 +220,14 @@
impl->ext_bio);
op.start();
}
- catch (boost::asio::error& e)
+ catch (boost::system::system_error& e)
{
- error_handler(e);
- return;
+ ec = e.code();
+ return ec;
}
- boost::asio::error e;
- error_handler(e);
+ ec = boost::system::error_code();
+ return ec;
}
// Start an asynchronous SSL handshake.
@@ -261,9 +263,9 @@
}
// Shut down SSL on the stream.
- template <typename Stream, typename Error_Handler>
- void shutdown(impl_type& impl, Stream& next_layer,
- Error_Handler error_handler)
+ template <typename Stream>
+ boost::system::error_code shutdown(impl_type& impl, Stream& next_layer,
+ boost::system::error_code& ec)
{
try
{
@@ -275,14 +277,14 @@
impl->ext_bio);
op.start();
}
- catch (boost::asio::error& e)
+ catch (boost::system::system_error& e)
{
- error_handler(e);
- return;
+ ec = e.code();
+ return ec;
}
- boost::asio::error e;
- error_handler(e);
+ ec = boost::system::error_code();
+ return ec;
}
// Asynchronously shut down SSL on the stream.
@@ -315,9 +317,9 @@
}
// Write some data to the stream.
- template <typename Stream, typename Const_Buffers, typename Error_Handler>
+ template <typename Stream, typename Const_Buffers>
std::size_t write_some(impl_type& impl, Stream& next_layer,
- const Const_Buffers& buffers, Error_Handler error_handler)
+ const Const_Buffers& buffers, boost::system::error_code& ec)
{
size_t bytes_transferred = 0;
try
@@ -335,14 +337,13 @@
);
bytes_transferred = static_cast<size_t>(op.start());
}
- catch (boost::asio::error& e)
+ catch (boost::system::system_error& e)
{
- error_handler(e);
+ ec = e.code();
return 0;
}
- boost::asio::error e;
- error_handler(e);
+ ec = boost::system::error_code();
return bytes_transferred;
}
@@ -381,9 +382,9 @@
}
// Read some data from the stream.
- template <typename Stream, typename Mutable_Buffers, typename Error_Handler>
+ template <typename Stream, typename Mutable_Buffers>
std::size_t read_some(impl_type& impl, Stream& next_layer,
- const Mutable_Buffers& buffers, Error_Handler error_handler)
+ const Mutable_Buffers& buffers, boost::system::error_code& ec)
{
size_t bytes_transferred = 0;
try
@@ -401,14 +402,13 @@
bytes_transferred = static_cast<size_t>(op.start());
}
- catch (boost::asio::error& e)
+ catch (boost::system::system_error& e)
{
- error_handler(e);
+ ec = e.code();
return 0;
}
- boost::asio::error e;
- error_handler(e);
+ ec = boost::system::error_code();
return bytes_transferred;
}
@@ -447,22 +447,20 @@
}
// Peek at the incoming data on the stream.
- template <typename Stream, typename Mutable_Buffers, typename Error_Handler>
+ template <typename Stream, typename Mutable_Buffers>
std::size_t peek(impl_type& impl, Stream& next_layer,
- const Mutable_Buffers& buffers, Error_Handler error_handler)
+ const Mutable_Buffers& buffers, boost::system::error_code& ec)
{
- boost::asio::error e;
- error_handler(e);
+ ec = boost::system::error_code();
return 0;
}
// Determine the amount of data that may be read without blocking.
- template <typename Stream, typename Error_Handler>
+ template <typename Stream>
std::size_t in_avail(impl_type& impl, Stream& next_layer,
- Error_Handler error_handler)
+ boost::system::error_code& ec)
{
- boost::asio::error e;
- error_handler(e);
+ ec = boost::system::error_code();
return 0;
}
-------------------------------------------------------------------------
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