diff --git a/src/roles/client.hpp b/src/roles/client.hpp index 2448732126..651ce45dcf 100644 --- a/src/roles/client.hpp +++ b/src/roles/client.hpp @@ -30,6 +30,7 @@ #include "../endpoint.hpp" #include "../uri.hpp" +#include "../shared_const_buffer.hpp" #ifndef __STDC_LIMIT_MACROS #define __STDC_LIMIT_MACROS @@ -361,13 +362,18 @@ void client::connection::write_request() { m_request.replace_header("Sec-WebSocket-Key",m_handshake_key); m_request.replace_header("User Agent","WebSocket++/2011-12-06"); - std::string raw = m_request.raw(); + // TODO: generating this raw request involves way too much copying in cases + // without string/vector move semantics. + shared_const_buffer buffer(m_request.raw()); - m_endpoint.alog().at(log::alevel::DEBUG_HANDSHAKE) << raw << log::endl; + //std::string raw = m_request.raw(); + + //m_endpoint.alog().at(log::alevel::DEBUG_HANDSHAKE) << raw << log::endl; boost::asio::async_write( m_connection.get_socket(), - boost::asio::buffer(raw), + //boost::asio::buffer(raw), + buffer, boost::bind( &type::handle_write_request, m_connection.shared_from_this(), diff --git a/src/shared_const_buffer.hpp b/src/shared_const_buffer.hpp new file mode 100644 index 0000000000..e9d2568c48 --- /dev/null +++ b/src/shared_const_buffer.hpp @@ -0,0 +1,56 @@ +/* + * Copyright (c) 2011, 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 SHARED_CONST_BUFFER_HPP +#define SHARED_CONST_BUFFER_HPP + + +#include +#include + +#include +#include + +namespace websocketpp { + +class shared_const_buffer { +public: + explicit shared_const_buffer(const std::string &data) : m_data(new std::vector(data.begin(), data.end())), + m_buffer(boost::asio::buffer(*m_data)) {} +public: + typedef boost::asio::const_buffer value_type; + typedef const boost::asio::const_buffer *const_iterator; + const boost::asio::const_buffer *begin() const { return &m_buffer; } + const boost::asio::const_buffer *end() const { return &m_buffer + 1; } +private: + boost::shared_ptr< std::vector > m_data; + boost::asio::const_buffer m_buffer; +}; + +} // namespace websocketpp + +#endif // SHARED_CONST_BUFFER_HPP diff --git a/websocketpp.xcodeproj/project.pbxproj b/websocketpp.xcodeproj/project.pbxproj index 4b16ebd514..6519735211 100644 --- a/websocketpp.xcodeproj/project.pbxproj +++ b/websocketpp.xcodeproj/project.pbxproj @@ -229,6 +229,7 @@ B62A5A6F14774CD5005F9EB0 /* uri.hpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.h; name = uri.hpp; path = src/uri.hpp; sourceTree = ""; }; B62A5A7014774F08005F9EB0 /* md5.hpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.h; name = md5.hpp; path = src/md5/md5.hpp; sourceTree = ""; }; B62A5A71147759EA005F9EB0 /* common.hpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.h; name = common.hpp; path = src/common.hpp; sourceTree = ""; }; + B63E51A814C9A5790006BF9A /* shared_const_buffer.hpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.h; name = shared_const_buffer.hpp; path = src/shared_const_buffer.hpp; sourceTree = ""; }; B64E12D214BDE132006F20F0 /* logging.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = logging.cpp; sourceTree = ""; }; B64E12D314BDE132006F20F0 /* Makefile */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.make; path = Makefile; sourceTree = ""; }; B64E12D414BDE132006F20F0 /* parsing.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = parsing.cpp; sourceTree = ""; }; @@ -685,17 +686,18 @@ B62A5A6A147748B2005F9EB0 /* processors */, B62A5A71147759EA005F9EB0 /* common.hpp */, B62A5A511473EBB0005F9EB0 /* connection.hpp */, + B62A5A521473EBB0005F9EB0 /* endpoint.hpp */, + B6DF1C7B1434AB920029A1B1 /* network_utilities.hpp */, + B6DF1C791434AB740029A1B1 /* network_utilities.cpp */, + B63E51A814C9A5790006BF9A /* shared_const_buffer.hpp */, B62A5A6F14774CD5005F9EB0 /* uri.hpp */, B6727428148517180029CF3E /* uri.cpp */, - B62A5A521473EBB0005F9EB0 /* endpoint.hpp */, B6DF1C981434AC470029A1B1 /* websocket_frame.hpp */, B6DF1C9F1434AC470029A1B1 /* websocketpp.hpp */, B6FE8D1414686A6D00B32547 /* md5 */, B6DF1C8E1434AC3E0029A1B1 /* utf8_validator */, B6DF1C871434ABF30029A1B1 /* sha1 */, B6DF1C801434ABE20029A1B1 /* base64 */, - B6DF1C791434AB740029A1B1 /* network_utilities.cpp */, - B6DF1C7B1434AB920029A1B1 /* network_utilities.hpp */, ); name = src; sourceTree = "";