From 34527fbbe4d36ffe1d324712a64806ec6afd1bfe Mon Sep 17 00:00:00 2001 From: Vinnie Falco Date: Wed, 21 Aug 2013 18:01:50 -0700 Subject: [PATCH] Add SocketWrapperStrand --- Builds/VisualStudio2012/beast.vcxproj | 1 + Builds/VisualStudio2012/beast.vcxproj.filters | 3 + modules/beast_asio/beast_asio.h | 9 +-- .../sockets/beast_StrandSocketWrapper.h | 68 +++++++++++++++++++ 4 files changed, 77 insertions(+), 4 deletions(-) create mode 100644 modules/beast_asio/sockets/beast_StrandSocketWrapper.h diff --git a/Builds/VisualStudio2012/beast.vcxproj b/Builds/VisualStudio2012/beast.vcxproj index c013d8f081..a58cfd9e21 100644 --- a/Builds/VisualStudio2012/beast.vcxproj +++ b/Builds/VisualStudio2012/beast.vcxproj @@ -89,6 +89,7 @@ + diff --git a/Builds/VisualStudio2012/beast.vcxproj.filters b/Builds/VisualStudio2012/beast.vcxproj.filters index 16c38df21f..14c8ad2a05 100644 --- a/Builds/VisualStudio2012/beast.vcxproj.filters +++ b/Builds/VisualStudio2012/beast.vcxproj.filters @@ -908,6 +908,9 @@ beast_core\memory + + beast_asio\sockets + diff --git a/modules/beast_asio/beast_asio.h b/modules/beast_asio/beast_asio.h index 0b67985bbd..47c41aa94a 100644 --- a/modules/beast_asio/beast_asio.h +++ b/modules/beast_asio/beast_asio.h @@ -74,13 +74,14 @@ namespace beast #include "basics/beast_FixedInputBuffer.h" #include "basics/beast_PeerRole.h" -#include "sockets/beast_SocketBase.h" -#include "sockets/beast_Socket.h" -#include "sockets/beast_SocketWrapper.h" + #include "sockets/beast_SocketBase.h" + #include "sockets/beast_Socket.h" + #include "sockets/beast_SocketWrapper.h" +#include "sockets/beast_StrandSocketWrapper.h" #include "sockets/beast_SslContext.h" #include "handshake/beast_InputParser.h" - #include "handshake/beast_HandshakeDetectLogic.h" + #include "handshake/beast_HandshakeDetectLogic.h" #include "handshake/beast_HandshakeDetectLogicPROXY.h" #include "handshake/beast_HandshakeDetectLogicSSL2.h" #include "handshake/beast_HandshakeDetectLogicSSL3.h" diff --git a/modules/beast_asio/sockets/beast_StrandSocketWrapper.h b/modules/beast_asio/sockets/beast_StrandSocketWrapper.h new file mode 100644 index 0000000000..d170db5a5f --- /dev/null +++ b/modules/beast_asio/sockets/beast_StrandSocketWrapper.h @@ -0,0 +1,68 @@ +//------------------------------------------------------------------------------ +/* + This file is part of Beast: https://github.com/vinniefalco/Beast + Copyright 2013, Vinnie Falco + + Permission to use, copy, modify, and/or distribute this software for any + purpose with or without fee is hereby granted, provided that the above + copyright notice and this permission notice appear in all copies. + + THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + ANY SPECIAL , DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. +*/ +//============================================================================== + +#ifndef BEAST_STRANDSOCKETWRAPPER_H_INCLUDED +#define BEAST_STRANDSOCKETWRAPPER_H_INCLUDED + +/** Wraps the async I/O of a SocketWrapper with an io_service::strand + To use this in a chain of wrappers, customize the Wrapper type. +*/ +template > +class StrandSocketWrapper + : public Base +{ +public: + template + StrandSocketWrapper (Arg& arg) + : Base (arg) + , m_strand (this->get_io_service ()) + { + } + + template + StrandSocketWrapper (Arg1& arg1, Arg2& arg2) + : Base (arg1, arg2) + , m_strand (this->get_io_service ()) + { + } + + //-------------------------------------------------------------------------- + // + // basic_stream_socket + // + + void async_read_some (MutableBuffers const& buffers, SharedHandlerPtr handler) + { + this->SocketWrapper ::async_read_some (buffers, + newReadHandler (m_strand.wrap (handler))); + } + + template + void async_write_some (ConstBuffers const& buffers, + BOOST_ASIO_MOVE_ARG(WriteHandler) handler) + { + this->SocketWrapper ::async_write_some (buffers, + newWriteHandler (m_strand.wrap (handler))); + } + +protected: + boost::asio::io_service::strand m_strand; +}; + +#endif