Compare commits

...

15 Commits

Author SHA1 Message Date
Peter Thorson e203dbed45 package for 0.3.0 release 2014-08-09 14:06:22 -05:00
Peter Thorson ad2932bbff Disable open timeout when duration is set to zero 2014-07-24 21:39:12 -05:00
Peter Thorson 3560fa144a Merge pull request #359 from redboltz/add_semicolon
Added a semicolon.
2014-07-08 18:56:42 -05:00
Takatoshi Kondo 296f61b595 Added a semicolon. 2014-07-08 17:15:19 +09:00
Peter Thorson 65cc3765a8 add docs for namespaces and concurrency policies 2014-05-30 16:02:07 -05:00
Peter Thorson 10be5eee14 clarified documentation for bad_connection error 2014-05-30 16:02:07 -05:00
Peter Thorson c39777e4c1 add documentation for socket policies 2014-05-30 16:02:06 -05:00
Peter Thorson af7149ae0a Adds read_all method to iostream transport
Adds `connection::read_all(...)` method to iostream transport as a
convenience method for reading all data into the connection buffer
without the end user needing to manually loop on `read_some`.
2014-05-22 21:10:58 -05:00
Peter Thorson 7c3eb3e6c2 fix log wording 2014-05-22 21:10:57 -05:00
Peter Thorson e7ce038207 remove unused file 2014-04-10 10:53:41 -05:00
Peter Thorson aaed2c4950 fix whitespace 2014-04-10 10:20:26 -05:00
Peter Thorson 64fffeda9f Add combination plain+TLS echo example 2014-04-10 10:19:30 -05:00
Peter Thorson 7137105a81 documentation updates 2014-04-02 11:57:04 -05:00
Peter Thorson beaa6e98cc testee server defaults changes 2014-03-27 07:43:36 -05:00
Peter Thorson 79c2d09200 remove debug logging from critical paths 2014-03-27 07:43:11 -05:00
30 changed files with 413 additions and 102 deletions
+1 -1
View File
@@ -33,7 +33,7 @@ PROJECT_NAME = "websocketpp"
# if some version control system is used.
PROJECT_NUMBER = "0.3.0-alpha4"
PROJECT_NUMBER = "0.3.0"
# Using the PROJECT_BRIEF tag one can provide an optional one line description
+1
View File
@@ -214,6 +214,7 @@ echo_server = SConscript('#/examples/echo_server/SConscript',variant_dir = build
# echo_server_tls
if tls_build:
echo_server_tls = SConscript('#/examples/echo_server_tls/SConscript',variant_dir = builddir + 'echo_server_tls',duplicate = 0)
echo_server_both = SConscript('#/examples/echo_server_both/SConscript',variant_dir = builddir + 'echo_server_both',duplicate = 0)
# broadcast_server
broadcast_server = SConscript('#/examples/broadcast_server/SConscript',variant_dir = builddir + 'broadcast_server',duplicate = 0)
+5
View File
@@ -1,4 +1,6 @@
HEAD
0.3.0 - 2014-08-10
- Feature: Adds `start_perpetual` and `stop_perpetual` methods to asio transport
These may be used to replace manually managed `asio::io_service::work` objects
- Feature: Allow setting pong and handshake timeouts at runtime.
@@ -17,6 +19,9 @@ HEAD
- Feature: Adds the ability to specify a maximum message size.
- Feature: Adds `close::status::get_string(...)` method to look up a human
readable string given a close code value.
- Feature: Adds `connection::read_all(...)` method to iostream transport as a
convenience method for reading all data into the connection buffer without the
end user needing to manually loop on `read_some`.
- Improvement: Open, close, and pong timeouts can be disabled entirely by
setting their duration to 0.
- Improvement: Numerous performance improvements. Including: tuned default
+15
View File
@@ -0,0 +1,15 @@
file (GLOB SOURCE_FILES *.cpp)
file (GLOB HEADER_FILES *.hpp)
if (OPENSSL_FOUND)
init_target (echo_server_both)
build_executable (${TARGET_NAME} ${SOURCE_FILES} ${HEADER_FILES})
link_boost ()
link_openssl()
final_target ()
endif()
+24
View File
@@ -0,0 +1,24 @@
## Combo plain+tls echo server
##
Import('env')
Import('env_cpp11')
Import('boostlibs')
Import('platform_libs')
Import('polyfill_libs')
Import('tls_libs')
env = env.Clone ()
env_cpp11 = env_cpp11.Clone ()
prgs = []
# if a C++11 environment is available build using that, otherwise use boost
if env_cpp11.has_key('WSPP_CPP11_ENABLED'):
ALL_LIBS = boostlibs(['system'],env_cpp11) + [platform_libs] + [polyfill_libs] + [tls_libs]
prgs += env_cpp11.Program('echo_server_both', ["echo_server_both.cpp"], LIBS = ALL_LIBS)
else:
ALL_LIBS = boostlibs(['system'],env) + [platform_libs] + [polyfill_libs] + [tls_libs]
prgs += env.Program('echo_server_both', ["echo_server_both.cpp"], LIBS = ALL_LIBS)
Return('prgs')
@@ -0,0 +1,86 @@
#include <websocketpp/config/asio.hpp>
#include <websocketpp/server.hpp>
#include <iostream>
// define types for two different server endpoints, one for each config we are
// using
typedef websocketpp::server<websocketpp::config::asio> server_plain;
typedef websocketpp::server<websocketpp::config::asio_tls> server_tls;
// alias some of the bind related functions as they are a bit long
using websocketpp::lib::placeholders::_1;
using websocketpp::lib::placeholders::_2;
using websocketpp::lib::bind;
// type of the ssl context pointer is long so alias it
typedef websocketpp::lib::shared_ptr<boost::asio::ssl::context> context_ptr;
// The shared on_message handler takes a template parameter so the function can
// resolve any endpoint dependent types like message_ptr or connection_ptr
template <typename EndpointType>
void on_message(EndpointType* s, websocketpp::connection_hdl hdl,
typename EndpointType::message_ptr msg)
{
std::cout << "on_message called with hdl: " << hdl.lock().get()
<< " and message: " << msg->get_payload()
<< std::endl;
try {
s->send(hdl, msg->get_payload(), msg->get_opcode());
} catch (const websocketpp::lib::error_code& e) {
std::cout << "Echo failed because: " << e
<< "(" << e.message() << ")" << std::endl;
}
}
// No change to TLS init methods from echo_server_tls
std::string get_password() {
return "test";
}
context_ptr on_tls_init(websocketpp::connection_hdl hdl) {
std::cout << "on_tls_init called with hdl: " << hdl.lock().get() << std::endl;
context_ptr ctx(new boost::asio::ssl::context(boost::asio::ssl::context::tlsv1));
try {
ctx->set_options(boost::asio::ssl::context::default_workarounds |
boost::asio::ssl::context::no_sslv2 |
boost::asio::ssl::context::single_dh_use);
ctx->set_password_callback(bind(&get_password));
ctx->use_certificate_chain_file("server.pem");
ctx->use_private_key_file("server.pem", boost::asio::ssl::context::pem);
} catch (std::exception& e) {
std::cout << e.what() << std::endl;
}
return ctx;
}
int main() {
// set up an external io_service to run both endpoints on. This is not
// strictly necessary, but simplifies thread management a bit.
boost::asio::io_service ios;
// set up plain endpoint
server_plain endpoint_plain;
// initialize asio with our external io_service rather than an internal one
endpoint_plain.init_asio(&ios);
endpoint_plain.set_message_handler(
bind(&on_message<server_plain>,&endpoint_plain,::_1,::_2));
endpoint_plain.listen(80);
endpoint_plain.start_accept();
// set up tls endpoint
server_tls endpoint_tls;
endpoint_tls.init_asio(&ios);
endpoint_tls.set_message_handler(
bind(&on_message<server_tls>,&endpoint_tls,::_1,::_2));
// TLS endpoint has an extra handler for the tls init
endpoint_tls.set_tls_init_handler(bind(&on_tls_init,::_1));
// tls endpoint listens on a different port
endpoint_tls.listen(443);
endpoint_tls.start_accept();
// Start the ASIO io_service run loop running both endpoints
ios.run();
}
+58
View File
@@ -0,0 +1,58 @@
-----BEGIN RSA PRIVATE KEY-----
Proc-Type: 4,ENCRYPTED
DEK-Info: DES-EDE3-CBC,A0ED66EF872A48A9
gXuvKojXzApVhhPVNdRliiajbC4PtwQG5c8TA7JADLgwOR7o9t6KtXEr37bDRpvB
9aO9P+SJaK5OOp3XKPGthOdqv+tvCRTlmzmC8GjPLBX389DWT2xoGu7JkGwDtdSm
rnF49Rlp5bfjpACk5xKNiKeDo1CWfeEJzw9Kto0g+5eMaEdors64oPzjXs3geA2g
TxCJSHv9qSX6++pCLKKCUTbyzidAxV/Zb0AAubt5V40QKqX4HhSwwstFnTaX3tlb
3QOdY+y04VIkM6d7qN5W8M7NzRkMpZ1qBpQcUMpkhQcRzWP2wub5AAff9D2GntRd
4Dz1vn3u41U3Okdr0CNj+iH7byCzuokoAhk6ZQEN6WB+GTpGgfBXdtUZrfpb0MKm
UNYP5AF2AmUqJRXhViTDVtu/V2tHF3LGuNT+W2Dz+spFZEq0byEO0N858eR0dikc
6jOASvNQbSwD0+mkgBC1gXKKU3ngj2gpJUwljeACdWFd8N2egrZfyI05CmX7vPNC
NXbs7k2buWNdjP4/D8IM+HDVidWzQa/kG/qokXKqllem9Egg37lUucwnP3cX2/Hw
U2mfaBWzeZtqc+GqRp08rYIql+Reai3sUYlQMnNk01prVY47UQb+dxuqjaxGV5Xx
Xkx0s2mfQnNRjL4S7Hjhqelufi6GpkCQ2EGsPpA+6K1ztZ0ame9Q2BE1SXeM/6vU
rxT5nRrCxueyXAyQSGcqMX9//gSe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ZXJAemFwaG95ZC5jb22CCQDOTLiiXs16tDAMBgNVHRMEBTADAQH/
MA0GCSqGSIb3DQEBBQUAA4IBAQB+SH0s/hrv5VYqgX6SNLzxdSLvCVsUkCdTpxwY
wOJ84XmYcXDMhKDtZqLtOtN6pfEwVusFlC9mkieuunztCnWNmsSG83RuljJPjFSi
1d4Id4bKEQkQ4cfnjoHKivRrViWLnxuNnLzC6tpyGH/35kKWhhr6T58AXerFgVw3
mHvLPTr1DuhdAZA0ZuvuseVAFFAjI3RetSySwHJE3ak8KswDVfLi6E3XxMVsIWTS
/iFsC2WwoZQlljya2V/kRYIhu+uCdqJ01wunn2BvmURPSgr4GTBF0FQ9JGpNbXxM
TAU7oQJgyFc5sCcuEgPTO0dWVQTvdZVgay4tkmduKDRkmJBF
-----END CERTIFICATE-----
@@ -1,37 +0,0 @@
/*
* Copyright (c) 2012, 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_ECHO_SERVER_HANDLER_HPP
#define WEBSOCKETPP_ECHO_SERVER_HANDLER_HPP
class echo_handler : public server::handler {
void on_message(connection_ptr con, std::string msg) {
con->write(msg);
}
};
#endif // WEBSOCKETPP_ECHO_SERVER_HANDLER_HPP
+3 -2
View File
@@ -45,7 +45,7 @@ struct testee_config : public websocketpp::config::asio {
typedef core::rng_type rng_type;
typedef core::endpoint_base endpoint_base;
static bool const enable_multithreading = false;
static bool const enable_multithreading = true;
struct transport_config : public core::transport_config {
typedef core::concurrency_type concurrency_type;
@@ -54,7 +54,7 @@ struct testee_config : public websocketpp::config::asio {
typedef core::request_type request_type;
typedef core::response_type response_type;
static bool const enable_multithreading = false;
static bool const enable_multithreading = true;
};
typedef websocketpp::transport::asio::endpoint<transport_config>
@@ -104,6 +104,7 @@ int main(int argc, char * argv[]) {
// Initialize ASIO
testee_server.init_asio();
testee_server.set_reuse_addr(true);
// Register our message handler
testee_server.set_message_handler(bind(&on_message,&testee_server,::_1,::_2));
+1 -1
View File
@@ -1,4 +1,4 @@
WebSocket++ (0.3.0-alpha4)
WebSocket++ (0.3.0)
==========================
WebSocket++ is a header only C++ library that implements RFC6455 The WebSocket
+76
View File
@@ -63,6 +63,7 @@ struct stub_con : public iostream_con {
// Set the error to a known code that is unused by the library
// This way we can easily confirm that the handler was run at all.
, ec(websocketpp::error::make_error_code(websocketpp::error::test))
, indef_read_total(0)
{}
/// Get a shared pointer to this component
@@ -111,7 +112,41 @@ struct stub_con : public iostream_con {
ec = e;
}
void async_read_indef(size_t num_bytes, char *buf, size_t len)
{
indef_read_size = num_bytes;
indef_read_buf = buf;
indef_read_len = len;
indef_read();
}
void indef_read() {
iostream_con::async_read_at_least(
indef_read_size,
indef_read_buf,
indef_read_len,
websocketpp::lib::bind(
&stub_con::handle_indef,
type::get_shared(),
websocketpp::lib::placeholders::_1,
websocketpp::lib::placeholders::_2
)
);
}
void handle_indef(websocketpp::lib::error_code const & e, size_t read) {
ec = e;
indef_read_total += read;
indef_read();
}
websocketpp::lib::error_code ec;
size_t indef_read_size;
char * indef_read_buf;
size_t indef_read_len;
size_t indef_read_total;
};
// Stubs
@@ -314,6 +349,47 @@ BOOST_AUTO_TEST_CASE( async_read_at_least_read_some ) {
BOOST_CHECK_EQUAL( std::string(buf,10), "abcdefgxxx" );
}
BOOST_AUTO_TEST_CASE( async_read_at_least_read_some_indef ) {
stub_con::ptr con(new stub_con(true,alogger,elogger));
char buf[20];
memset(buf,'x',20);
con->async_read_indef(5,buf,5);
BOOST_CHECK( con->ec == make_error_code(websocketpp::error::test) );
// here we expect to return early from read some because the outstanding
// read was for 5 bytes and we were called with 10.
char input[11] = "aaaaabbbbb";
BOOST_CHECK_EQUAL(con->read_some(input,10), 5);
BOOST_CHECK( !con->ec );
BOOST_CHECK_EQUAL( std::string(buf,10), "aaaaaxxxxx" );
BOOST_CHECK_EQUAL( con->indef_read_total, 5 );
// A subsequent read should read 5 more because the indef read refreshes
// itself. The new read will start again at the beginning of the buffer.
BOOST_CHECK_EQUAL(con->read_some(input+5,5), 5);
BOOST_CHECK( !con->ec );
BOOST_CHECK_EQUAL( std::string(buf,10), "bbbbbxxxxx" );
BOOST_CHECK_EQUAL( con->indef_read_total, 10 );
}
BOOST_AUTO_TEST_CASE( async_read_at_least_read_all ) {
stub_con::ptr con(new stub_con(true,alogger,elogger));
char buf[20];
memset(buf,'x',20);
con->async_read_indef(5,buf,5);
BOOST_CHECK( con->ec == make_error_code(websocketpp::error::test) );
char input[11] = "aaaaabbbbb";
BOOST_CHECK_EQUAL(con->read_all(input,10), 10);
BOOST_CHECK( !con->ec );
BOOST_CHECK_EQUAL( std::string(buf,10), "bbbbbxxxxx" );
BOOST_CHECK_EQUAL( con->indef_read_total, 10 );
}
BOOST_AUTO_TEST_CASE( eof_flag ) {
stub_con::ptr con(new stub_con(true,alogger,elogger));
char buf[10];
+1 -1
View File
@@ -204,7 +204,7 @@ namespace status {
/**
* See https://tools.ietf.org/html/rfc6455#section-7.4 for more details.
*
* @since 0.4.0-beta1
* @since 0.3.0
*
* @param [in] code The code to look up.
* @return A human readable interpretation of the code.
+24 -2
View File
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2013, Peter Thorson. All rights reserved.
* Copyright (c) 2014, 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:
@@ -29,15 +29,20 @@
#define WEBSOCKETPP_CONCURRENCY_NONE_HPP
namespace websocketpp {
/// Concurrency handling support
namespace concurrency {
/// Implementation for no-op locking primitives
namespace none_impl {
/// A fake mutex implementation that does nothing
class fake_mutex {
public:
fake_mutex() {}
~fake_mutex() {}
};
/// A fake lock guard implementation that does nothing
class fake_lock_guard {
public:
explicit fake_lock_guard(fake_mutex foo) {}
@@ -45,10 +50,27 @@ public:
};
} // namespace none_impl
/// Stub Concurrency policy to remove locking in single threaded projects
/// Stub concurrency policy that implements the interface using no-ops.
/**
* This policy documents the concurrency policy interface using no-ops. It can
* be used as a reference or base for building a new concurrency policy. It can
* also be used as is to disable all locking for endpoints used in purely single
* threaded programs.
*/
class none {
public:
/// The type of a mutex primitive
/**
* std::mutex is an example.
*/
typedef none_impl::fake_mutex mutex_type;
/// The type of a scoped/RAII lock primitive.
/**
* The scoped lock constructor should take a mutex_type as a parameter,
* acquire that lock, and release it in its destructor. std::lock_guard is
* an example.
*/
typedef none_impl::fake_lock_guard scoped_lock_type;
};
+1 -1
View File
@@ -223,7 +223,7 @@ struct core {
*
* The default is 32MB
*
* @since 0.4.0-alpha1
* @since 0.3.0
*/
static const size_t max_message_size = 32000000;
+1 -1
View File
@@ -232,7 +232,7 @@ struct core_client {
*
* The default is 32MB
*
* @since 0.4.0-alpha1
* @since 0.3.0
*/
static const size_t max_message_size = 32000000;
+1 -1
View File
@@ -224,7 +224,7 @@ struct debug_core {
*
* The default is 32MB
*
* @since 0.4.0-alpha1
* @since 0.3.0
*/
static const size_t max_message_size = 32000000;
+2 -2
View File
@@ -538,7 +538,7 @@ public:
*
* The default is set by the endpoint that creates the connection.
*
* @since 0.4.0-alpha1
* @since 0.3.0
*/
size_t get_max_message_size() const {
return m_max_message_size;
@@ -552,7 +552,7 @@ public:
*
* The default is set by the endpoint that creates the connection.
*
* @since 0.4.0-alpha1
* @since 0.3.0
*
* @param new_value The value to set as the maximum message size.
*/
+2 -2
View File
@@ -357,7 +357,7 @@ public:
*
* The default is set by the max_message_size value from the template config
*
* @since 0.4.0-alpha1
* @since 0.3.0
*/
size_t get_max_message_size() const {
return m_max_message_size;
@@ -371,7 +371,7 @@ public:
*
* The default is set by the max_message_size value from the template config
*
* @since 0.4.0-alpha1
* @since 0.3.0
*
* @param new_value The value to set as the maximum message size.
*/
+5 -4
View File
@@ -38,7 +38,7 @@ namespace websocketpp {
/// Combination error code / string type for returning two values
typedef std::pair<lib::error_code,std::string> err_str_pair;
// setup for errors that should be propogated back to the user.
/// Library level error codes
namespace error {
enum value {
/// Catch-all library error
@@ -86,7 +86,8 @@ enum value {
/// Invalid subprotocol
invalid_subprotocol,
/// Bad or unknown connection
/// An operation was attempted on a connection that did not exist or was
/// already deleted.
bad_connection,
/// Unit testing utility error code
@@ -115,11 +116,11 @@ enum value {
/// Invalid port in URI
invalid_port,
/// An async accept operation failed because the underlying transport has been
/// requested to not listen for new connections anymore.
async_accept_not_listening,
/// The requested operation was canceled
operation_canceled
}; // enum value
+1
View File
@@ -33,6 +33,7 @@
#include <vector>
namespace websocketpp {
/// HTTP handling support
namespace http {
/// The type of an HTTP attribute list
/**
+25 -13
View File
@@ -95,7 +95,9 @@ lib::error_code connection<config>::send(const void* payload, size_t len,
template <typename config>
lib::error_code connection<config>::send(typename config::message_type::ptr msg)
{
m_alog.write(log::alevel::devel,"connection send");
if (m_alog.static_test(log::alevel::devel)) {
m_alog.write(log::alevel::devel,"connection send");
}
// TODO:
if (m_state != session::state::open) {
@@ -141,7 +143,9 @@ lib::error_code connection<config>::send(typename config::message_type::ptr msg)
template <typename config>
void connection<config>::ping(const std::string& payload, lib::error_code& ec) {
m_alog.write(log::alevel::devel,"connection ping");
if (m_alog.static_test(log::alevel::devel)) {
m_alog.write(log::alevel::devel,"connection ping");
}
if (m_state != session::state::open) {
ec = error::make_error_code(error::invalid_state);
@@ -230,7 +234,9 @@ void connection<config>::handle_pong_timeout(std::string payload, const lib::err
template <typename config>
void connection<config>::pong(const std::string& payload, lib::error_code& ec) {
m_alog.write(log::alevel::devel,"connection pong");
if (m_alog.static_test(log::alevel::devel)) {
m_alog.write(log::alevel::devel,"connection pong");
}
if (m_state != session::state::open) {
ec = error::make_error_code(error::invalid_state);
@@ -276,7 +282,9 @@ template <typename config>
void connection<config>::close(close::status::value const code,
std::string const & reason, lib::error_code & ec)
{
m_alog.write(log::alevel::devel,"connection close");
if (m_alog.static_test(log::alevel::devel)) {
m_alog.write(log::alevel::devel,"connection close");
}
if (m_state != session::state::open) {
ec = error::make_error_code(error::invalid_state);
@@ -957,7 +965,7 @@ void connection<config>::handle_read_frame(lib::error_code const & ec,
if (m_processor->ready()) {
if (m_alog.static_test(log::alevel::devel)) {
std::stringstream s;
s << "Complete frame received. Dispatching";
s << "Complete message received. Dispatching";
m_alog.write(log::alevel::devel,s.str());
}
@@ -2012,10 +2020,12 @@ void connection<config>::write_push(typename config::message_type::ptr msg)
m_send_buffer_size += msg->get_payload().size();
m_send_queue.push(msg);
std::stringstream s;
s << "write_push: message count: " << m_send_queue.size()
<< " buffer size: " << m_send_buffer_size;
m_alog.write(log::alevel::devel,s.str());
if (m_alog.static_test(log::alevel::devel)) {
std::stringstream s;
s << "write_push: message count: " << m_send_queue.size()
<< " buffer size: " << m_send_buffer_size;
m_alog.write(log::alevel::devel,s.str());
}
}
template <typename config>
@@ -2032,10 +2042,12 @@ typename config::message_type::ptr connection<config>::write_pop()
m_send_buffer_size -= msg->get_payload().size();
m_send_queue.pop();
std::stringstream s;
s << "write_pop: message count: " << m_send_queue.size()
<< " buffer size: " << m_send_buffer_size;
m_alog.write(log::alevel::devel,s.str());
if (m_alog.static_test(log::alevel::devel)) {
std::stringstream s;
s << "write_pop: message count: " << m_send_queue.size()
<< " buffer size: " << m_send_buffer_size;
m_alog.write(log::alevel::devel,s.str());
}
return msg;
}
+2 -2
View File
@@ -177,7 +177,7 @@ public:
*
* The default is retrieved from the max_message_size value from the template config
*
* @since 0.4.0-alpha1
* @since 0.3.0
*/
size_t get_max_message_size() const {
return m_max_message_size;
@@ -190,7 +190,7 @@ public:
*
* The default is retrieved from the max_message_size value from the template config
*
* @since 0.4.0-alpha1
* @since 0.3.0
*
* @param new_value The value to set as the maximum message size.
*/
+1
View File
@@ -29,6 +29,7 @@
#define WEBSOCKETPP_RANDOM_NONE_HPP
namespace websocketpp {
/// Random number generation policies
namespace random {
/// Stub RNG policy that always returns 0
namespace none {
+19 -14
View File
@@ -116,7 +116,7 @@ public:
* established but before any additional wrappers (proxy connects, TLS
* handshakes, etc) have been performed.
*
* @since 0.4.0-alpha1
* @since 0.3.0
*
* @param h The handler to call on tcp pre init.
*/
@@ -145,7 +145,7 @@ public:
* etc have been performed. This is fired before any bytes are read or any
* WebSocket specific handshake logic has been performed.
*
* @since 0.4.0-alpha1
* @since 0.3.0
*
* @param h The handler to call on tcp post init.
*/
@@ -477,16 +477,19 @@ protected:
}
timer_ptr post_timer;
post_timer = set_timer(
config::timeout_socket_post_init,
lib::bind(
&type::handle_post_init_timeout,
get_shared(),
post_timer,
m_init_handler,
lib::placeholders::_1
)
);
if (config::timeout_socket_post_init > 0) {
post_timer = set_timer(
config::timeout_socket_post_init,
lib::bind(
&type::handle_post_init_timeout,
get_shared(),
post_timer,
m_init_handler,
lib::placeholders::_1
)
);
}
socket_con_type::post_init(
lib::bind(
@@ -530,13 +533,15 @@ protected:
lib::error_code const & ec)
{
if (ec == transport::error::operation_aborted ||
post_timer->expires_from_now().is_negative())
(post_timer && post_timer->expires_from_now().is_negative()))
{
m_alog.write(log::alevel::devel,"post_init cancelled");
return;
}
post_timer->cancel();
if (post_timer) {
post_timer->cancel();
}
if (m_alog.static_test(log::alevel::devel)) {
m_alog.write(log::alevel::devel,"asio connection handle_post_init");
+7 -7
View File
@@ -138,7 +138,7 @@ public:
m_io_service = rhs.m_io_service;
m_external_io_service = rhs.m_external_io_service;
m_acceptor = rhs.m_acceptor;
m_listen_backlog = rhs.m_listen_backlog
m_listen_backlog = rhs.m_listen_backlog;
m_reuse_addr = rhs.m_reuse_addr;
m_state = rhs.m_state;
@@ -231,7 +231,7 @@ public:
* established but before any additional wrappers (proxy connects, TLS
* handshakes, etc) have been performed.
*
* @since 0.4.0-alpha1
* @since 0.3.0
*
* @param h The handler to call on tcp pre init.
*/
@@ -260,7 +260,7 @@ public:
* etc have been performed. This is fired before any bytes are read or any
* WebSocket specific handshake logic has been performed.
*
* @since 0.4.0-alpha1
* @since 0.3.0
*
* @param h The handler to call on tcp post init.
*/
@@ -283,7 +283,7 @@ public:
* A value of zero will use the operating system default. This is the
* default value.
*
* @since 0.4.0-alpha1
* @since 0.3.0
*
* @param backlog The maximum length of the queue of pending connections
*/
@@ -301,7 +301,7 @@ public:
*
* The default is false.
*
* @since 0.4.0-alpha1
* @since 0.3.0
*
* @param value Whether or not to use the SO_REUSEADDR option
*/
@@ -604,7 +604,7 @@ public:
* called either before the endpoint has run out of work or before it was
* started
*
* @since 0.4.0-alpha1
* @since 0.3.0
*/
void start_perpetual() {
m_work.reset(new boost::asio::io_service::work(*m_io_service));
@@ -616,7 +616,7 @@ public:
* method to exit normally when it runs out of connections. If there are
* currently active connections it will not end until they are complete.
*
* @since 0.4.0-alpha1
* @since 0.3.0
*/
void stop_perpetual() {
m_work.reset();
+8 -3
View File
@@ -39,8 +39,11 @@
namespace websocketpp {
namespace transport {
namespace asio {
/// A socket policy for the asio transport that implements a plain, unencrypted
/// socket
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&)>
socket_init_handler;
@@ -60,8 +63,10 @@ public:
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 the ASIO socket being used
typedef boost::asio::ip::tcp::socket socket_type;
/// Type of a shared pointer to the socket being used.
typedef lib::shared_ptr<boost::asio::ip::tcp::socket> socket_ptr;
typedef lib::shared_ptr<socket_type> socket_ptr;
explicit connection() : m_state(UNINITIALIZED) {
//std::cout << "transport::asio::basic_socket::connection constructor"
@@ -229,7 +234,7 @@ protected:
lib::error_code get_ec() const {
return lib::error_code();
}
/// Translate any security policy specific information about an error code
/**
* Translate_ec takes a boost error code and attempts to convert its value
@@ -237,7 +242,7 @@ protected:
* not presently provide any additional information so all errors will be
* reported as the generic transport pass_through error.
*
* @since 0.4.0-beta1
* @since 0.3.0
*
* @param ec The error code to translate_ec
* @return The translated error code
+5 -1
View File
@@ -43,10 +43,14 @@
namespace websocketpp {
namespace transport {
namespace asio {
/// A socket policy for the asio transport that implements a TLS encrypted
/// socket by wrapping with an asio::ssl::stream
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;
/// The signature of the tls_init_handler for this socket policy
typedef lib::function<lib::shared_ptr<boost::asio::ssl::context>(connection_hdl)>
tls_init_handler;
@@ -294,7 +298,7 @@ protected:
* Non-TLS related errors are returned as the transport generic pass_through
* error.
*
* @since 0.4.0-beta1
* @since 0.3.0
*
* @param ec The error code to translate_ec
* @return The translated error code
+3 -2
View File
@@ -141,6 +141,7 @@ struct buffer {
size_t len;
};
/// Generic transport related errors
namespace error {
enum value {
/// Catch-all error for transport policy errors that don't fit in other
@@ -170,10 +171,10 @@ enum value {
/// Timer expired
timeout,
/// read or write after shutdown
action_after_shutdown,
/// Other TLS error
tls_error,
};
+33 -3
View File
@@ -128,14 +128,13 @@ public:
return in;
}
/// Manual input supply
/// Manual input supply (read some)
/**
* Copies bytes from buf into WebSocket++'s input buffers. Bytes will be
* copied from the supplied buffer to fulfill any pending library reads. It
* will return the number of bytes successfully processed. If there are no
* pending reads read_some will return immediately. Not all of the bytes may
* be able to be read in one call
*
* be able to be read in one call.
*
* @since 0.3.0-alpha4
*
@@ -149,6 +148,37 @@ public:
return this->read_some_impl(buf,len);
}
/// Manual input supply (read all)
/**
* Similar to read_some, but continues to read until all bytes in the
* supplied buffer have been read or the connection runs out of read
* requests.
*
* This method still may not read all of the bytes in the input buffer. if
* it doesn't it indicates that the connection was most likely closed or
* is in an error state where it is no longer accepting new input.
*
* @since 0.3.0
*
* @param buf Char buffer to read into the websocket
* @param len Length of buf
* @return The number of characters from buf actually read.
*/
size_t read_all(char const * buf, size_t len) {
// this serializes calls to external read.
scoped_lock_type lock(m_read_mutex);
size_t total_read = 0;
size_t read = 0;
do {
read = this->read_some_impl(buf+total_read,len-total_read);
total_read += read;
} while (read != 0 && total_read < len);
return total_read;
}
/// Manual input supply (DEPRECATED)
/**
+2 -2
View File
@@ -50,10 +50,10 @@ static int const patch_version = 0;
* This is a textual flag indicating the type and number for pre-release
* versions (dev, alpha, beta, rc). This will be blank for release versions.
*/
static char const prerelease_flag[] = "alpha4";
static char const prerelease_flag[] = "";
/// Default user agent string
static char const user_agent[] = "WebSocket++/0.3.0-alpha4";
static char const user_agent[] = "WebSocket++/0.3.0";
} // namespace websocketpp