Major refactor to support standalone Asio and remove Boost dependencies

It is now possible to use WebSocket++’s asio transport using only
standalone asio by defining ASIO_STANDALONE before including any
WebSocket++ headers.
This commit is contained in:
Peter Thorson
2015-04-25 07:17:28 -04:00
parent d670d69c6e
commit 769fe89533
19 changed files with 370 additions and 195 deletions
+1 -1
View File
@@ -9,7 +9,7 @@ project (websocketpp)
cmake_minimum_required (VERSION 2.6)
set (WEBSOCKETPP_MAJOR_VERSION 0)
set (WEBSOCKETPP_MINOR_VERSION 5)
set (WEBSOCKETPP_MINOR_VERSION 6)
set (WEBSOCKETPP_PATCH_VERSION 0)
set (WEBSOCKETPP_VERSION ${WEBSOCKETPP_MAJOR_VERSION}.${WEBSOCKETPP_MINOR_VERSION}.${WEBSOCKETPP_PATCH_VERSION})
+1 -1
View File
@@ -33,7 +33,7 @@ PROJECT_NAME = "websocketpp"
# if some version control system is used.
PROJECT_NUMBER = "0.5.x-dev"
PROJECT_NUMBER = "0.6.x-dev"
# Using the PROJECT_BRIEF tag one can provide an optional one line description
+23 -3
View File
@@ -2,17 +2,37 @@ HEAD
- BREAKING TRANSPORT POLICY CHANGE: Custom transport policies will now be
required to include a new method `void set_uri(uri_ptr u)`. An implementation
is not required. The stub transport policy includes an example stub method
that can be pasted into any existing custom transport policy to fulfill this
that can be added to any existing custom transport policy to fulfill this
requirement. This does not affect anyone using the bundled transports or
configs.
- BREAKING SOCKET POLICY CHANGE: Custom asio transport socket policies will now
be required to include a new method `void set_uri(uri_ptr u)`. Like with the
transport layer, an implementation is not required. This does not affect
anyone using the bundled socket policies.
- Improvement: Outgoing TLS connections to servers using the SNI extension to
choose a certificate will now work.
- Feature: WebSocket++ Asio transport policy can now be used with the standalone
version of Asio (1.8.0+) when a C++11 compiler and standard library are
present. This means that it is possible now to use WebSocket++'s Asio
transport entirely without Boost.
- Feature: Adds a vectored/scatter-gather write handler to the iostream
transport.
- Improvement: `endpoint::set_timer` now uses a steady clock provided by
`boost::chrono` or `std::chrono` where available instead of the non-monotonic
system clock. Thank you breyed for reporting. fixes #241
- Improvement: Outgoing TLS connections to servers using the SNI extension to
choose a certificate will now work.
- Cleanup: Asio transport policy has been refactored to remove many Boost
dependencies. On C++03 compilers the `boost::noncopyable` dependency has been
removed and the `boost::date_time` dependency has been replaced with the newer
`boost::chrono` when possible. On C++11 compilers the `boost::aligned_storage`
and `boost::date_time` dependencies are gone, replaced with equivalent C++11
standard library features.
0.5.1 - 2015-02-27
- Bug: Fixes an issue where some frame data was counted against the max header
size limit, resulting in connections that included a lot of frame data
immediately after the opening handshake to fail.
- Bug: Fix a typo in the name of the set method for `max_http_body_size`. #406
Thank you jplatte for reporting.
0.5.0 - 2015-01-22
- BREAKING UTILITY CHANGE: Deprecated methods `http::parser::parse_headers`,
@@ -30,9 +30,9 @@ public:
// Bind the handlers we are using
using websocketpp::lib::placeholders::_1;
using websocketpp::lib::bind;
m_client.set_open_handler(bind(&telemetry_client::on_open,this,::_1));
m_client.set_close_handler(bind(&telemetry_client::on_close,this,::_1));
m_client.set_fail_handler(bind(&telemetry_client::on_fail,this,::_1));
m_client.set_open_handler(bind(&telemetry_client::on_open,this,_1));
m_client.set_close_handler(bind(&telemetry_client::on_close,this,_1));
m_client.set_fail_handler(bind(&telemetry_client::on_fail,this,_1));
}
// This method will block until the connection is complete
@@ -46,9 +46,9 @@ public:
// Bind the handlers we are using
using websocketpp::lib::placeholders::_1;
using websocketpp::lib::bind;
m_endpoint.set_open_handler(bind(&telemetry_server::on_open,this,::_1));
m_endpoint.set_close_handler(bind(&telemetry_server::on_close,this,::_1));
m_endpoint.set_http_handler(bind(&telemetry_server::on_http,this,::_1));
m_endpoint.set_open_handler(bind(&telemetry_server::on_open,this,_1));
m_endpoint.set_close_handler(bind(&telemetry_server::on_close,this,_1));
m_endpoint.set_http_handler(bind(&telemetry_server::on_http,this,_1));
}
void run(std::string docroot, uint16_t port) {
+5 -3
View File
@@ -1,10 +1,12 @@
WebSocket++ (0.5.x-dev)
WebSocket++ (0.6.x-dev)
==========================
WebSocket++ is a header only C++ library that implements RFC6455 The WebSocket
Protocol. It allows integrating WebSocket client and server functionality into
C++ programs. It uses interchangeable network transport modules including one
based on C++ iostreams and one based on Boost Asio.
based on raw char buffers, one based on C++ iostreams, and one based on Asio
(either via Boost or standalone). End users can write additional transport
policies to support other networking or event libraries as needed.
Major Features
==============
@@ -13,7 +15,7 @@ Major Features
* Message/event based interface
* Supports secure WebSockets (TLS), IPv6, and explicit proxies.
* Flexible dependency management (C++11 Standard Library or Boost)
* Interchangeable network transport modules (iostream and Boost Asio)
* Interchangeable network transport modules (raw, iostream, Asio, or custom)
* Portable/cross platform (Posix/Windows, 32/64bit, Intel/ARM/PPC)
* Thread-safe
+1 -1
View File
@@ -11,7 +11,7 @@ Import('tls_libs')
env = env.Clone ()
env_cpp11 = env_cpp11.Clone ()
BOOST_LIBS = boostlibs(['unit_test_framework','system','thread','random'],env) + [platform_libs] + [tls_libs]
BOOST_LIBS = boostlibs(['unit_test_framework','system','thread','random','chrono'],env) + [platform_libs] + [tls_libs]
objs = env.Object('boost_integration.o', ["integration.cpp"], LIBS = BOOST_LIBS)
prgs = env.Program('test_boost_integration', ["boost_integration.o"], LIBS = BOOST_LIBS)
+1 -1
View File
@@ -11,7 +11,7 @@ Import('tls_libs')
env = env.Clone ()
env_cpp11 = env_cpp11.Clone ()
BOOST_LIBS = boostlibs(['unit_test_framework','system','thread'],env) + [platform_libs] + [tls_libs]
BOOST_LIBS = boostlibs(['unit_test_framework','system','thread','chrono'],env) + [platform_libs] + [tls_libs]
objs = env.Object('base_boost.o', ["base.cpp"], LIBS = BOOST_LIBS)
objs += env.Object('timers_boost.o', ["timers.cpp"], LIBS = BOOST_LIBS)
+130
View File
@@ -0,0 +1,130 @@
/*
* Copyright (c) 2015, Peter Thorson. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* * Neither the name of the WebSocket++ Project nor the
* names of its contributors may be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL PETER THORSON BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*/
#ifndef WEBSOCKETPP_COMMON_ASIO_HPP
#define WEBSOCKETPP_COMMON_ASIO_HPP
// This file goes to some length to preserve compatibility with versions of
// boost older than 1.49 (where the first modern steady_timer timer based on
// boost/std chrono was introduced.
//
// For the versions older than 1.49, the deadline_timer is used instead. this
// brings in dependencies on boost date_time and it has a different interface
// that is normalized by the `lib::asio::is_neg` and `lib::asio::milliseconds`
// wrappers provided by this file.
//
// The primary reason for this continued support is that boost 1.48 is the
// default and not easily changeable version of boost supplied by the package
// manager of popular Linux distributions like Ubuntu 12.04 LTS. Once the need
// for this has passed this should be cleaned up and simplified.
#ifdef ASIO_STANDALONE
#include <asio/version.hpp>
#if (ASIO_VERSION/100000) == 1 && ((ASIO_VERSION/100)%1000) < 8
static_assert(false, "The minimum version of standalone Asio is 1.8.0");
#endif
#include <asio.hpp>
#include <asio/steady_timer.hpp>
#include <websocketpp/common/chrono.hpp>
#else
#include <boost/asio.hpp>
// See note above about boost <1.49 compatibility. If we are running on
// boost > 1.48 pull in the steady timer and chrono library
#if (BOOST_VERSION/100000) == 1 && ((BOOST_VERSION/100)%1000) > 48
#include <boost/asio/steady_timer.hpp>
#include <websocketpp/common/chrono.hpp>
#endif
#include <boost/system/error_code.hpp>
#endif
namespace websocketpp {
namespace lib {
#ifdef ASIO_STANDALONE
namespace asio {
using namespace ::asio;
// Here we assume that we will be using std::error_code with standalone
// Asio. This is probably a good assumption, but it is possible in rare
// cases that local Asio versions would be used.
using std::errc;
// See note above about boost <1.49 compatibility. Because we require
// a standalone Asio version of 1.8+ we are guaranteed to have
// steady_timer available. By convention we require the chrono library
// (either boost or std) for use with standalone Asio.
template <typename T>
bool is_neg(T duration) {
return duration.count() < 0;
}
inline lib::chrono::milliseconds milliseconds(long duration) {
return lib::chrono::milliseconds(duration);
}
} // namespace asio
#else
namespace asio {
using namespace boost::asio;
// See note above about boost <1.49 compatibility
#if (BOOST_VERSION/100000) == 1 && ((BOOST_VERSION/100)%1000) > 48
// Using boost::asio >=1.49 so we use chrono and steady_timer
template <typename T>
bool is_neg(T duration) {
return duration.count() < 0;
}
inline lib::chrono::milliseconds milliseconds(long duration) {
return lib::chrono::milliseconds(duration);
}
#else
// Using boost::asio <1.49 we pretend a deadline timer is a steady
// timer and wrap the negative detection and duration conversion
// appropriately.
typedef boost::asio::deadline_timer steady_timer;
template <typename T>
bool is_neg(T duration) {
return duration.is_negative();
}
inline boost::posix_time::time_duration milliseconds(long duration) {
return boost::posix_time::milliseconds(duration);
}
#endif
using boost::system::error_code;
namespace errc = boost::system::errc;
} // namespace asio
#endif
} // namespace lib
} // namespace websocketpp
#endif // WEBSOCKETPP_COMMON_ASIO_HPP
+37
View File
@@ -0,0 +1,37 @@
/*
* Copyright (c) 2015, Peter Thorson. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* * Neither the name of the WebSocket++ Project nor the
* names of its contributors may be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL PETER THORSON BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*/
#ifndef WEBSOCKETPP_COMMON_ASIO_SSL_HPP
#define WEBSOCKETPP_COMMON_ASIO_SSL_HPP
#ifdef ASIO_STANDALONE
#include <asio/asio/ssl.hpp>
#else
#include <boost/asio/ssl.hpp>
#endif
#endif // WEBSOCKETPP_COMMON_ASIO_SSL_HPP
+2 -2
View File
@@ -44,9 +44,9 @@ namespace websocketpp {
namespace lib {
#ifdef _WEBSOCKETPP_CPP11_CHRONO_
using std::chrono::system_clock;
namespace chrono = std::chrono;
#else
using boost::chrono::system_clock;
namespace chrono = boost::chrono;
#endif
} // namespace lib
+2
View File
@@ -61,6 +61,7 @@ namespace websocketpp {
namespace lib {
#ifdef _WEBSOCKETPP_CPP11_SYSTEM_ERROR_
using std::errc;
using std::error_code;
using std::error_category;
using std::error_condition;
@@ -68,6 +69,7 @@ namespace lib {
#define _WEBSOCKETPP_ERROR_CODE_ENUM_NS_START_ namespace std {
#define _WEBSOCKETPP_ERROR_CODE_ENUM_NS_END_ }
#else
namespace errc = boost::system::errc;
using boost::system::error_code;
using boost::system::error_category;
using boost::system::error_condition;
+7 -10
View File
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2014, Peter Thorson. All rights reserved.
* Copyright (c) 2015, Peter Thorson. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
@@ -28,26 +28,23 @@
#ifndef WEBSOCKETPP_TRANSPORT_ASIO_BASE_HPP
#define WEBSOCKETPP_TRANSPORT_ASIO_BASE_HPP
#include <websocketpp/common/asio.hpp>
#include <websocketpp/common/cpp11.hpp>
#include <websocketpp/common/functional.hpp>
#include <websocketpp/common/system_error.hpp>
#include <websocketpp/common/type_traits.hpp>
#include <boost/system/error_code.hpp>
#include <string>
namespace websocketpp {
namespace transport {
/// Transport policy that uses boost::asio
/// Transport policy that uses asio
/**
* This policy uses a single boost::asio io_service to provide transport
* This policy uses a single asio io_service to provide transport
* services to a WebSocket++ endpoint.
*/
namespace asio {
//
// Class to manage the memory to be used for handler-based custom allocation.
// It contains a single block of memory which may be returned for allocation
// requests. If the memory is in use when an allocation request is made, the
@@ -145,13 +142,13 @@ inline custom_alloc_handler<Handler> make_custom_alloc_handler(
template <typename config>
class endpoint;
typedef lib::function<void(boost::system::error_code const &)>
typedef lib::function<void(lib::asio::error_code const &)>
socket_shutdown_handler;
typedef lib::function<void (boost::system::error_code const & ec,
typedef lib::function<void (lib::asio::error_code const & ec,
size_t bytes_transferred)> async_read_handler;
typedef lib::function<void (boost::system::error_code const & ec,
typedef lib::function<void (lib::asio::error_code const & ec,
size_t bytes_transferred)> async_write_handler;
typedef lib::function<void (lib::error_code const & ec)> pre_init_handler;
+49 -50
View File
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2014, Peter Thorson. All rights reserved.
* Copyright (c) 2015, Peter Thorson. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
@@ -39,14 +39,13 @@
#include <websocketpp/error.hpp>
#include <websocketpp/uri.hpp>
#include <websocketpp/common/asio.hpp>
#include <websocketpp/common/chrono.hpp>
#include <websocketpp/common/cpp11.hpp>
#include <websocketpp/common/memory.hpp>
#include <websocketpp/common/functional.hpp>
#include <websocketpp/common/connection_hdl.hpp>
#include <boost/asio.hpp>
#include <boost/system/error_code.hpp>
#include <istream>
#include <sstream>
#include <string>
@@ -58,10 +57,10 @@ namespace asio {
typedef lib::function<void(connection_hdl)> tcp_init_handler;
/// Boost Asio based connection transport component
/// Asio based connection transport component
/**
* transport::asio::connection implements a connection transport component using
* Boost ASIO that works with the transport::asio::endpoint endpoint transport
* Asio that works with the transport::asio::endpoint endpoint transport
* component.
*/
template <typename config>
@@ -86,12 +85,12 @@ public:
typedef typename config::response_type response_type;
typedef typename response_type::ptr response_ptr;
/// Type of a pointer to the ASIO io_service being used
typedef boost::asio::io_service* io_service_ptr;
/// Type of a pointer to the ASIO io_service::strand being used
typedef lib::shared_ptr<boost::asio::io_service::strand> strand_ptr;
/// Type of a pointer to the ASIO timer class
typedef lib::shared_ptr<boost::asio::deadline_timer> timer_ptr;
/// Type of a pointer to the Asio io_service being used
typedef lib::asio::io_service * io_service_ptr;
/// Type of a pointer to the Asio io_service::strand being used
typedef lib::shared_ptr<lib::asio::io_service::strand> strand_ptr;
/// Type of a pointer to the Asio timer class
typedef lib::shared_ptr<lib::asio::steady_timer> timer_ptr;
// connection is friends with its associated endpoint to allow the endpoint
// to call private/protected utility methods that we don't want to expose
@@ -99,7 +98,7 @@ public:
friend class endpoint<config>;
// generate and manage our own io_service
explicit connection(bool is_server, alog_type& alog, elog_type& elog)
explicit connection(bool is_server, alog_type & alog, elog_type & elog)
: m_is_server(is_server)
, m_alog(alog)
, m_elog(elog)
@@ -312,9 +311,9 @@ public:
* needed.
*/
timer_ptr set_timer(long duration, timer_handler callback) {
timer_ptr new_timer = lib::make_shared<boost::asio::deadline_timer>(
timer_ptr new_timer = lib::make_shared<lib::asio::steady_timer>(
lib::ref(*m_io_service),
boost::posix_time::milliseconds(duration)
lib::asio::milliseconds(duration)
);
if (config::enable_multithreading) {
@@ -348,10 +347,10 @@ public:
* @param ec The status code
*/
void handle_timer(timer_ptr, timer_handler callback,
boost::system::error_code const & ec)
lib::asio::error_code const & ec)
{
if (ec) {
if (ec == boost::asio::error::operation_aborted) {
if (ec == lib::asio::error::operation_aborted) {
callback(make_error_code(transport::error::operation_aborted));
} else {
log_err(log::elevel::info,"asio handle_timer",ec);
@@ -370,7 +369,7 @@ public:
/// Initialize transport for reading
/**
* init_asio is called once immediately after construction to initialize
* boost::asio components to the io_service
* Asio components to the io_service
*
* The transport initialization sequence consists of the following steps:
* - Pre-init: the underlying socket is initialized to the point where
@@ -429,7 +428,7 @@ protected:
/// Finish constructing the transport
/**
* init_asio is called once immediately after construction to initialize
* boost::asio components to the io_service.
* Asio components to the io_service.
*
* @param io_service A pointer to the io_service to register with this
* connection
@@ -440,7 +439,7 @@ protected:
m_io_service = io_service;
if (config::enable_multithreading) {
m_strand = lib::make_shared<boost::asio::strand>(
m_strand = lib::make_shared<lib::asio::strand>(
lib::ref(*io_service));
m_async_read_handler = m_strand->wrap(lib::bind(
@@ -573,7 +572,7 @@ protected:
lib::error_code const & ec)
{
if (ec == transport::error::operation_aborted ||
(post_timer && post_timer->expires_from_now().is_negative()))
(post_timer && lib::asio::is_neg(post_timer->expires_from_now())))
{
m_alog.write(log::alevel::devel,"post_init cancelled");
return;
@@ -608,8 +607,8 @@ protected:
m_proxy_data->write_buf = m_proxy_data->req.raw();
m_bufs.push_back(boost::asio::buffer(m_proxy_data->write_buf.data(),
m_proxy_data->write_buf.size()));
m_bufs.push_back(lib::asio::buffer(m_proxy_data->write_buf.data(),
m_proxy_data->write_buf.size()));
m_alog.write(log::alevel::devel,m_proxy_data->write_buf);
@@ -626,7 +625,7 @@ protected:
// Send proxy request
if (config::enable_multithreading) {
boost::asio::async_write(
lib::asio::async_write(
socket_con_type::get_next_layer(),
m_bufs,
m_strand->wrap(lib::bind(
@@ -636,7 +635,7 @@ protected:
))
);
} else {
boost::asio::async_write(
lib::asio::async_write(
socket_con_type::get_next_layer(),
m_bufs,
lib::bind(
@@ -666,7 +665,7 @@ protected:
}
void handle_proxy_write(init_handler callback,
boost::system::error_code const & ec)
lib::asio::error_code const & ec)
{
if (m_alog.static_test(log::alevel::devel)) {
m_alog.write(log::alevel::devel,
@@ -678,8 +677,8 @@ protected:
// Timer expired or the operation was aborted for some reason.
// Whatever aborted it will be issuing the callback so we are safe to
// return
if (ec == boost::asio::error::operation_aborted ||
m_proxy_data->timer->expires_from_now().is_negative())
if (ec == lib::asio::error::operation_aborted ||
lib::asio::is_neg(m_proxy_data->timer->expires_from_now()))
{
m_elog.write(log::elevel::devel,"write operation aborted");
return;
@@ -709,7 +708,7 @@ protected:
}
if (config::enable_multithreading) {
boost::asio::async_read_until(
lib::asio::async_read_until(
socket_con_type::get_next_layer(),
m_proxy_data->read_buf,
"\r\n\r\n",
@@ -720,7 +719,7 @@ protected:
))
);
} else {
boost::asio::async_read_until(
lib::asio::async_read_until(
socket_con_type::get_next_layer(),
m_proxy_data->read_buf,
"\r\n\r\n",
@@ -740,7 +739,7 @@ protected:
* @param bytes_transferred The number of bytes read
*/
void handle_proxy_read(init_handler callback,
boost::system::error_code const & ec, size_t)
lib::asio::error_code const & ec, size_t)
{
if (m_alog.static_test(log::alevel::devel)) {
m_alog.write(log::alevel::devel,
@@ -750,8 +749,8 @@ protected:
// Timer expired or the operation was aborted for some reason.
// Whatever aborted it will be issuing the callback so we are safe to
// return
if (ec == boost::asio::error::operation_aborted ||
m_proxy_data->timer->expires_from_now().is_negative())
if (ec == lib::asio::error::operation_aborted ||
lib::asio::is_neg(m_proxy_data->timer->expires_from_now()))
{
m_elog.write(log::elevel::devel,"read operation aborted");
return;
@@ -854,10 +853,10 @@ protected:
"asio con async_read_at_least called with bad handler");
}
boost::asio::async_read(
lib::asio::async_read(
socket_con_type::get_socket(),
boost::asio::buffer(buf,len),
boost::asio::transfer_at_least(num_bytes),
lib::asio::buffer(buf,len),
lib::asio::transfer_at_least(num_bytes),
make_custom_alloc_handler(
m_read_handler_allocator,
m_async_read_handler
@@ -865,14 +864,14 @@ protected:
);
}
void handle_async_read(boost::system::error_code const & ec,
void handle_async_read(lib::asio::error_code const & ec,
size_t bytes_transferred)
{
m_alog.write(log::alevel::devel, "asio con handle_async_read");
// translate boost error codes into more lib::error_codes
// translate asio error codes into more lib::error_codes
lib::error_code tec;
if (ec == boost::asio::error::eof) {
if (ec == lib::asio::error::eof) {
tec = make_error_code(transport::error::eof);
} else if (ec) {
// We don't know much more about the error at this point. As our
@@ -908,11 +907,11 @@ protected:
return;
}
m_bufs.push_back(boost::asio::buffer(buf,len));
m_bufs.push_back(lib::asio::buffer(buf,len));
m_write_handler = handler;
boost::asio::async_write(
lib::asio::async_write(
socket_con_type::get_socket(),
m_bufs,
make_custom_alloc_handler(
@@ -932,12 +931,12 @@ protected:
std::vector<buffer>::const_iterator it;
for (it = bufs.begin(); it != bufs.end(); ++it) {
m_bufs.push_back(boost::asio::buffer((*it).buf,(*it).len));
m_bufs.push_back(lib::asio::buffer((*it).buf,(*it).len));
}
m_write_handler = handler;
boost::asio::async_write(
lib::asio::async_write(
socket_con_type::get_socket(),
m_bufs,
make_custom_alloc_handler(
@@ -952,7 +951,7 @@ protected:
* @param ec The status code
* @param bytes_transferred The number of bytes read
*/
void handle_async_write(boost::system::error_code const & ec, size_t) {
void handle_async_write(lib::asio::error_code const & ec, size_t) {
m_bufs.clear();
lib::error_code tec;
if (ec) {
@@ -1079,10 +1078,10 @@ protected:
}
void handle_async_shutdown(timer_ptr shutdown_timer, shutdown_handler
callback, boost::system::error_code const & ec)
callback, lib::asio::error_code const & ec)
{
if (ec == boost::asio::error::operation_aborted ||
shutdown_timer->expires_from_now().is_negative())
if (ec == lib::asio::error::operation_aborted ||
lib::asio::is_neg(shutdown_timer->expires_from_now()))
{
m_alog.write(log::alevel::devel,"async_shutdown cancelled");
return;
@@ -1092,7 +1091,7 @@ protected:
lib::error_code tec;
if (ec) {
if (ec == boost::asio::error::not_connected) {
if (ec == lib::asio::error::not_connected) {
// The socket was already closed when we tried to close it. This
// happens periodically (usually if a read or write fails
// earlier and if it is a real error will be caught at another
@@ -1142,7 +1141,7 @@ private:
request_type req;
response_type res;
std::string write_buf;
boost::asio::streambuf read_buf;
lib::asio::streambuf read_buf;
long timeout_proxy;
timer_ptr timer;
};
@@ -1155,7 +1154,7 @@ private:
strand_ptr m_strand;
connection_hdl m_connection_hdl;
std::vector<boost::asio::const_buffer> m_bufs;
std::vector<lib::asio::const_buffer> m_bufs;
// Handlers
tcp_init_handler m_tcp_pre_init_handler;
+51 -55
View File
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2014, Peter Thorson. All rights reserved.
* Copyright (c) 2015, Peter Thorson. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
@@ -37,10 +37,6 @@
#include <websocketpp/common/functional.hpp>
#include <boost/asio.hpp>
#include <boost/bind.hpp>
#include <boost/system/error_code.hpp>
#include <sstream>
#include <string>
@@ -48,10 +44,10 @@ namespace websocketpp {
namespace transport {
namespace asio {
/// Boost Asio based endpoint transport component
/// Asio based endpoint transport component
/**
* transport::asio::endpoint implements an endpoint transport component using
* Boost ASIO.
* Asio.
*/
template <typename config>
class endpoint : public config::socket_type {
@@ -81,15 +77,15 @@ public:
typedef typename transport_con_type::ptr transport_con_ptr;
/// Type of a pointer to the ASIO io_service being used
typedef boost::asio::io_service* io_service_ptr;
typedef lib::asio::io_service * io_service_ptr;
/// Type of a shared pointer to the acceptor being used
typedef lib::shared_ptr<boost::asio::ip::tcp::acceptor> acceptor_ptr;
typedef lib::shared_ptr<lib::asio::ip::tcp::acceptor> acceptor_ptr;
/// Type of a shared pointer to the resolver being used
typedef lib::shared_ptr<boost::asio::ip::tcp::resolver> resolver_ptr;
typedef lib::shared_ptr<lib::asio::ip::tcp::resolver> resolver_ptr;
/// Type of timer handle
typedef lib::shared_ptr<boost::asio::deadline_timer> timer_ptr;
typedef lib::shared_ptr<lib::asio::steady_timer> timer_ptr;
/// Type of a shared pointer to an io_service work object
typedef lib::shared_ptr<boost::asio::io_service::work> work_ptr;
typedef lib::shared_ptr<lib::asio::io_service::work> work_ptr;
// generate and manage our own io_service
explicit endpoint()
@@ -131,7 +127,7 @@ public:
, m_io_service(src.m_io_service)
, m_external_io_service(src.m_external_io_service)
, m_acceptor(src.m_acceptor)
, m_listen_backlog(boost::asio::socket_base::max_connections)
, m_listen_backlog(lib::asio::socket_base::max_connections)
, m_reuse_addr(src.m_reuse_addr)
, m_elog(src.m_elog)
, m_alog(src.m_alog)
@@ -155,7 +151,7 @@ public:
rhs.m_io_service = NULL;
rhs.m_external_io_service = false;
rhs.m_acceptor = NULL;
rhs.m_listen_backlog = boost::asio::socket_base::max_connections;
rhs.m_listen_backlog = lib::asio::socket_base::max_connections;
rhs.m_state = UNINITIALIZED;
// TODO: this needs to be updated
@@ -191,7 +187,7 @@ public:
m_io_service = ptr;
m_external_io_service = true;
m_acceptor = lib::make_shared<boost::asio::ip::tcp::acceptor>(
m_acceptor = lib::make_shared<lib::asio::ip::tcp::acceptor>(
lib::ref(*m_io_service));
m_state = READY;
@@ -222,7 +218,7 @@ public:
* @param ec Set to indicate what error occurred, if any.
*/
void init_asio(lib::error_code & ec) {
init_asio(new boost::asio::io_service(), ec);
init_asio(new lib::asio::io_service(), ec);
m_external_io_service = false;
}
@@ -234,7 +230,7 @@ public:
* @see init_asio(io_service_ptr ptr)
*/
void init_asio() {
init_asio(new boost::asio::io_service());
init_asio(new lib::asio::io_service());
m_external_io_service = false;
}
@@ -333,7 +329,7 @@ public:
*
* @return A reference to the endpoint's io_service
*/
boost::asio::io_service & get_io_service() {
lib::asio::io_service & get_io_service() {
return *m_io_service;
}
@@ -345,7 +341,7 @@ public:
* @param ep An endpoint to read settings from
* @param ec Set to indicate what error occurred, if any.
*/
void listen(boost::asio::ip::tcp::endpoint const & ep, lib::error_code & ec)
void listen(lib::asio::ip::tcp::endpoint const & ep, lib::error_code & ec)
{
if (m_state != READY) {
m_elog->write(log::elevel::library,
@@ -357,11 +353,11 @@ public:
m_alog->write(log::alevel::devel,"asio::listen");
boost::system::error_code bec;
lib::asio::error_code bec;
m_acceptor->open(ep.protocol(),bec);
if (!bec) {
m_acceptor->set_option(boost::asio::socket_base::reuse_address(m_reuse_addr),bec);
m_acceptor->set_option(lib::asio::socket_base::reuse_address(m_reuse_addr),bec);
}
if (!bec) {
m_acceptor->bind(ep,bec);
@@ -387,7 +383,7 @@ public:
*
* @param ep An endpoint to read settings from
*/
void listen(boost::asio::ip::tcp::endpoint const & ep) {
void listen(lib::asio::ip::tcp::endpoint const & ep) {
lib::error_code ec;
listen(ep,ec);
if (ec) { throw exception(ec); }
@@ -400,8 +396,8 @@ public:
* listening.
*
* Common options include:
* - IPv6 with mapped IPv4 for dual stack hosts boost::asio::ip::tcp::v6()
* - IPv4 only: boost::asio::ip::tcp::v4()
* - IPv6 with mapped IPv4 for dual stack hosts lib::asio::ip::tcp::v6()
* - IPv4 only: lib::asio::ip::tcp::v4()
*
* @param internet_protocol The internet protocol to use.
* @param port The port to listen on.
@@ -411,7 +407,7 @@ public:
void listen(InternetProtocol const & internet_protocol, uint16_t port,
lib::error_code & ec)
{
boost::asio::ip::tcp::endpoint ep(internet_protocol, port);
lib::asio::ip::tcp::endpoint ep(internet_protocol, port);
listen(ep,ec);
}
@@ -422,8 +418,8 @@ public:
* listening.
*
* Common options include:
* - IPv6 with mapped IPv4 for dual stack hosts boost::asio::ip::tcp::v6()
* - IPv4 only: boost::asio::ip::tcp::v4()
* - IPv6 with mapped IPv4 for dual stack hosts lib::asio::ip::tcp::v6()
* - IPv4 only: lib::asio::ip::tcp::v4()
*
* @param internet_protocol The internet protocol to use.
* @param port The port to listen on.
@@ -431,7 +427,7 @@ public:
template <typename InternetProtocol>
void listen(InternetProtocol const & internet_protocol, uint16_t port)
{
boost::asio::ip::tcp::endpoint ep(internet_protocol, port);
lib::asio::ip::tcp::endpoint ep(internet_protocol, port);
listen(ep);
}
@@ -448,7 +444,7 @@ public:
* @param ec Set to indicate what error occurred, if any.
*/
void listen(uint16_t port, lib::error_code & ec) {
listen(boost::asio::ip::tcp::v6(), port, ec);
listen(lib::asio::ip::tcp::v6(), port, ec);
}
/// Set up endpoint for listening on a port
@@ -464,13 +460,13 @@ public:
* @param ec Set to indicate what error occurred, if any.
*/
void listen(uint16_t port) {
listen(boost::asio::ip::tcp::v6(), port);
listen(lib::asio::ip::tcp::v6(), port);
}
/// Set up endpoint for listening on a host and service (exception free)
/**
* Bind the internal acceptor using the given host and service. More details
* about what host and service can be are available in the boost asio
* about what host and service can be are available in the Asio
* documentation for ip::basic_resolver_query::basic_resolver_query's
* constructors.
*
@@ -486,7 +482,7 @@ public:
void listen(std::string const & host, std::string const & service,
lib::error_code & ec)
{
using boost::asio::ip::tcp;
using lib::asio::ip::tcp;
tcp::resolver r(*m_io_service);
tcp::resolver::query query(host, service);
tcp::resolver::iterator endpoint_iterator = r.resolve(query);
@@ -503,7 +499,7 @@ public:
/// Set up endpoint for listening on a host and service
/**
* Bind the internal acceptor using the given host and service. More details
* about what host and service can be are available in the boost asio
* about what host and service can be are available in the Asio
* documentation for ip::basic_resolver_query::basic_resolver_query's
* constructors.
*
@@ -617,7 +613,7 @@ public:
* @since 0.3.0
*/
void start_perpetual() {
m_work = lib::make_shared<boost::asio::io_service::work>(
m_work = lib::make_shared<lib::asio::io_service::work>(
lib::ref(*m_io_service)
);
}
@@ -647,9 +643,9 @@ public:
* needed.
*/
timer_ptr set_timer(long duration, timer_handler callback) {
timer_ptr new_timer = lib::make_shared<boost::asio::deadline_timer>(
timer_ptr new_timer = lib::make_shared<lib::asio::steady_timer>(
*m_io_service,
boost::posix_time::milliseconds(duration)
lib::asio::milliseconds(duration)
);
new_timer->async_wait(
@@ -675,10 +671,10 @@ public:
* @param ec A status code indicating an error, if any.
*/
void handle_timer(timer_ptr, timer_handler callback,
boost::system::error_code const & ec)
lib::asio::error_code const & ec)
{
if (ec) {
if (ec == boost::asio::error::operation_aborted) {
if (ec == lib::asio::error::operation_aborted) {
callback(make_error_code(transport::error::operation_aborted));
} else {
m_elog->write(log::elevel::info,
@@ -757,18 +753,18 @@ protected:
m_elog = e;
}
void handle_accept(accept_handler callback, boost::system::error_code const
& boost_ec)
void handle_accept(accept_handler callback, lib::asio::error_code const &
asio_ec)
{
lib::error_code ret_ec;
m_alog->write(log::alevel::devel, "asio::handle_accept");
if (boost_ec) {
if (boost_ec == boost::system::errc::operation_canceled) {
if (asio_ec) {
if (asio_ec == lib::asio::errc::operation_canceled) {
ret_ec = make_error_code(websocketpp::error::operation_canceled);
} else {
log_err(log::elevel::info,"asio handle_accept",boost_ec);
log_err(log::elevel::info,"asio handle_accept",asio_ec);
ret_ec = make_error_code(error::pass_through);
}
}
@@ -779,11 +775,11 @@ protected:
/// Initiate a new connection
// TODO: there have to be some more failure conditions here
void async_connect(transport_con_ptr tcon, uri_ptr u, connect_handler cb) {
using namespace boost::asio::ip;
using namespace lib::asio::ip;
// Create a resolver
if (!m_resolver) {
m_resolver = lib::make_shared<boost::asio::ip::tcp::resolver>(
m_resolver = lib::make_shared<lib::asio::ip::tcp::resolver>(
lib::ref(*m_io_service));
}
@@ -898,11 +894,11 @@ protected:
}
void handle_resolve(transport_con_ptr tcon, timer_ptr dns_timer,
connect_handler callback, boost::system::error_code const & ec,
boost::asio::ip::tcp::resolver::iterator iterator)
connect_handler callback, lib::asio::error_code const & ec,
lib::asio::ip::tcp::resolver::iterator iterator)
{
if (ec == boost::asio::error::operation_aborted ||
dns_timer->expires_from_now().is_negative())
if (ec == lib::asio::error::operation_aborted ||
lib::asio::is_neg(dns_timer->expires_from_now()))
{
m_alog->write(log::alevel::devel,"async_resolve cancelled");
return;
@@ -920,7 +916,7 @@ protected:
std::stringstream s;
s << "Async DNS resolve successful. Results: ";
boost::asio::ip::tcp::resolver::iterator it, end;
lib::asio::ip::tcp::resolver::iterator it, end;
for (it = iterator; it != end; ++it) {
s << (*it).endpoint() << " ";
}
@@ -945,7 +941,7 @@ protected:
);
if (config::enable_multithreading) {
boost::asio::async_connect(
lib::asio::async_connect(
tcon->get_raw_socket(),
iterator,
tcon->get_strand()->wrap(lib::bind(
@@ -958,7 +954,7 @@ protected:
))
);
} else {
boost::asio::async_connect(
lib::asio::async_connect(
tcon->get_raw_socket(),
iterator,
lib::bind(
@@ -1007,10 +1003,10 @@ protected:
}
void handle_connect(transport_con_ptr tcon, timer_ptr con_timer,
connect_handler callback, boost::system::error_code const & ec)
connect_handler callback, lib::asio::error_code const & ec)
{
if (ec == boost::asio::error::operation_aborted ||
con_timer->expires_from_now().is_negative())
if (ec == lib::asio::error::operation_aborted ||
lib::asio::is_neg(con_timer->expires_from_now()))
{
m_alog->write(log::alevel::devel,"async_connect cancelled");
return;
@@ -34,8 +34,6 @@
#include <websocketpp/common/cpp11.hpp>
#include <websocketpp/common/connection_hdl.hpp>
#include <boost/asio.hpp>
#include <string>
// Interface that sockets/security policies must implement
+25 -26
View File
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2014, Peter Thorson. All rights reserved.
* Copyright (c) 2015, Peter Thorson. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
@@ -32,10 +32,9 @@
#include <websocketpp/transport/asio/security/base.hpp>
#include <websocketpp/common/asio.hpp>
#include <websocketpp/common/memory.hpp>
#include <boost/asio.hpp>
#include <sstream>
#include <string>
@@ -47,13 +46,13 @@ namespace asio {
namespace basic_socket {
/// The signature of the socket init handler for this socket policy
typedef lib::function<void(connection_hdl,boost::asio::ip::tcp::socket&)>
typedef lib::function<void(connection_hdl,lib::asio::ip::tcp::socket&)>
socket_init_handler;
/// Basic Boost ASIO connection socket component
/// Basic Asio connection socket component
/**
* transport::asio::basic_socket::connection implements a connection socket
* component using Boost ASIO ip::tcp::socket.
* component using Asio ip::tcp::socket.
*/
class connection : public lib::enable_shared_from_this<connection> {
public:
@@ -62,12 +61,12 @@ public:
/// Type of a shared pointer to this connection socket component
typedef lib::shared_ptr<type> ptr;
/// Type of a pointer to the ASIO io_service being used
typedef boost::asio::io_service* io_service_ptr;
/// Type of a pointer to the ASIO io_service strand being used
typedef lib::shared_ptr<boost::asio::io_service::strand> strand_ptr;
/// Type of a pointer to the Asio io_service being used
typedef lib::asio::io_service* io_service_ptr;
/// Type of a pointer to the Asio io_service strand being used
typedef lib::shared_ptr<lib::asio::io_service::strand> strand_ptr;
/// Type of the ASIO socket being used
typedef boost::asio::ip::tcp::socket socket_type;
typedef lib::asio::ip::tcp::socket socket_type;
/// Type of a shared pointer to the socket being used.
typedef lib::shared_ptr<socket_type> socket_ptr;
@@ -93,7 +92,7 @@ public:
/**
* The socket initialization handler is called after the socket object is
* created but before it is used. This gives the application a chance to
* set any ASIO socket options it needs.
* set any Asio socket options it needs.
*
* @param h The new socket_init_handler
*/
@@ -105,7 +104,7 @@ public:
/**
* This is used internally. It can also be used to set socket options, etc
*/
boost::asio::ip::tcp::socket& get_socket() {
lib::asio::ip::tcp::socket & get_socket() {
return *m_socket;
}
@@ -113,7 +112,7 @@ public:
/**
* This is used internally.
*/
boost::asio::ip::tcp::socket& get_next_layer() {
lib::asio::ip::tcp::socket & get_next_layer() {
return *m_socket;
}
@@ -121,7 +120,7 @@ public:
/**
* This is used internally. It can also be used to set socket options, etc
*/
boost::asio::ip::tcp::socket& get_raw_socket() {
lib::asio::ip::tcp::socket & get_raw_socket() {
return *m_socket;
}
@@ -135,16 +134,16 @@ public:
*
* @return A string identifying the address of the remote endpoint
*/
std::string get_remote_endpoint(lib::error_code &ec) const {
std::string get_remote_endpoint(lib::error_code & ec) const {
std::stringstream s;
boost::system::error_code bec;
boost::asio::ip::tcp::endpoint ep = m_socket->remote_endpoint(bec);
lib::asio::error_code aec;
lib::asio::ip::tcp::endpoint ep = m_socket->remote_endpoint(aec);
if (bec) {
if (aec) {
ec = error::make_error_code(error::pass_through);
s << "Error getting remote endpoint: " << bec
<< " (" << bec.message() << ")";
s << "Error getting remote endpoint: " << aec
<< " (" << aec.message() << ")";
return s.str();
} else {
ec = lib::error_code();
@@ -156,7 +155,7 @@ protected:
/// Perform one time initializations
/**
* init_asio is called once immediately after construction to initialize
* boost::asio components to the io_service
* Asio components to the io_service
*
* @param service A pointer to the endpoint's io_service
* @param strand A shared pointer to the connection's asio strand
@@ -168,7 +167,7 @@ protected:
return socket::make_error_code(socket::error::invalid_state);
}
m_socket = lib::make_shared<boost::asio::ip::tcp::socket>(
m_socket = lib::make_shared<lib::asio::ip::tcp::socket>(
lib::ref(*service));
m_state = READY;
@@ -242,8 +241,8 @@ protected:
}
void async_shutdown(socket_shutdown_handler h) {
boost::system::error_code ec;
m_socket->shutdown(boost::asio::ip::tcp::socket::shutdown_both,ec);
lib::asio::error_code ec;
m_socket->shutdown(lib::asio::ip::tcp::socket::shutdown_both, ec);
h(ec);
}
@@ -263,7 +262,7 @@ protected:
* @param ec The error code to translate_ec
* @return The translated error code
*/
lib::error_code translate_ec(boost::system::error_code) {
lib::error_code translate_ec(lib::asio::error_code) {
// We don't know any more information about this error so pass through
return make_error_code(transport::error::pass_through);
}
+27 -32
View File
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2014, Peter Thorson. All rights reserved.
* Copyright (c) 2015, Peter Thorson. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
@@ -32,14 +32,12 @@
#include <websocketpp/uri.hpp>
#include <websocketpp/common/asio.hpp>
#include <websocketpp/common/asio_ssl.hpp>
#include <websocketpp/common/connection_hdl.hpp>
#include <websocketpp/common/functional.hpp>
#include <websocketpp/common/memory.hpp>
#include <boost/asio.hpp>
#include <boost/asio/ssl.hpp>
#include <boost/system/error_code.hpp>
#include <sstream>
#include <string>
@@ -51,16 +49,16 @@ namespace asio {
namespace tls_socket {
/// The signature of the socket_init_handler for this socket policy
typedef lib::function<void(connection_hdl,boost::asio::ssl::stream<
boost::asio::ip::tcp::socket>&)> socket_init_handler;
typedef lib::function<void(connection_hdl,lib::asio::ssl::stream<
lib::asio::ip::tcp::socket>&)> socket_init_handler;
/// The signature of the tls_init_handler for this socket policy
typedef lib::function<lib::shared_ptr<boost::asio::ssl::context>(connection_hdl)>
typedef lib::function<lib::shared_ptr<lib::asio::ssl::context>(connection_hdl)>
tls_init_handler;
/// TLS enabled Boost ASIO connection socket component
/**
* transport::asio::tls_socket::connection implements a secure connection socket
* component that uses Boost ASIO's ssl::stream to wrap an ip::tcp::socket.
* component that uses Asio's ssl::stream to wrap an ip::tcp::socket.
*/
class connection : public lib::enable_shared_from_this<connection> {
public:
@@ -70,17 +68,15 @@ public:
typedef lib::shared_ptr<type> ptr;
/// Type of the ASIO socket being used
typedef boost::asio::ssl::stream<boost::asio::ip::tcp::socket> socket_type;
typedef lib::asio::ssl::stream<lib::asio::ip::tcp::socket> socket_type;
/// Type of a shared pointer to the ASIO socket being used
typedef lib::shared_ptr<socket_type> socket_ptr;
/// Type of a pointer to the ASIO io_service being used
typedef boost::asio::io_service* io_service_ptr;
typedef lib::asio::io_service * io_service_ptr;
/// Type of a pointer to the ASIO io_service strand being used
typedef lib::shared_ptr<boost::asio::io_service::strand> strand_ptr;
typedef lib::shared_ptr<lib::asio::io_service::strand> strand_ptr;
/// Type of a shared pointer to the ASIO TLS context being used
typedef lib::shared_ptr<boost::asio::ssl::context> context_ptr;
typedef boost::system::error_code boost_error;
typedef lib::shared_ptr<lib::asio::ssl::context> context_ptr;
explicit connection() {
//std::cout << "transport::asio::tls_socket::connection constructor"
@@ -104,7 +100,7 @@ public:
/**
* This is used internally. It can also be used to set socket options, etc
*/
socket_type::lowest_layer_type& get_raw_socket() {
socket_type::lowest_layer_type & get_raw_socket() {
return m_socket->lowest_layer();
}
@@ -112,7 +108,7 @@ public:
/**
* This is used internally.
*/
socket_type::next_layer_type& get_next_layer() {
socket_type::next_layer_type & get_next_layer() {
return m_socket->next_layer();
}
@@ -120,7 +116,7 @@ public:
/**
* This is used internally.
*/
socket_type& get_socket() {
socket_type & get_socket() {
return *m_socket;
}
@@ -159,16 +155,16 @@ public:
*
* @return A string identifying the address of the remote endpoint
*/
std::string get_remote_endpoint(lib::error_code &ec) const {
std::string get_remote_endpoint(lib::error_code & ec) const {
std::stringstream s;
boost::system::error_code bec;
boost::asio::ip::tcp::endpoint ep = m_socket->lowest_layer().remote_endpoint(bec);
lib::asio::error_code aec;
lib::asio::ip::tcp::endpoint ep = m_socket->lowest_layer().remote_endpoint(aec);
if (bec) {
if (aec) {
ec = error::make_error_code(error::pass_through);
s << "Error getting remote endpoint: " << bec
<< " (" << bec.message() << ")";
s << "Error getting remote endpoint: " << aec
<< " (" << aec.message() << ")";
return s.str();
} else {
ec = lib::error_code();
@@ -180,7 +176,7 @@ protected:
/// Perform one time initializations
/**
* init_asio is called once immediately after construction to initialize
* boost::asio components to the io_service
* Asio components to the io_service
*
* @param service A pointer to the endpoint's io_service
* @param strand A pointer to the connection's strand
@@ -300,8 +296,7 @@ protected:
m_hdl = hdl;
}
void handle_init(init_handler callback,boost::system::error_code const & ec)
{
void handle_init(init_handler callback,lib::asio::error_code const & ec) {
if (ec) {
m_ec = socket::make_error_code(socket::error::tls_handshake_failed);
} else {
@@ -340,7 +335,7 @@ protected:
* @return The translated error code
*/
lib::error_code translate_ec(boost::system::error_code ec) {
if (ec.category() == boost::asio::error::get_ssl_category()) {
if (ec.category() == lib::asio::error::get_ssl_category()) {
if (ERR_GET_REASON(ec.value()) == SSL_R_SHORT_READ) {
return make_error_code(transport::error::tls_short_read);
} else {
@@ -357,9 +352,9 @@ protected:
private:
socket_type::handshake_type get_handshake_type() {
if (m_is_server) {
return boost::asio::ssl::stream_base::server;
return lib::asio::ssl::stream_base::server;
} else {
return boost::asio::ssl::stream_base::client;
return lib::asio::ssl::stream_base::client;
}
}
@@ -377,10 +372,10 @@ private:
tls_init_handler m_tls_init_handler;
};
/// TLS enabled Boost ASIO endpoint socket component
/// TLS enabled Asio endpoint socket component
/**
* transport::asio::tls_socket::endpoint implements a secure endpoint socket
* component that uses Boost ASIO's ssl::stream to wrap an ip::tcp::socket.
* component that uses Asio's ssl::stream to wrap an ip::tcp::socket.
*/
class endpoint {
public:
+2 -2
View File
@@ -42,7 +42,7 @@ namespace websocketpp {
/// Library major version number
static int const major_version = 0;
/// Library minor version number
static int const minor_version = 5;
static int const minor_version = 6;
/// Library patch version number
static int const patch_version = 0;
/// Library pre-release flag
@@ -53,7 +53,7 @@ static int const patch_version = 0;
static char const prerelease_flag[] = "dev";
/// Default user agent string
static char const user_agent[] = "WebSocket++/0.5.x-dev";
static char const user_agent[] = "WebSocket++/0.6.x-dev";
} // namespace websocketpp