Compare commits
200
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
bded14b635 | ||
|
|
002d2d0007 | ||
|
|
d8b7cf3fdc | ||
|
|
b358e2cfe8 | ||
|
|
099fdbd4f1 | ||
|
|
19a3713b29 | ||
|
|
cd534ad18e | ||
|
|
e2b7a4b9f1 | ||
|
|
e154d955ec | ||
|
|
2207348abb | ||
|
|
77495d4076 | ||
|
|
8752687bc8 | ||
|
|
0f3a36a630 | ||
|
|
edb26d7721 | ||
|
|
b2d698d3ca | ||
|
|
9d8eced9a1 | ||
|
|
fd0c62a8e4 | ||
|
|
1a68f4b907 | ||
|
|
c3dfb25181 | ||
|
|
5a5d8321bd | ||
|
|
b805689f9c | ||
|
|
7eedf25500 | ||
|
|
3ca53d0064 | ||
|
|
5e2fadd826 | ||
|
|
840bb6b59e | ||
|
|
fe00a84f7b | ||
|
|
337bf2fb0a | ||
|
|
c5b5492e5c | ||
|
|
af15537205 | ||
|
|
bdeb4ad680 | ||
|
|
faad2ec854 | ||
|
|
dc06049df9 | ||
|
|
3e53c74c3f | ||
|
|
a5a30e554e | ||
|
|
9c8762c961 | ||
|
|
797ce35c5a | ||
|
|
30da3a967b | ||
|
|
e1547bbde8 | ||
|
|
37f69cc19b | ||
|
|
93d9b5f820 | ||
|
|
98fd183210 | ||
|
|
093806f860 | ||
|
|
1da45144e9 | ||
|
|
5f56976290 | ||
|
|
40ed74a141 | ||
|
|
fbc9db2b5d | ||
|
|
f87c9d4360 | ||
|
|
99461184d3 | ||
|
|
9eff0db756 | ||
|
|
86325b1838 | ||
|
|
2d2312a1d7 | ||
|
|
afc28be004 | ||
|
|
b7c5a2e791 | ||
|
|
d36925ce7d | ||
|
|
92dfe9ef97 | ||
|
|
2ab02197fd | ||
|
|
89ac45e60a | ||
|
|
713a05679c | ||
|
|
0fecf023ef | ||
|
|
ffdf5f842b | ||
|
|
d425caea80 | ||
|
|
ce2c1d6e34 | ||
|
|
7ceeaa4f9c | ||
|
|
883410bb77 | ||
|
|
724974c758 | ||
|
|
1622cdde04 | ||
|
|
180543b9e6 | ||
|
|
7c08cae15b | ||
|
|
81e0c44b34 | ||
|
|
722a67a910 | ||
|
|
ba6320ba1c | ||
|
|
d9aa498310 | ||
|
|
47c46a2fbc | ||
|
|
9401cf00ce | ||
|
|
acedd4db49 | ||
|
|
91617150e1 | ||
|
|
c7463afb06 | ||
|
|
ba90910f6e | ||
|
|
bee2c03aa0 | ||
|
|
8e86ddcf5a | ||
|
|
fe85de763e | ||
|
|
ca97dd1fb8 | ||
|
|
c7ec97795a | ||
|
|
6ee7c368bb | ||
|
|
2000746be7 | ||
|
|
c84cc110aa | ||
|
|
09940a5c0b | ||
|
|
bb21e3cf95 | ||
|
|
5f3b92c9e4 | ||
|
|
14074666a7 | ||
|
|
bb431ee0d2 | ||
|
|
373f180638 | ||
|
|
021ac0599c | ||
|
|
e44463583b | ||
|
|
4393a2562b | ||
|
|
780f7683a4 | ||
|
|
8f359e6d35 | ||
|
|
ebb65c81e2 | ||
|
|
c7fda5a960 | ||
|
|
6d4514246f | ||
|
|
c2f2cb951b | ||
|
|
827f3678bb | ||
|
|
57cd0e286e | ||
|
|
87cb5036a4 | ||
|
|
f05f18b384 | ||
|
|
01963a23ea | ||
|
|
18036d2b01 | ||
|
|
17bd89bd80 | ||
|
|
f59f301b91 | ||
|
|
319507f4af | ||
|
|
06cdf43dcf | ||
|
|
f8f945433f | ||
|
|
a4f96cf0c3 | ||
|
|
7032e6940f | ||
|
|
bfd50e1ee1 | ||
|
|
415533f7e7 | ||
|
|
b87bfc068e | ||
|
|
dbb5f963c8 | ||
|
|
a1872c3790 | ||
|
|
8993b34b3d | ||
|
|
7ae83b9efd | ||
|
|
430c49d394 | ||
|
|
3e5404e1b1 | ||
|
|
8524a1a272 | ||
|
|
6f79894ea5 | ||
|
|
5e803b57f7 | ||
|
|
6a3e886f0b | ||
|
|
ac9351f9b3 | ||
|
|
00b5bed0d1 | ||
|
|
0f6e93a13e | ||
|
|
84efd0425a | ||
|
|
f4d3640870 | ||
|
|
6680606523 | ||
|
|
962a090300 | ||
|
|
4d51d990a4 | ||
|
|
362f828767 | ||
|
|
aa74d2b295 | ||
|
|
746389efab | ||
|
|
5894601291 | ||
|
|
17c9831449 | ||
|
|
45a612f44b | ||
|
|
2e3dfe7935 | ||
|
|
1b453e4679 | ||
|
|
72a3bd6e4e | ||
|
|
e73f4cdb10 | ||
|
|
86fe22334c | ||
|
|
71e6babd93 | ||
|
|
8b9fa5db72 | ||
|
|
57d8e5cb6b | ||
|
|
1e97f6c67c | ||
|
|
5c14c8e71e | ||
|
|
933533c623 | ||
|
|
4231edec53 | ||
|
|
4761938600 | ||
|
|
bf5f2852f9 | ||
|
|
e16972b153 | ||
|
|
3d0d28affc | ||
|
|
63cdaec0ba | ||
|
|
43a258efaa | ||
|
|
3d57d412f7 | ||
|
|
97e5e5fc7b | ||
|
|
ed39a6ab1a | ||
|
|
67804061ea | ||
|
|
b934e71ace | ||
|
|
96f7d0f3f2 | ||
|
|
013c2da7e8 | ||
|
|
aebdb26dc6 | ||
|
|
550365df6a | ||
|
|
e91d6f6a45 | ||
|
|
de6d15c9fc | ||
|
|
3035c8dc0a | ||
|
|
c175ec4f42 | ||
|
|
e6319f51a4 | ||
|
|
d17569fa87 | ||
|
|
f22c542a0d | ||
|
|
e9cb0b840f | ||
|
|
bd9c9767e1 | ||
|
|
80133d6d55 | ||
|
|
ac41f467ed | ||
|
|
cab72215aa | ||
|
|
12d240ff09 | ||
|
|
107d3c9bb6 | ||
|
|
49c07296dd | ||
|
|
8475f5f200 | ||
|
|
8ef8372af1 | ||
|
|
4a10d8ddfd | ||
|
|
f02c6f1c75 | ||
|
|
eb9ab6f70f | ||
|
|
a2d92c9a21 | ||
|
|
6e23a6ec3c | ||
|
|
c30d000359 | ||
|
|
ffe59ab078 | ||
|
|
e457467e9b | ||
|
|
485304b438 | ||
|
|
3bab403c1b | ||
|
|
c017331959 | ||
|
|
df828914c7 | ||
|
|
2c879ee797 | ||
|
|
241cf697f6 | ||
|
|
c6f579a52a |
No files matched your search
+2
-2
@@ -1,7 +1,7 @@
|
||||
# Lineendings
|
||||
*.sln eol=crlf
|
||||
*.vcproj eol=crlf
|
||||
*.vcxproj* eol=crfl
|
||||
*.vcxproj* eol=crlf
|
||||
|
||||
# Whitespace rules
|
||||
# strict (no trailing, no tabs)
|
||||
@@ -15,4 +15,4 @@
|
||||
*.txt whitespace=trailing-space,space-before-tab,cr-at-eol
|
||||
|
||||
# special files which must ignore whitespace
|
||||
*.patch whitespace=-trailing-space
|
||||
*.patch whitespace=-trailing-space
|
||||
+5
-6
@@ -92,7 +92,7 @@ if (BUILD_TESTS OR BUILD_EXAMPLES)
|
||||
|
||||
# Visual studio
|
||||
if (MSVC)
|
||||
set (WEBSOCKETPP_BOOST_LIBS system thread regex)
|
||||
set (WEBSOCKETPP_BOOST_LIBS system thread)
|
||||
set (CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} /GL /Gy /GF /Ox /Ob2 /Ot /Oi /MP /arch:SSE2 /fp:fast")
|
||||
set (CMAKE_SHARED_LINKER_FLAGS_RELEASE "${CMAKE_SHARED_LINKER_FLAGS_RELEASE} /LTCG /INCREMENTAL:NO /OPT:REF /OPT:ICF")
|
||||
add_definitions (/W3 /wd4996 /wd4995 /wd4355)
|
||||
@@ -105,7 +105,7 @@ if (BUILD_TESTS OR BUILD_EXAMPLES)
|
||||
if (CMAKE_COMPILER_IS_GNUCXX)
|
||||
set (WEBSOCKETPP_PLATFORM_LIBS pthread rt)
|
||||
set (WEBSOCKETPP_PLATFORM_TSL_LIBS ssl crypto)
|
||||
set (WEBSOCKETPP_BOOST_LIBS system thread regex)
|
||||
set (WEBSOCKETPP_BOOST_LIBS system thread)
|
||||
set (CMAKE_CXX_FLAGS ${CMAKE_CXX_FLAGS} "-std=c++0x")
|
||||
if (NOT APPLE)
|
||||
add_definitions (-DNDEBUG -Wall -Wcast-align) # todo: should we use CMAKE_C_FLAGS for these?
|
||||
@@ -115,8 +115,7 @@ if (BUILD_TESTS OR BUILD_EXAMPLES)
|
||||
execute_process (COMMAND ${CMAKE_CXX_COMPILER} "-dumpversion" OUTPUT_VARIABLE GCC_VERSION)
|
||||
if ("${GCC_VERSION}" STRGREATER "4.4.0")
|
||||
message("* C++11 support partially enabled due to GCC version ${GCC_VERSION}")
|
||||
set (WEBSOCKETPP_BOOST_LIBS system thread regex)
|
||||
add_definitions (-D_WEBSOCKETPP_NO_CPP11_REGEX_)
|
||||
set (WEBSOCKETPP_BOOST_LIBS system thread)
|
||||
endif ()
|
||||
endif ()
|
||||
|
||||
@@ -128,7 +127,7 @@ if (BUILD_TESTS OR BUILD_EXAMPLES)
|
||||
set (WEBSOCKETPP_PLATFORM_LIBS pthread)
|
||||
endif()
|
||||
set (WEBSOCKETPP_PLATFORM_TSL_LIBS ssl crypto)
|
||||
set (WEBSOCKETPP_BOOST_LIBS system thread regex)
|
||||
set (WEBSOCKETPP_BOOST_LIBS system thread)
|
||||
set (CMAKE_CXX_FLAGS ${CMAKE_CXX_FLAGS} "-std=c++0x -stdlib=libc++") # todo: is libc++ really needed here?
|
||||
if (NOT APPLE)
|
||||
add_definitions (-DNDEBUG -Wall -Wno-padded) # todo: should we use CMAKE_C_FLAGS for these?
|
||||
@@ -204,7 +203,7 @@ if (BUILD_TESTS OR BUILD_EXAMPLES)
|
||||
else ()
|
||||
message (FATAL_ERROR "Failed to find required dependency: boost")
|
||||
endif ()
|
||||
|
||||
|
||||
find_package(OpenSSL)
|
||||
endif()
|
||||
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
Main Library:
|
||||
|
||||
Copyright (c) 2013, Peter Thorson. All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
@@ -11,13 +13,133 @@ modification, are permitted provided that the following conditions are met:
|
||||
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
|
||||
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.
|
||||
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
Bundled Libraries:
|
||||
|
||||
****** Base 64 Library (base64/base64.hpp) ******
|
||||
base64.hpp is a repackaging of the base64.cpp and base64.h files into a
|
||||
single header suitable for use as a header only library. This conversion was
|
||||
done by Peter Thorson (webmaster@zaphoyd.com) in 2012. All modifications to
|
||||
the code are redistributed under the same license as the original, which is
|
||||
listed below.
|
||||
|
||||
base64.cpp and base64.h
|
||||
|
||||
Copyright (C) 2004-2008 René Nyffenegger
|
||||
|
||||
This source code is provided 'as-is', without any express or implied
|
||||
warranty. In no event will the author be held liable for any damages
|
||||
arising from the use of this software.
|
||||
|
||||
Permission is granted to anyone to use this software for any purpose,
|
||||
including commercial applications, and to alter it and redistribute it
|
||||
freely, subject to the following restrictions:
|
||||
|
||||
1. The origin of this source code must not be misrepresented; you must not
|
||||
claim that you wrote the original source code. If you use this source code
|
||||
in a product, an acknowledgment in the product documentation would be
|
||||
appreciated but is not required.
|
||||
|
||||
2. Altered source versions must be plainly marked as such, and must not be
|
||||
misrepresented as being the original source code.
|
||||
|
||||
3. This notice may not be removed or altered from any source distribution.
|
||||
|
||||
René Nyffenegger rene.nyffenegger@adp-gmbh.ch
|
||||
|
||||
****** SHA1 Library (sha1/sha1.hpp) ******
|
||||
sha1.hpp is a repackaging of the sha1.cpp and sha1.h files from the shallsha1
|
||||
library (http://code.google.com/p/smallsha1/) into a single header suitable for
|
||||
use as a header only library. This conversion was done by Peter Thorson
|
||||
(webmaster@zaphoyd.com) in 2013. All modifications to the code are redistributed
|
||||
under the same license as the original, which is listed below.
|
||||
|
||||
Copyright (c) 2011, Micael Hildenborg
|
||||
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 Micael Hildenborg 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 Micael Hildenborg ''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 Micael Hildenborg 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.
|
||||
|
||||
****** MD5 Library (common/md5.hpp) ******
|
||||
md5.hpp is a reformulation of the md5.h and md5.c code from
|
||||
http://www.opensource.apple.com/source/cups/cups-59/cups/md5.c to allow it to
|
||||
function as a component of a header only library. This conversion was done by
|
||||
Peter Thorson (webmaster@zaphoyd.com) in 2012 for the WebSocket++ project. The
|
||||
changes are released under the same license as the original (listed below)
|
||||
|
||||
Copyright (C) 1999, 2002 Aladdin Enterprises. All rights reserved.
|
||||
|
||||
This software is provided 'as-is', without any express or implied
|
||||
warranty. In no event will the authors be held liable for any damages
|
||||
arising from the use of this software.
|
||||
|
||||
Permission is granted to anyone to use this software for any purpose,
|
||||
including commercial applications, and to alter it and redistribute it
|
||||
freely, subject to the following restrictions:
|
||||
|
||||
1. The origin of this software must not be misrepresented; you must not
|
||||
claim that you wrote the original software. If you use this software
|
||||
in a product, an acknowledgment in the product documentation would be
|
||||
appreciated but is not required.
|
||||
2. Altered source versions must be plainly marked as such, and must not be
|
||||
misrepresented as being the original software.
|
||||
3. This notice may not be removed or altered from any source distribution.
|
||||
|
||||
L. Peter Deutsch
|
||||
ghost@aladdin.com
|
||||
|
||||
****** UTF8 Validation logic (utf8_validation.hpp) ******
|
||||
utf8_validation.hpp is adapted from code originally written by Bjoern Hoehrmann
|
||||
<bjoern@hoehrmann.de>. See http://bjoern.hoehrmann.de/utf-8/decoder/dfa/ for
|
||||
details.
|
||||
|
||||
The original license:
|
||||
|
||||
Copyright (c) 2008-2009 Bjoern Hoehrmann <bjoern@hoehrmann.de>
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
@@ -33,7 +33,7 @@ PROJECT_NAME = "websocketpp"
|
||||
# if some version control system is used.
|
||||
|
||||
|
||||
PROJECT_NUMBER = "0.3.0-alpha3"
|
||||
PROJECT_NUMBER = "0.3.0-alpha4"
|
||||
|
||||
|
||||
# Using the PROJECT_BRIEF tag one can provide an optional one line description
|
||||
|
||||
+13
-2
@@ -79,6 +79,8 @@ elif env['PLATFORM'] == 'posix':
|
||||
env.Append(CCFLAGS = ['-Wall'])
|
||||
#env['LINKFLAGS'] = ''
|
||||
elif env['PLATFORM'] == 'darwin':
|
||||
if not os.environ.has_key('CXX'):
|
||||
env['CXX'] = "clang++"
|
||||
if env.has_key('DEBUG'):
|
||||
env.Append(CCFLAGS = ['-g', '-O0'])
|
||||
else:
|
||||
@@ -98,11 +100,13 @@ else:
|
||||
if env['CXX'].startswith('g++'):
|
||||
#env.Append(CCFLAGS = ['-Wconversion'])
|
||||
env.Append(CCFLAGS = ['-Wcast-align'])
|
||||
env.Append(CCFLAGS = ['-Wshadow'])
|
||||
elif env['CXX'].startswith('clang++'):
|
||||
#env.Append(CCFLAGS = ['-Wcast-align'])
|
||||
#env.Append(CCFLAGS = ['-Wglobal-constructors'])
|
||||
#env.Append(CCFLAGS = ['-Wconversion'])
|
||||
env.Append(CCFLAGS = ['-Wno-padded'])
|
||||
env.Append(CCFLAGS = ['-Wshadow'])
|
||||
|
||||
# Wpadded
|
||||
# Wsign-conversion
|
||||
@@ -142,6 +146,7 @@ if env_cpp11['CXX'].startswith('g++'):
|
||||
print "C++11 build environment is not supported on this version of G++"
|
||||
elif env_cpp11['CXX'].startswith('clang++'):
|
||||
print "C++11 build environment enabled"
|
||||
env.Append(CXXFLANGS = ['-stdlib=libc++'],LINKFLAGS=['-stdlib=libc++'])
|
||||
env_cpp11.Append(WSPP_CPP11_ENABLED = "true",CXXFLAGS = ['-std=c++0x','-stdlib=libc++'],LINKFLAGS = ['-stdlib=libc++'],TOOLSET = ['clang++'],CPPDEFINES = ['_WEBSOCKETPP_CPP11_STL_'])
|
||||
|
||||
# look for optional second boostroot compiled with clang's libc++ STL library
|
||||
@@ -157,7 +162,7 @@ else:
|
||||
print "C++11 build environment disabled"
|
||||
|
||||
# if the build system is known to allow the isystem modifier for library include
|
||||
# values then use it for the boost libraries. Otherwise just add them to the
|
||||
# values then use it for the boost libraries. Otherwise just add them to the
|
||||
# regular CPPPATH values.
|
||||
if env['CXX'].startswith('g++') or env['CXX'].startswith('clang'):
|
||||
env.Append(CPPFLAGS = '-isystem ' + env['BOOST_INCLUDES'])
|
||||
@@ -166,7 +171,7 @@ else:
|
||||
env.Append(LIBPATH = [env['BOOST_LIBS']])
|
||||
|
||||
# if the build system is known to allow the isystem modifier for library include
|
||||
# values then use it for the boost libraries. Otherwise just add them to the
|
||||
# values then use it for the boost libraries. Otherwise just add them to the
|
||||
# regular CPPPATH values.
|
||||
if env_cpp11['CXX'].startswith('g++') or env_cpp11['CXX'].startswith('clang'):
|
||||
env_cpp11.Append(CPPFLAGS = '-isystem ' + env_cpp11['BOOST_INCLUDES'])
|
||||
@@ -222,6 +227,12 @@ testee_client = SConscript('#/examples/testee_client/SConscript',variant_dir = b
|
||||
# utility_client
|
||||
utility_client = SConscript('#/examples/utility_client/SConscript',variant_dir = builddir + 'utility_client',duplicate = 0)
|
||||
|
||||
# debug_client
|
||||
debug_client = SConscript('#/examples/debug_client/SConscript',variant_dir = builddir + 'debug_client',duplicate = 0)
|
||||
|
||||
# debug_server
|
||||
debug_server = SConscript('#/examples/debug_server/SConscript',variant_dir = builddir + 'debug_server',duplicate = 0)
|
||||
|
||||
# subprotocol_server
|
||||
subprotocol_server = SConscript('#/examples/subprotocol_server/SConscript',variant_dir = builddir + 'subprotocol_server',duplicate = 0)
|
||||
|
||||
|
||||
+99
-2
@@ -1,4 +1,101 @@
|
||||
HEAD
|
||||
- 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.
|
||||
- Feature: Allows changing the listen backlog queue length.
|
||||
- Feature: Split tcp init into pre and post init.
|
||||
- Feature: Adds URI method to extract query string from URI. Thank you Banaan
|
||||
for code. #298
|
||||
- Feature: Adds a compile time switch to asio transport config to disable
|
||||
certain multithreading features (some locks, asio strands)
|
||||
- Feature: Adds the ability to pause reading on a connection. Paused connections
|
||||
will not read more data from their socket, allowing TCP flow control to work
|
||||
without blocking the main thread.
|
||||
- Feature: Adds the ability to specify whether or not to use the `SO_REUSEADDR`
|
||||
TCP socket option. The default for this value has been changed from `true` to
|
||||
`false`.
|
||||
- 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.
|
||||
- Improvement: Open, close, and pong timeouts can be disabled entirely by
|
||||
setting their duration to 0.
|
||||
- Improvement: Numerous performance improvements. Including: tuned default
|
||||
buffer sizes based on profiling, caching of handler binding for async
|
||||
reads/writes, non-malloc allocators for read/write handlers, disabling of a
|
||||
number of questionably useful range sanity checks in tight inner loops.
|
||||
- Improvement: Cleaned up the handling of TLS related errors. TLS errors will
|
||||
now be reported with more detail on the info channel rather than all being
|
||||
`tls_short_read` or `pass_through`. In addition, many cases where a TLS short
|
||||
read was in fact expected are no longer classified as errors. Expected TLS
|
||||
short reads and quasi-expected socket shutdown related errors will no longer
|
||||
be reported as unclean WebSocket shutdowns to the application. Information
|
||||
about them will remain in the info error channel for debugging purposes.
|
||||
- Improvement: `start_accept` and `listen` errors are now reported to the caller
|
||||
either via an exception or an ec parameter.
|
||||
- Improvement: Outgoing writes are now batched for improved message throughput
|
||||
and reduced system call and TCP frame overhead.
|
||||
- Bug: Fix some cases of calls to empty lib::function objects.
|
||||
- Bug: Fix memory leak of connection objects due to cached handlers holding on to
|
||||
reference counted pointers. #310 Thank you otaras for reporting.
|
||||
- Bug: Fix issue with const endpoint accessors (such as `get_user_agent`) not
|
||||
compiling due to non-const mutex use. #292 Thank you logofive for reporting.
|
||||
- Bug: Fix handler allocation crash with multithreaded `io_service`.
|
||||
- Bug: Fixes incorrect whitespace handling in header parsing. #301 Thank you
|
||||
Wolfram Schroers for reporting
|
||||
- Bug: Fix a crash when parsing empty HTTP headers. Thank you Thingol for
|
||||
reporting.
|
||||
- Bug: Fix a crash following use of the `stop_listening` function. Thank you
|
||||
Thingol for reporting.
|
||||
- Bug: Fix use of variable names that shadow function parameters. The library
|
||||
should compile cleanly with -Wshadow now. Thank you giszo for reporting. #318
|
||||
- Bug: Fix an issue where `set_open_handshake_timeout` was ignored by server
|
||||
code. Thank you Robin Rowe for reporting.
|
||||
- Bug: Fix an issue where custom timeout values weren't being propagated from
|
||||
endpoints to new connections.
|
||||
- Bug: Fix a number of memory leaks related to server connection failures. #323
|
||||
#333 #334 #335 Thank you droppy and aydany for reporting and patches.
|
||||
reporting.
|
||||
- Compatibility: Fix compile time conflict with Visual Studio's MIN/MAX macros.
|
||||
Thank you Robin Rowe for reporting.
|
||||
- Documentation: Examples and test suite build system now defaults to clang on
|
||||
OS X
|
||||
|
||||
0.3.0-alpha4 - 2013-10-11
|
||||
- HTTP requests ending normally are no longer logged as errors. Thank you Banaan
|
||||
for reporting. #294
|
||||
- Eliminates spurious expired timers in certain error conditions. Thank you
|
||||
Banaan for reporting. #295
|
||||
- Consolidates all bundled library licenses into the COPYING file. #294
|
||||
- Updates bundled sha1 library to one with a cleaner interface and more
|
||||
straight-forward license. Thank you lotodore for reporting and Evgeni Golov
|
||||
for reviewing. #294
|
||||
- Re-introduces strands to asio transport, allowing `io_service` thread pools to
|
||||
be used (with some limitations).
|
||||
- Removes endpoint code that kept track of a connection list that was never used
|
||||
anywhere. Removes a lock and reduces connection creation/deletion complexity
|
||||
from O(log n) to O(1) in the number of connections.
|
||||
- A number of internal changes to transport APIs
|
||||
- Deprecates iostream transport `readsome` in favor of `read_some` which is more
|
||||
consistent with the naming of the rest of the library.
|
||||
- Adds preliminary signaling to iostream transport of eof and fatal transport
|
||||
errors
|
||||
- Updates transport code to use shared pointers rather than raw pointers to
|
||||
prevent asio from retaining pointers to connection methods after the
|
||||
connection goes out of scope. #293 Thank you otaras for reporting.
|
||||
- Fixes an issue where custom headers couldn't be set for client connections
|
||||
Thank you Jerry Win and Wolfram Schroers for reporting.
|
||||
- Fixes a compile error on visual studio when using interrupts. Thank you Javier
|
||||
Rey Neira for reporting this.
|
||||
- Adds new 1012 and 1013 close codes per IANA registry
|
||||
- Add `set_remote_endpoint` method to iostream transport.
|
||||
- Add `set_secure` method to iostream transport.
|
||||
- Fix typo in .gitattributes file. Thank you jstarasov for reporting this. #280
|
||||
- Add missing locale include. Thank you Toninoso for reporting this. #281
|
||||
- Refactors `asio_transport` endpoint and adds full documentation and exception
|
||||
free varients of all methods.
|
||||
- Removes `asio_transport` endpoint method cancel(). Use `stop_listen()` instead
|
||||
- Wrap internal `io_service` `run_one()` method
|
||||
- Suppress error when trying to shut down a connection that was already closed
|
||||
|
||||
0.3.0-alpha3 - 2013-07-16
|
||||
- Minor refactor to bundled sha1 library
|
||||
@@ -9,7 +106,7 @@ HEAD
|
||||
binary sizes.
|
||||
- Updates handling of Server and User-Agent headers to better handle custom
|
||||
settings and allow suppression of these headers for security purposes.
|
||||
- Fix issue where pong timeout handler always fired. Thank you Steven Klassen
|
||||
- Fix issue where pong timeout handler always fired. Thank you Steven Klassen
|
||||
for reporting this bug.
|
||||
- Add ping and pong endpoint wrapper methods
|
||||
- Add `get_request()` pass through method to connection to allow calling methods
|
||||
@@ -23,7 +120,7 @@ HEAD
|
||||
0.3.0-alpha2 - 2013-06-09
|
||||
- Fix a regression that caused servers being sent two close frames in a row
|
||||
to end a connection uncleanly. #259
|
||||
- Fix a regression that caused spurious frames following a legitimate close
|
||||
- Fix a regression that caused spurious frames following a legitimate close
|
||||
frames to erroneously trigger handlers. #258
|
||||
- Change default HTTP response error code when no http_handler is defined from
|
||||
500/Internal Server Error to 426/Upgrade Required
|
||||
|
||||
@@ -20,55 +20,55 @@ class print_server {
|
||||
public:
|
||||
print_server() : m_next_sessionid(1) {
|
||||
m_server.init_asio();
|
||||
|
||||
|
||||
m_server.set_open_handler(bind(&print_server::on_open,this,::_1));
|
||||
m_server.set_close_handler(bind(&print_server::on_close,this,::_1));
|
||||
m_server.set_message_handler(bind(&print_server::on_message,this,::_1,::_2));
|
||||
}
|
||||
|
||||
|
||||
void on_open(connection_hdl hdl) {
|
||||
connection_data data;
|
||||
|
||||
|
||||
data.sessionid = m_next_sessionid++;
|
||||
data.name = "";
|
||||
|
||||
|
||||
m_connections[hdl] = data;
|
||||
}
|
||||
|
||||
|
||||
void on_close(connection_hdl hdl) {
|
||||
connection_data& data = get_data_from_hdl(hdl);
|
||||
|
||||
std::cout << "Closing connection " << data.name
|
||||
|
||||
std::cout << "Closing connection " << data.name
|
||||
<< " with sessionid " << data.sessionid << std::endl;
|
||||
|
||||
|
||||
m_connections.erase(hdl);
|
||||
}
|
||||
|
||||
|
||||
void on_message(connection_hdl hdl, server::message_ptr msg) {
|
||||
connection_data& data = get_data_from_hdl(hdl);
|
||||
|
||||
|
||||
if (data.name == "") {
|
||||
data.name = msg->get_payload();
|
||||
std::cout << "Setting name of connection with sessionid "
|
||||
std::cout << "Setting name of connection with sessionid "
|
||||
<< data.sessionid << " to " << data.name << std::endl;
|
||||
} else {
|
||||
std::cout << "Got a message from connection " << data.name
|
||||
std::cout << "Got a message from connection " << data.name
|
||||
<< " with sessionid " << data.sessionid << std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
connection_data& get_data_from_hdl(connection_hdl hdl) {
|
||||
auto it = m_connections.find(hdl);
|
||||
|
||||
|
||||
if (it == m_connections.end()) {
|
||||
// this connection is not in the list. This really shouldn't happen
|
||||
// and probably means something else is wrong.
|
||||
throw std::invalid_argument("No data available for session");
|
||||
}
|
||||
|
||||
|
||||
return it->second;
|
||||
}
|
||||
|
||||
|
||||
void run(uint16_t port) {
|
||||
m_server.listen(port);
|
||||
m_server.start_accept();
|
||||
@@ -85,4 +85,4 @@ private:
|
||||
int main() {
|
||||
print_server server;
|
||||
server.run(9002);
|
||||
}
|
||||
}
|
||||
@@ -34,32 +34,33 @@ enum action_type {
|
||||
|
||||
struct action {
|
||||
action(action_type t, connection_hdl h) : type(t), hdl(h) {}
|
||||
action(action_type t, server::message_ptr m) : type(t), msg(m) {}
|
||||
|
||||
action(action_type t, connection_hdl h, server::message_ptr m)
|
||||
: type(t), hdl(h), msg(m) {}
|
||||
|
||||
action_type type;
|
||||
websocketpp::connection_hdl hdl;
|
||||
server::message_ptr msg;
|
||||
};
|
||||
|
||||
|
||||
class broadcast_server {
|
||||
public:
|
||||
broadcast_server() {
|
||||
// Initialize Asio Transport
|
||||
m_server.init_asio();
|
||||
|
||||
|
||||
// Register handler callbacks
|
||||
m_server.set_open_handler(bind(&broadcast_server::on_open,this,::_1));
|
||||
m_server.set_close_handler(bind(&broadcast_server::on_close,this,::_1));
|
||||
m_server.set_message_handler(bind(&broadcast_server::on_message,this,::_1,::_2));
|
||||
}
|
||||
|
||||
|
||||
void run(uint16_t port) {
|
||||
// listen on specified port
|
||||
m_server.listen(port);
|
||||
|
||||
|
||||
// Start the server accept loop
|
||||
m_server.start_accept();
|
||||
|
||||
|
||||
// Start the ASIO io_service run loop
|
||||
try {
|
||||
m_server.run();
|
||||
@@ -71,7 +72,7 @@ public:
|
||||
std::cout << "other exception" << std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void on_open(connection_hdl hdl) {
|
||||
unique_lock<mutex> lock(m_action_lock);
|
||||
//std::cout << "on_open" << std::endl;
|
||||
@@ -79,7 +80,7 @@ public:
|
||||
lock.unlock();
|
||||
m_action_cond.notify_one();
|
||||
}
|
||||
|
||||
|
||||
void on_close(connection_hdl hdl) {
|
||||
unique_lock<mutex> lock(m_action_lock);
|
||||
//std::cout << "on_close" << std::endl;
|
||||
@@ -87,38 +88,38 @@ public:
|
||||
lock.unlock();
|
||||
m_action_cond.notify_one();
|
||||
}
|
||||
|
||||
|
||||
void on_message(connection_hdl hdl, server::message_ptr msg) {
|
||||
// queue message up for sending by processing thread
|
||||
unique_lock<mutex> lock(m_action_lock);
|
||||
//std::cout << "on_message" << std::endl;
|
||||
m_actions.push(action(MESSAGE,msg));
|
||||
m_actions.push(action(MESSAGE,hdl,msg));
|
||||
lock.unlock();
|
||||
m_action_cond.notify_one();
|
||||
}
|
||||
|
||||
|
||||
void process_messages() {
|
||||
while(1) {
|
||||
unique_lock<mutex> lock(m_action_lock);
|
||||
|
||||
|
||||
while(m_actions.empty()) {
|
||||
m_action_cond.wait(lock);
|
||||
}
|
||||
|
||||
|
||||
action a = m_actions.front();
|
||||
m_actions.pop();
|
||||
|
||||
|
||||
lock.unlock();
|
||||
|
||||
|
||||
if (a.type == SUBSCRIBE) {
|
||||
unique_lock<mutex> lock(m_connection_lock);
|
||||
unique_lock<mutex> con_lock(m_connection_lock);
|
||||
m_connections.insert(a.hdl);
|
||||
} else if (a.type == UNSUBSCRIBE) {
|
||||
unique_lock<mutex> lock(m_connection_lock);
|
||||
unique_lock<mutex> con_lock(m_connection_lock);
|
||||
m_connections.erase(a.hdl);
|
||||
} else if (a.type == MESSAGE) {
|
||||
unique_lock<mutex> lock(m_connection_lock);
|
||||
|
||||
unique_lock<mutex> con_lock(m_connection_lock);
|
||||
|
||||
con_list::iterator it;
|
||||
for (it = m_connections.begin(); it != m_connections.end(); ++it) {
|
||||
m_server.send(*it,a.msg);
|
||||
@@ -130,11 +131,11 @@ public:
|
||||
}
|
||||
private:
|
||||
typedef std::set<connection_hdl,std::owner_less<connection_hdl>> con_list;
|
||||
|
||||
|
||||
server m_server;
|
||||
con_list m_connections;
|
||||
std::queue<action> m_actions;
|
||||
|
||||
|
||||
mutex m_action_lock;
|
||||
mutex m_connection_lock;
|
||||
condition_variable m_action_cond;
|
||||
@@ -142,16 +143,16 @@ private:
|
||||
|
||||
int main() {
|
||||
try {
|
||||
broadcast_server server;
|
||||
|
||||
broadcast_server server_instance;
|
||||
|
||||
// Start a thread to run the processing loop
|
||||
thread t(bind(&broadcast_server::process_messages,&server));
|
||||
|
||||
thread t(bind(&broadcast_server::process_messages,&server_instance));
|
||||
|
||||
// Run the asio loop with the main thread
|
||||
server.run(9002);
|
||||
|
||||
server_instance.run(9002);
|
||||
|
||||
t.join();
|
||||
|
||||
|
||||
} catch (std::exception & e) {
|
||||
std::cout << e.what() << std::endl;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,24 @@
|
||||
## Debug client example
|
||||
##
|
||||
|
||||
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('debug_client', ["debug_client.cpp"], LIBS = ALL_LIBS)
|
||||
else:
|
||||
ALL_LIBS = boostlibs(['system','random'],env) + [platform_libs] + [polyfill_libs] + [tls_libs]
|
||||
prgs += env.Program('debug_client', ["debug_client.cpp"], LIBS = ALL_LIBS)
|
||||
|
||||
Return('prgs')
|
||||
@@ -0,0 +1,152 @@
|
||||
/*
|
||||
* 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:
|
||||
* * 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.
|
||||
*/
|
||||
|
||||
/** ====== WARNING ========
|
||||
* This example is presently used as a scratch space. It may or may not be broken
|
||||
* at any given time.
|
||||
*/
|
||||
|
||||
#include <websocketpp/config/asio_client.hpp>
|
||||
|
||||
#include <websocketpp/client.hpp>
|
||||
|
||||
#include <iostream>
|
||||
#include <chrono>
|
||||
|
||||
typedef websocketpp::client<websocketpp::config::asio_tls_client> client;
|
||||
|
||||
using websocketpp::lib::placeholders::_1;
|
||||
using websocketpp::lib::placeholders::_2;
|
||||
using websocketpp::lib::bind;
|
||||
|
||||
// pull out the type of messages sent by our config
|
||||
typedef websocketpp::config::asio_tls_client::message_type::ptr message_ptr;
|
||||
typedef websocketpp::lib::shared_ptr<boost::asio::ssl::context> context_ptr;
|
||||
typedef client::connection_ptr connection_ptr;
|
||||
|
||||
|
||||
|
||||
class perftest {
|
||||
public:
|
||||
typedef perftest type;
|
||||
typedef std::chrono::duration<int,std::micro> dur_type;
|
||||
|
||||
perftest () {
|
||||
m_endpoint.set_access_channels(websocketpp::log::alevel::all);
|
||||
m_endpoint.set_error_channels(websocketpp::log::elevel::all);
|
||||
|
||||
// Initialize ASIO
|
||||
m_endpoint.init_asio();
|
||||
|
||||
// Register our handlers
|
||||
m_endpoint.set_socket_init_handler(bind(&type::on_socket_init,this,::_1));
|
||||
m_endpoint.set_tls_init_handler(bind(&type::on_tls_init,this,::_1));
|
||||
m_endpoint.set_message_handler(bind(&type::on_message,this,::_1,::_2));
|
||||
m_endpoint.set_open_handler(bind(&type::on_open,this,::_1));
|
||||
m_endpoint.set_close_handler(bind(&type::on_close,this,::_1));
|
||||
}
|
||||
|
||||
void start(std::string uri) {
|
||||
websocketpp::lib::error_code ec;
|
||||
client::connection_ptr con = m_endpoint.get_connection(uri, ec);
|
||||
|
||||
if (ec) {
|
||||
m_endpoint.get_alog().write(websocketpp::log::alevel::app,ec.message());
|
||||
}
|
||||
|
||||
//con->set_proxy("http://humupdates.uchicago.edu:8443");
|
||||
|
||||
m_endpoint.connect(con);
|
||||
|
||||
// Start the ASIO io_service run loop
|
||||
m_start = std::chrono::high_resolution_clock::now();
|
||||
m_endpoint.run();
|
||||
}
|
||||
|
||||
void on_socket_init(websocketpp::connection_hdl hdl) {
|
||||
m_socket_init = std::chrono::high_resolution_clock::now();
|
||||
}
|
||||
|
||||
context_ptr on_tls_init(websocketpp::connection_hdl hdl) {
|
||||
m_tls_init = std::chrono::high_resolution_clock::now();
|
||||
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);
|
||||
} catch (std::exception& e) {
|
||||
std::cout << e.what() << std::endl;
|
||||
}
|
||||
return ctx;
|
||||
}
|
||||
|
||||
void on_open(websocketpp::connection_hdl hdl) {
|
||||
m_open = std::chrono::high_resolution_clock::now();
|
||||
m_endpoint.send(hdl, "", websocketpp::frame::opcode::text);
|
||||
}
|
||||
void on_message(websocketpp::connection_hdl hdl, message_ptr msg) {
|
||||
m_message = std::chrono::high_resolution_clock::now();
|
||||
m_endpoint.close(hdl,websocketpp::close::status::going_away,"");
|
||||
}
|
||||
void on_close(websocketpp::connection_hdl hdl) {
|
||||
m_close = std::chrono::high_resolution_clock::now();
|
||||
|
||||
std::cout << "Socket Init: " << std::chrono::duration_cast<dur_type>(m_socket_init-m_start).count() << std::endl;
|
||||
std::cout << "TLS Init: " << std::chrono::duration_cast<dur_type>(m_tls_init-m_start).count() << std::endl;
|
||||
std::cout << "Open: " << std::chrono::duration_cast<dur_type>(m_open-m_start).count() << std::endl;
|
||||
std::cout << "Message: " << std::chrono::duration_cast<dur_type>(m_message-m_start).count() << std::endl;
|
||||
std::cout << "Close: " << std::chrono::duration_cast<dur_type>(m_close-m_start).count() << std::endl;
|
||||
}
|
||||
private:
|
||||
client m_endpoint;
|
||||
|
||||
std::chrono::high_resolution_clock::time_point m_start;
|
||||
std::chrono::high_resolution_clock::time_point m_socket_init;
|
||||
std::chrono::high_resolution_clock::time_point m_tls_init;
|
||||
std::chrono::high_resolution_clock::time_point m_open;
|
||||
std::chrono::high_resolution_clock::time_point m_message;
|
||||
std::chrono::high_resolution_clock::time_point m_close;
|
||||
};
|
||||
|
||||
int main(int argc, char* argv[]) {
|
||||
std::string uri = "wss://echo.websocket.org";
|
||||
|
||||
if (argc == 2) {
|
||||
uri = argv[1];
|
||||
}
|
||||
|
||||
try {
|
||||
perftest endpoint;
|
||||
endpoint.start(uri);
|
||||
} catch (const std::exception & e) {
|
||||
std::cout << e.what() << std::endl;
|
||||
} catch (websocketpp::lib::error_code e) {
|
||||
std::cout << e.message() << std::endl;
|
||||
} catch (...) {
|
||||
std::cout << "other exception" << std::endl;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
|
||||
file (GLOB SOURCE_FILES *.cpp)
|
||||
file (GLOB HEADER_FILES *.hpp)
|
||||
|
||||
init_target (debug_server)
|
||||
|
||||
build_executable (${TARGET_NAME} ${SOURCE_FILES} ${HEADER_FILES})
|
||||
|
||||
link_boost ()
|
||||
final_target ()
|
||||
@@ -0,0 +1,23 @@
|
||||
## Debug server example
|
||||
##
|
||||
|
||||
Import('env')
|
||||
Import('env_cpp11')
|
||||
Import('boostlibs')
|
||||
Import('platform_libs')
|
||||
Import('polyfill_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]
|
||||
prgs += env_cpp11.Program('debug_server', ["debug_server.cpp"], LIBS = ALL_LIBS)
|
||||
else:
|
||||
ALL_LIBS = boostlibs(['system'],env) + [platform_libs] + [polyfill_libs]
|
||||
prgs += env.Program('debug_server', ["debug_server.cpp"], LIBS = ALL_LIBS)
|
||||
|
||||
Return('prgs')
|
||||
@@ -0,0 +1,92 @@
|
||||
/*
|
||||
* 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:
|
||||
* * 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.
|
||||
*/
|
||||
|
||||
/** ====== WARNING ========
|
||||
* This example is presently used as a scratch space. It may or may not be broken
|
||||
* at any given time.
|
||||
*/
|
||||
|
||||
#include <websocketpp/config/debug_asio_no_tls.hpp>
|
||||
|
||||
#include <websocketpp/server.hpp>
|
||||
|
||||
#include <iostream>
|
||||
|
||||
typedef websocketpp::server<websocketpp::config::debug_asio> server;
|
||||
|
||||
using websocketpp::lib::placeholders::_1;
|
||||
using websocketpp::lib::placeholders::_2;
|
||||
using websocketpp::lib::bind;
|
||||
|
||||
// pull out the type of messages sent by our config
|
||||
typedef server::message_ptr message_ptr;
|
||||
|
||||
// Define a callback to handle incoming messages
|
||||
void on_message(server* s, websocketpp::connection_hdl hdl, 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;
|
||||
}
|
||||
}
|
||||
|
||||
int main() {
|
||||
// Create a server endpoint
|
||||
server echo_server;
|
||||
|
||||
try {
|
||||
// Set logging settings
|
||||
echo_server.set_access_channels(websocketpp::log::alevel::all);
|
||||
echo_server.clear_access_channels(websocketpp::log::alevel::frame_payload);
|
||||
|
||||
// Initialize ASIO
|
||||
echo_server.init_asio();
|
||||
echo_server.set_reuse_addr(true);
|
||||
|
||||
// Register our message handler
|
||||
echo_server.set_message_handler(bind(&on_message,&echo_server,::_1,::_2));
|
||||
|
||||
// Listen on port 9012
|
||||
echo_server.listen(9012);
|
||||
|
||||
// Start the server accept loop
|
||||
echo_server.start_accept();
|
||||
|
||||
// Start the ASIO io_service run loop
|
||||
echo_server.run();
|
||||
} catch (const std::exception & e) {
|
||||
std::cout << e.what() << std::endl;
|
||||
} catch (websocketpp::lib::error_code e) {
|
||||
std::cout << e.message() << std::endl;
|
||||
} catch (...) {
|
||||
std::cout << "other exception" << std::endl;
|
||||
}
|
||||
}
|
||||
+50
-50
@@ -32,169 +32,169 @@ typedef websocketpp::server<websocketpp::config::core> server;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
void http(connection_ptr con) {
|
||||
std::cout << "handler http" << std::endl;
|
||||
}
|
||||
|
||||
|
||||
void on_load(connection_ptr con, ptr old_handler) {
|
||||
std::cout << "handler on_load" << std::endl;
|
||||
}
|
||||
void on_unload(connection_ptr con, ptr new_handler) {
|
||||
std::cout << "handler on_unload" << std::endl;
|
||||
}
|
||||
|
||||
|
||||
void on_open(connection_ptr con) {
|
||||
std::cout << "handler on_open" << std::endl;
|
||||
}
|
||||
void on_fail(connection_ptr con) {
|
||||
std::cout << "handler on_fail" << std::endl;
|
||||
}
|
||||
|
||||
|
||||
void on_message(connection_ptr con, message_ptr msg) {
|
||||
std::cout << "handler on_message" << std::endl;
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
void on_close(connection_ptr con) {
|
||||
std::cout << "handler on_close" << std::endl;
|
||||
}
|
||||
};*/
|
||||
|
||||
int main() {
|
||||
typedef websocketpp::message_buffer::message<websocketpp::message_buffer::alloc::con_msg_manager>
|
||||
typedef websocketpp::message_buffer::message<websocketpp::message_buffer::alloc::con_msg_manager>
|
||||
message_type;
|
||||
typedef websocketpp::message_buffer::alloc::con_msg_manager<message_type>
|
||||
typedef websocketpp::message_buffer::alloc::con_msg_manager<message_type>
|
||||
con_msg_man_type;
|
||||
|
||||
con_msg_man_type::ptr manager(new con_msg_man_type());
|
||||
|
||||
|
||||
size_t foo = 1024;
|
||||
|
||||
|
||||
message_type::ptr input = manager->get_message(websocketpp::frame::opcode::TEXT,foo);
|
||||
message_type::ptr output = manager->get_message(websocketpp::frame::opcode::TEXT,foo);
|
||||
websocketpp::frame::masking_key_type key;
|
||||
|
||||
|
||||
std::random_device dev;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
key.i = 0x12345678;
|
||||
|
||||
|
||||
double m = 18094238402394.0824923;
|
||||
|
||||
|
||||
/*std::cout << "Some Math" << std::endl;
|
||||
{
|
||||
boost::timer::auto_cpu_timer t;
|
||||
|
||||
|
||||
for (int i = 0; i < foo; i++) {
|
||||
m /= 1.001;
|
||||
}
|
||||
|
||||
|
||||
}*/
|
||||
|
||||
|
||||
std::cout << m << std::endl;
|
||||
|
||||
|
||||
std::cout << "Random Gen" << std::endl;
|
||||
{
|
||||
boost::timer::auto_cpu_timer t;
|
||||
|
||||
|
||||
input->get_raw_payload().replace(0,foo,foo,'\0');
|
||||
output->get_raw_payload().replace(0,foo,foo,'\0');
|
||||
}
|
||||
|
||||
|
||||
std::cout << "Out of place accelerated" << std::endl;
|
||||
{
|
||||
boost::timer::auto_cpu_timer t;
|
||||
|
||||
|
||||
websocketpp::frame::word_mask_exact(reinterpret_cast<uint8_t*>(const_cast<char*>(input->get_raw_payload().data())), reinterpret_cast<uint8_t*>(const_cast<char*>(output->get_raw_payload().data())), foo, key);
|
||||
}
|
||||
|
||||
|
||||
std::cout << websocketpp::utility::to_hex(input->get_payload().c_str(),20) << std::endl;
|
||||
std::cout << websocketpp::utility::to_hex(output->get_payload().c_str(),20) << std::endl;
|
||||
|
||||
|
||||
input->get_raw_payload().replace(0,foo,foo,'\0');
|
||||
output->get_raw_payload().replace(0,foo,foo,'\0');
|
||||
|
||||
|
||||
std::cout << "In place accelerated" << std::endl;
|
||||
{
|
||||
boost::timer::auto_cpu_timer t;
|
||||
|
||||
|
||||
websocketpp::frame::word_mask_exact(reinterpret_cast<uint8_t*>(const_cast<char*>(input->get_raw_payload().data())), reinterpret_cast<uint8_t*>(const_cast<char*>(input->get_raw_payload().data())), foo, key);
|
||||
}
|
||||
|
||||
|
||||
std::cout << websocketpp::utility::to_hex(input->get_payload().c_str(),20) << std::endl;
|
||||
std::cout << websocketpp::utility::to_hex(output->get_payload().c_str(),20) << std::endl;
|
||||
|
||||
|
||||
input->get_raw_payload().replace(0,foo,foo,'\0');
|
||||
output->get_raw_payload().replace(0,foo,foo,'\0');
|
||||
std::cout << "Out of place byte by byte" << std::endl;
|
||||
{
|
||||
boost::timer::auto_cpu_timer t;
|
||||
|
||||
|
||||
websocketpp::frame::byte_mask(input->get_raw_payload().begin(), input->get_raw_payload().end(), output->get_raw_payload().begin(), key);
|
||||
}
|
||||
|
||||
|
||||
std::cout << websocketpp::utility::to_hex(input->get_payload().c_str(),20) << std::endl;
|
||||
std::cout << websocketpp::utility::to_hex(output->get_payload().c_str(),20) << std::endl;
|
||||
|
||||
|
||||
input->get_raw_payload().replace(0,foo,foo,'\0');
|
||||
output->get_raw_payload().replace(0,foo,foo,'\0');
|
||||
std::cout << "In place byte by byte" << std::endl;
|
||||
{
|
||||
boost::timer::auto_cpu_timer t;
|
||||
|
||||
|
||||
websocketpp::frame::byte_mask(input->get_raw_payload().begin(), input->get_raw_payload().end(), input->get_raw_payload().begin(), key);
|
||||
}
|
||||
|
||||
|
||||
std::cout << websocketpp::utility::to_hex(input->get_payload().c_str(),20) << std::endl;
|
||||
std::cout << websocketpp::utility::to_hex(output->get_payload().c_str(),20) << std::endl;
|
||||
|
||||
|
||||
input->get_raw_payload().replace(0,foo,foo,'a');
|
||||
output->get_raw_payload().replace(0,foo,foo,'b');
|
||||
std::cout << "Copy" << std::endl;
|
||||
{
|
||||
boost::timer::auto_cpu_timer t;
|
||||
|
||||
|
||||
std::copy(input->get_raw_payload().begin(), input->get_raw_payload().end(), output->get_raw_payload().begin());
|
||||
}
|
||||
|
||||
|
||||
std::cout << websocketpp::utility::to_hex(input->get_payload().c_str(),20) << std::endl;
|
||||
std::cout << websocketpp::utility::to_hex(output->get_payload().c_str(),20) << std::endl;
|
||||
|
||||
|
||||
/*server::handler::ptr h(new handler());
|
||||
|
||||
|
||||
server test_server(h);
|
||||
server::connection_ptr con;
|
||||
|
||||
|
||||
std::stringstream output;
|
||||
|
||||
|
||||
test_server.register_ostream(&output);
|
||||
|
||||
|
||||
con = test_server.get_connection();
|
||||
|
||||
|
||||
con->start();
|
||||
|
||||
|
||||
//foo.handle_accept(con,true);
|
||||
|
||||
|
||||
std::stringstream input;
|
||||
input << "GET / HTTP/1.1\r\nHost: www.example.com\r\nConnection: upgrade\r\nUpgrade: websocket\r\nSec-WebSocket-Version: 13\r\nSec-WebSocket-Key: dGhlIHNhbXBsZSBub25jZQ==\r\nOrigin: http://www.example.com\r\n\r\n";
|
||||
//input << "GET / HTTP/1.1\r\nHost: www.example.com\r\n\r\n";
|
||||
input >> *con;
|
||||
|
||||
|
||||
std::stringstream input2;
|
||||
input2 << "messageabc2";
|
||||
input2 >> *con;
|
||||
|
||||
|
||||
std::stringstream input3;
|
||||
input3 << "messageabc3";
|
||||
input3 >> *con;
|
||||
|
||||
|
||||
std::stringstream input4;
|
||||
input4 << "close";
|
||||
input4 >> *con;
|
||||
|
||||
|
||||
std::cout << "connection output:" << std::endl;
|
||||
std::cout << output.str() << std::endl;*/
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
|
||||
|
||||
file (GLOB SOURCE_FILES *.cpp)
|
||||
file (GLOB HEADER_FILES *.hpp)
|
||||
|
||||
|
||||
@@ -11,10 +11,10 @@
|
||||
* * 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
|
||||
*
|
||||
* 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;
|
||||
@@ -22,7 +22,7 @@
|
||||
* 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
|
||||
|
||||
@@ -15,14 +15,14 @@ typedef server::message_ptr message_ptr;
|
||||
|
||||
// Define a callback to handle incoming messages
|
||||
void on_message(server* s, websocketpp::connection_hdl hdl, message_ptr msg) {
|
||||
std::cout << "on_message called with hdl: " << hdl.lock().get()
|
||||
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
|
||||
std::cout << "Echo failed because: " << e
|
||||
<< "(" << e.message() << ")" << std::endl;
|
||||
}
|
||||
}
|
||||
@@ -30,24 +30,24 @@ void on_message(server* s, websocketpp::connection_hdl hdl, message_ptr msg) {
|
||||
int main() {
|
||||
// Create a server endpoint
|
||||
server echo_server;
|
||||
|
||||
|
||||
try {
|
||||
// Set logging settings
|
||||
echo_server.set_access_channels(websocketpp::log::alevel::all);
|
||||
echo_server.clear_access_channels(websocketpp::log::alevel::frame_payload);
|
||||
|
||||
|
||||
// Initialize ASIO
|
||||
echo_server.init_asio();
|
||||
|
||||
|
||||
// Register our message handler
|
||||
echo_server.set_message_handler(bind(&on_message,&echo_server,::_1,::_2));
|
||||
|
||||
|
||||
// Listen on port 9002
|
||||
echo_server.listen(9002);
|
||||
|
||||
|
||||
// Start the server accept loop
|
||||
echo_server.start_accept();
|
||||
|
||||
|
||||
// Start the ASIO io_service run loop
|
||||
echo_server.run();
|
||||
} catch (const std::exception & e) {
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
|
||||
|
||||
file (GLOB SOURCE_FILES *.cpp)
|
||||
file (GLOB HEADER_FILES *.hpp)
|
||||
|
||||
|
||||
if (OPENSSL_FOUND)
|
||||
|
||||
|
||||
init_target (echo_server_tls)
|
||||
|
||||
build_executable (${TARGET_NAME} ${SOURCE_FILES} ${HEADER_FILES})
|
||||
@@ -12,4 +12,4 @@ build_executable (${TARGET_NAME} ${SOURCE_FILES} ${HEADER_FILES})
|
||||
link_boost ()
|
||||
link_openssl()
|
||||
final_target ()
|
||||
endif()
|
||||
endif()
|
||||
@@ -11,10 +11,10 @@
|
||||
* * 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
|
||||
*
|
||||
* 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;
|
||||
@@ -22,7 +22,7 @@
|
||||
* 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
|
||||
|
||||
@@ -15,14 +15,14 @@ typedef websocketpp::config::asio::message_type::ptr message_ptr;
|
||||
typedef websocketpp::lib::shared_ptr<boost::asio::ssl::context> context_ptr;
|
||||
|
||||
void on_message(server* s, websocketpp::connection_hdl hdl, message_ptr msg) {
|
||||
std::cout << "on_message called with hdl: " << hdl.lock().get()
|
||||
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
|
||||
std::cout << "Echo failed because: " << e
|
||||
<< "(" << e.message() << ")" << std::endl;
|
||||
}
|
||||
}
|
||||
@@ -51,7 +51,7 @@ context_ptr on_tls_init(websocketpp::connection_hdl hdl) {
|
||||
int main() {
|
||||
// Create a server endpoint
|
||||
server echo_server;
|
||||
|
||||
|
||||
// Initialize ASIO
|
||||
echo_server.init_asio();
|
||||
|
||||
@@ -59,10 +59,10 @@ int main() {
|
||||
echo_server.set_message_handler(bind(&on_message,&echo_server,::_1,::_2));
|
||||
echo_server.set_tls_init_handler(bind(&on_tls_init,::_1));
|
||||
|
||||
|
||||
|
||||
// Listen on port 9002
|
||||
echo_server.listen(9002);
|
||||
|
||||
|
||||
// Start the server accept loop
|
||||
echo_server.start_accept();
|
||||
|
||||
|
||||
@@ -17,12 +17,12 @@ void custom_on_msg(server & s, connection_hdl hdl, server::message_ptr msg) {
|
||||
|
||||
void default_on_msg(server & s, connection_hdl hdl, server::message_ptr msg) {
|
||||
std::cout << "Message sent to default handler" << std::endl;
|
||||
|
||||
|
||||
if (msg->get_payload() == "upgrade") {
|
||||
// Upgrade our connection_hdl to a full connection_ptr
|
||||
server::connection_ptr con = s.get_con_from_hdl(hdl);
|
||||
|
||||
// Change the on message handler for this connection only to
|
||||
|
||||
// Change the on message handler for this connection only to
|
||||
// custom_on_mesage
|
||||
con->set_message_handler(bind(&custom_on_msg,ref(s),::_1,::_2));
|
||||
std::cout << "Upgrading connection to custom handler" << std::endl;
|
||||
@@ -39,4 +39,4 @@ int main() {
|
||||
s.start_accept();
|
||||
|
||||
s.run();
|
||||
}
|
||||
}
|
||||
@@ -17,17 +17,17 @@ typedef server::message_ptr message_ptr;
|
||||
// Define a callback to handle incoming messages
|
||||
void on_message(server* s, websocketpp::connection_hdl hdl, message_ptr msg) {
|
||||
if (msg->get_opcode() == websocketpp::frame::opcode::text) {
|
||||
s->get_alog().write(websocketpp::log::alevel::app,
|
||||
s->get_alog().write(websocketpp::log::alevel::app,
|
||||
"Text Message Received: "+msg->get_payload());
|
||||
} else {
|
||||
s->get_alog().write(websocketpp::log::alevel::app,
|
||||
s->get_alog().write(websocketpp::log::alevel::app,
|
||||
"Binary Message Received: "+websocketpp::utility::to_hex(msg->get_payload()));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
try {
|
||||
s->send(hdl, msg->get_payload(), msg->get_opcode());
|
||||
} catch (const websocketpp::lib::error_code& e) {
|
||||
s->get_alog().write(websocketpp::log::alevel::app,
|
||||
s->get_alog().write(websocketpp::log::alevel::app,
|
||||
"Echo Failed: "+e.message());
|
||||
}
|
||||
}
|
||||
@@ -35,50 +35,52 @@ void on_message(server* s, websocketpp::connection_hdl hdl, message_ptr msg) {
|
||||
int main() {
|
||||
server s;
|
||||
std::ofstream log;
|
||||
|
||||
try {
|
||||
|
||||
try {
|
||||
// set up access channels to only log interesting things
|
||||
s.clear_access_channels(websocketpp::log::alevel::all);
|
||||
s.set_access_channels(websocketpp::log::alevel::connect);
|
||||
s.set_access_channels(websocketpp::log::alevel::disconnect);
|
||||
s.set_access_channels(websocketpp::log::alevel::app);
|
||||
|
||||
// Log to a file rather than stdout, as we are using stdout for real
|
||||
|
||||
// Log to a file rather than stdout, as we are using stdout for real
|
||||
// output
|
||||
log.open("output.log");
|
||||
s.get_alog().set_ostream(&log);
|
||||
s.get_elog().set_ostream(&log);
|
||||
|
||||
|
||||
// print all output to stdout
|
||||
s.register_ostream(&std::cout);
|
||||
|
||||
|
||||
// Register our message handler
|
||||
s.set_message_handler(bind(&on_message,&s,::_1,::_2));
|
||||
|
||||
|
||||
server::connection_ptr con = s.get_connection();
|
||||
|
||||
|
||||
con->start();
|
||||
|
||||
// C++ iostream's don't support the idea of asynchronous i/o. As such
|
||||
// there are two input strategies demonstrated here. Buffered I/O will
|
||||
// read from stdin in chunks until EOF. This works very well for
|
||||
|
||||
// C++ iostream's don't support the idea of asynchronous i/o. As such
|
||||
// there are two input strategies demonstrated here. Buffered I/O will
|
||||
// read from stdin in chunks until EOF. This works very well for
|
||||
// replaying canned connections as would be done in automated testing.
|
||||
//
|
||||
// If the server is being used live however, assuming input is being
|
||||
// piped from elsewhere in realtime, this strategy will result in small
|
||||
// messages being buffered forever. The non-buffered strategy below
|
||||
// reads characters from stdin one at a time. This is inefficient and
|
||||
// for more serious uses should be replaced with a platform specific
|
||||
// If the server is being used live however, assuming input is being
|
||||
// piped from elsewhere in realtime, this strategy will result in small
|
||||
// messages being buffered forever. The non-buffered strategy below
|
||||
// reads characters from stdin one at a time. This is inefficient and
|
||||
// for more serious uses should be replaced with a platform specific
|
||||
// asyncronous i/o technique like select, poll, IOCP, etc
|
||||
bool buffered_io = false;
|
||||
|
||||
|
||||
if (buffered_io) {
|
||||
std::cin >> *con;
|
||||
con->eof();
|
||||
} else {
|
||||
char a;
|
||||
while(std::cin.get(a)) {
|
||||
con->readsome(&a,1);
|
||||
con->read_some(&a,1);
|
||||
}
|
||||
con->eof();
|
||||
}
|
||||
} catch (const std::exception & e) {
|
||||
std::cout << e.what() << std::endl;
|
||||
@@ -88,4 +90,4 @@ int main() {
|
||||
std::cout << "other exception" << std::endl;
|
||||
}
|
||||
log.close();
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
|
||||
|
||||
file (GLOB SOURCE_FILES *.cpp)
|
||||
file (GLOB HEADER_FILES *.hpp)
|
||||
|
||||
|
||||
@@ -13,20 +13,20 @@ class broadcast_server {
|
||||
public:
|
||||
broadcast_server() {
|
||||
m_server.init_asio();
|
||||
|
||||
|
||||
m_server.set_open_handler(bind(&broadcast_server::on_open,this,::_1));
|
||||
m_server.set_close_handler(bind(&broadcast_server::on_close,this,::_1));
|
||||
m_server.set_message_handler(bind(&broadcast_server::on_message,this,::_1,::_2));
|
||||
}
|
||||
|
||||
|
||||
void on_open(connection_hdl hdl) {
|
||||
m_connections.insert(hdl);
|
||||
}
|
||||
|
||||
|
||||
void on_close(connection_hdl hdl) {
|
||||
m_connections.erase(hdl);
|
||||
}
|
||||
|
||||
|
||||
void on_message(connection_hdl hdl, server::message_ptr msg) {
|
||||
for (auto it : m_connections) {
|
||||
m_server.send(it,msg);
|
||||
@@ -48,4 +48,4 @@ private:
|
||||
int main() {
|
||||
broadcast_server server;
|
||||
server.run(9002);
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
|
||||
|
||||
file (GLOB SOURCE_FILES *.cpp)
|
||||
file (GLOB HEADER_FILES *.hpp)
|
||||
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
|
||||
#include <iostream>
|
||||
|
||||
#include <boost/thread/thread.hpp>
|
||||
#include <boost/thread/thread.hpp>
|
||||
|
||||
typedef websocketpp::client<websocketpp::config::asio_client> client;
|
||||
|
||||
@@ -21,12 +21,12 @@ typedef websocketpp::config::asio_client::message_type::ptr message_ptr;
|
||||
client sip_client;
|
||||
|
||||
|
||||
bool received;
|
||||
bool received;
|
||||
|
||||
void on_open(client* c, websocketpp::connection_hdl hdl) {
|
||||
// now it is safe to use the connection
|
||||
std::cout << "connection ready" << std::endl;
|
||||
|
||||
|
||||
received=false;
|
||||
// Send a SIP OPTIONS message to the server:
|
||||
std::string SIP_msg="OPTIONS sip:carol@chicago.com SIP/2.0\r\nVia: SIP/2.0/WS df7jal23ls0d.invalid;rport;branch=z9hG4bKhjhs8ass877\r\nMax-Forwards: 70\r\nTo: <sip:carol@chicago.com>\r\nFrom: Alice <sip:alice@atlanta.com>;tag=1928301774\r\nCall-ID: a84b4c76e66710\r\nCSeq: 63104 OPTIONS\r\nContact: <sip:alice@pc33.atlanta.com>\r\nAccept: application/sdp\r\nContent-Length: 0\r\n\r\n";
|
||||
@@ -35,32 +35,32 @@ void on_open(client* c, websocketpp::connection_hdl hdl) {
|
||||
|
||||
void on_message(client* c, websocketpp::connection_hdl hdl, message_ptr msg) {
|
||||
client::connection_ptr con = sip_client.get_con_from_hdl(hdl);
|
||||
|
||||
|
||||
std::cout << "Received a reply:" << std::endl;
|
||||
fwrite(msg->get_payload().c_str(), msg->get_payload().size(), 1, stdout);
|
||||
received=true;
|
||||
}
|
||||
|
||||
int main(int argc, char* argv[]) {
|
||||
|
||||
|
||||
std::string uri = "ws://localhost:9001";
|
||||
|
||||
|
||||
if (argc == 2) {
|
||||
uri = argv[1];
|
||||
}
|
||||
|
||||
|
||||
try {
|
||||
// We expect there to be a lot of errors, so suppress them
|
||||
sip_client.clear_access_channels(websocketpp::log::alevel::all);
|
||||
sip_client.clear_error_channels(websocketpp::log::elevel::all);
|
||||
|
||||
|
||||
// Initialize ASIO
|
||||
sip_client.init_asio();
|
||||
|
||||
|
||||
// Register our handlers
|
||||
sip_client.set_open_handler(bind(&on_open,&sip_client,::_1));
|
||||
sip_client.set_message_handler(bind(&on_message,&sip_client,::_1,::_2));
|
||||
|
||||
|
||||
websocketpp::lib::error_code ec;
|
||||
client::connection_ptr con = sip_client.get_connection(uri, ec);
|
||||
|
||||
@@ -68,16 +68,16 @@ int main(int argc, char* argv[]) {
|
||||
con->add_subprotocol("sip");
|
||||
|
||||
sip_client.connect(con);
|
||||
|
||||
|
||||
// Start the ASIO io_service run loop
|
||||
sip_client.run();
|
||||
|
||||
|
||||
while(!received) {
|
||||
boost::this_thread::sleep(boost::posix_time::milliseconds(100));
|
||||
}
|
||||
|
||||
|
||||
std::cout << "done" << std::endl;
|
||||
|
||||
|
||||
} catch (const std::exception & e) {
|
||||
std::cout << e.what() << std::endl;
|
||||
} catch (websocketpp::lib::error_code e) {
|
||||
|
||||
@@ -14,20 +14,20 @@ using websocketpp::lib::ref;
|
||||
|
||||
bool validate(server & s, connection_hdl hdl) {
|
||||
server::connection_ptr con = s.get_con_from_hdl(hdl);
|
||||
|
||||
|
||||
std::cout << "Cache-Control: " << con->get_request_header("Cache-Control") << std::endl;
|
||||
|
||||
|
||||
const std::vector<std::string> & subp_requests = con->get_requested_subprotocols();
|
||||
std::vector<std::string>::const_iterator it;
|
||||
|
||||
|
||||
for (it = subp_requests.begin(); it != subp_requests.end(); ++it) {
|
||||
std::cout << "Requested: " << *it << std::endl;
|
||||
}
|
||||
|
||||
|
||||
if (subp_requests.size() > 0) {
|
||||
con->select_subprotocol(subp_requests[0]);
|
||||
}
|
||||
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -49,4 +49,4 @@ int main() {
|
||||
} catch (...) {
|
||||
std::cout << "other exception" << std::endl;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
|
||||
|
||||
file (GLOB SOURCE_FILES *.cpp)
|
||||
file (GLOB HEADER_FILES *.hpp)
|
||||
|
||||
|
||||
@@ -9,24 +9,24 @@
|
||||
/**
|
||||
* The telemetry client connects to a WebSocket server and sends a message every
|
||||
* second containing an integer count. This example can be used as the basis for
|
||||
* programs where a client connects and pushes data for logging, stress/load
|
||||
* programs where a client connects and pushes data for logging, stress/load
|
||||
* testing, etc.
|
||||
*/
|
||||
class telemetry_client {
|
||||
public:
|
||||
typedef websocketpp::client<websocketpp::config::asio_client> client;
|
||||
typedef websocketpp::lib::lock_guard<websocketpp::lib::mutex> scoped_lock;
|
||||
|
||||
|
||||
telemetry_client() : m_open(false),m_done(false) {
|
||||
// set up access channels to only log interesting things
|
||||
m_client.clear_access_channels(websocketpp::log::alevel::all);
|
||||
m_client.set_access_channels(websocketpp::log::alevel::connect);
|
||||
m_client.set_access_channels(websocketpp::log::alevel::disconnect);
|
||||
m_client.set_access_channels(websocketpp::log::alevel::app);
|
||||
|
||||
|
||||
// Initialize the Asio transport policy
|
||||
m_client.init_asio();
|
||||
|
||||
|
||||
// Bind the handlers we are using
|
||||
using websocketpp::lib::placeholders::_1;
|
||||
using websocketpp::lib::bind;
|
||||
@@ -34,98 +34,104 @@ public:
|
||||
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
|
||||
void run(const std::string & uri) {
|
||||
// Create a new connection to the given URI
|
||||
websocketpp::lib::error_code ec;
|
||||
client::connection_ptr con = m_client.get_connection(uri, ec);
|
||||
if (ec) {
|
||||
m_client.get_alog().write(websocketpp::log::alevel::app,
|
||||
m_client.get_alog().write(websocketpp::log::alevel::app,
|
||||
"Get Connection Error: "+ec.message());
|
||||
return;
|
||||
}
|
||||
|
||||
// Grab a handle for this connection so we can talk to it in a thread
|
||||
|
||||
// Grab a handle for this connection so we can talk to it in a thread
|
||||
// safe manor after the event loop starts.
|
||||
m_hdl = con->get_handle();
|
||||
|
||||
|
||||
// Queue the connection. No DNS queries or network connections will be
|
||||
// made until the io_service event loop is run.
|
||||
m_client.connect(con);
|
||||
|
||||
|
||||
// Create a thread to run the ASIO io_service event loop
|
||||
websocketpp::lib::thread asio_thread(&client::run, &m_client);
|
||||
|
||||
|
||||
// Create a thread to run the telemetry loop
|
||||
websocketpp::lib::thread telemetry_thread(&telemetry_client::telemetry_loop,this);
|
||||
|
||||
|
||||
asio_thread.join();
|
||||
telemetry_thread.join();
|
||||
}
|
||||
|
||||
|
||||
// The open handler will signal that we are ready to start sending telemetry
|
||||
void on_open(websocketpp::connection_hdl hdl) {
|
||||
m_client.get_alog().write(websocketpp::log::alevel::app,
|
||||
m_client.get_alog().write(websocketpp::log::alevel::app,
|
||||
"Connection opened, starting telemetry!");
|
||||
|
||||
|
||||
scoped_lock guard(m_lock);
|
||||
m_open = true;
|
||||
}
|
||||
|
||||
|
||||
// The close handler will signal that we should stop sending telemetry
|
||||
void on_close(websocketpp::connection_hdl hdl) {
|
||||
m_client.get_alog().write(websocketpp::log::alevel::app,
|
||||
m_client.get_alog().write(websocketpp::log::alevel::app,
|
||||
"Connection closed, stopping telemetry!");
|
||||
|
||||
|
||||
scoped_lock guard(m_lock);
|
||||
m_done = true;
|
||||
}
|
||||
|
||||
|
||||
// The fail handler will signal that we should stop sending telemetry
|
||||
void on_fail(websocketpp::connection_hdl hdl) {
|
||||
m_client.get_alog().write(websocketpp::log::alevel::app,
|
||||
m_client.get_alog().write(websocketpp::log::alevel::app,
|
||||
"Connection failed, stopping telemetry!");
|
||||
|
||||
|
||||
scoped_lock guard(m_lock);
|
||||
m_done = true;
|
||||
}
|
||||
|
||||
|
||||
void telemetry_loop() {
|
||||
uint64_t count = 0;
|
||||
std::stringstream val;
|
||||
websocketpp::lib::error_code ec;
|
||||
|
||||
|
||||
while(1) {
|
||||
bool wait = false;
|
||||
|
||||
{
|
||||
scoped_lock guard(m_lock);
|
||||
// If the connection has been closed, stop generating telemetry
|
||||
if (m_done) {break;}
|
||||
|
||||
|
||||
// If the connection hasn't been opened yet wait a bit and retry
|
||||
if (!m_open) {
|
||||
sleep(1);
|
||||
continue;
|
||||
wait = true;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (wait) {
|
||||
sleep(1);
|
||||
continue;
|
||||
}
|
||||
|
||||
val.str("");
|
||||
val << "count is " << count++;
|
||||
|
||||
|
||||
m_client.get_alog().write(websocketpp::log::alevel::app, val.str());
|
||||
m_client.send(m_hdl,val.str(),websocketpp::frame::opcode::text,ec);
|
||||
|
||||
|
||||
// The most likely error that we will get is that the connection is
|
||||
// not in the right state. Usually this means we tried to send a
|
||||
// message to a connection that was closed or in the process of
|
||||
// closing. While many errors here can be easily recovered from,
|
||||
// not in the right state. Usually this means we tried to send a
|
||||
// message to a connection that was closed or in the process of
|
||||
// closing. While many errors here can be easily recovered from,
|
||||
// in this simple example, we'll stop the telemetry loop.
|
||||
if (ec) {
|
||||
m_client.get_alog().write(websocketpp::log::alevel::app,
|
||||
m_client.get_alog().write(websocketpp::log::alevel::app,
|
||||
"Send Error: "+ec.message());
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
sleep(1);
|
||||
}
|
||||
}
|
||||
@@ -139,12 +145,12 @@ private:
|
||||
|
||||
int main(int argc, char* argv[]) {
|
||||
telemetry_client c;
|
||||
|
||||
|
||||
std::string uri = "ws://localhost:9002";
|
||||
|
||||
|
||||
if (argc == 2) {
|
||||
uri = argv[1];
|
||||
}
|
||||
|
||||
|
||||
c.run(uri);
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
|
||||
|
||||
file (GLOB SOURCE_FILES *.cpp)
|
||||
file (GLOB HEADER_FILES *.hpp)
|
||||
|
||||
|
||||
@@ -17,9 +17,9 @@ int case_count = 0;
|
||||
|
||||
void on_message(client* c, websocketpp::connection_hdl hdl, message_ptr msg) {
|
||||
client::connection_ptr con = c->get_con_from_hdl(hdl);
|
||||
|
||||
|
||||
if (con->get_resource() == "/getCaseCount") {
|
||||
std::cout << "Detected " << msg->get_payload() << " test cases."
|
||||
std::cout << "Detected " << msg->get_payload() << " test cases."
|
||||
<< std::endl;
|
||||
case_count = atoi(msg->get_payload().c_str());
|
||||
} else {
|
||||
@@ -30,50 +30,50 @@ void on_message(client* c, websocketpp::connection_hdl hdl, message_ptr msg) {
|
||||
int main(int argc, char* argv[]) {
|
||||
// Create a server endpoint
|
||||
client c;
|
||||
|
||||
|
||||
std::string uri = "ws://localhost:9001";
|
||||
|
||||
|
||||
if (argc == 2) {
|
||||
uri = argv[1];
|
||||
}
|
||||
|
||||
|
||||
try {
|
||||
// We expect there to be a lot of errors, so suppress them
|
||||
c.clear_access_channels(websocketpp::log::alevel::all);
|
||||
c.clear_error_channels(websocketpp::log::elevel::all);
|
||||
|
||||
|
||||
// Initialize ASIO
|
||||
c.init_asio();
|
||||
|
||||
|
||||
// Register our handlers
|
||||
c.set_message_handler(bind(&on_message,&c,::_1,::_2));
|
||||
|
||||
|
||||
websocketpp::lib::error_code ec;
|
||||
client::connection_ptr con = c.get_connection(uri+"/getCaseCount", ec);
|
||||
c.connect(con);
|
||||
|
||||
|
||||
// Start the ASIO io_service run loop
|
||||
c.run();
|
||||
|
||||
|
||||
std::cout << "case count: " << case_count << std::endl;
|
||||
|
||||
|
||||
for (int i = 1; i <= case_count; i++) {
|
||||
c.reset();
|
||||
|
||||
|
||||
std::stringstream url;
|
||||
|
||||
url << uri << "/runCase?case=" << i << "&agent="
|
||||
|
||||
url << uri << "/runCase?case=" << i << "&agent="
|
||||
<< websocketpp::user_agent;
|
||||
|
||||
|
||||
con = c.get_connection(url.str(), ec);
|
||||
|
||||
|
||||
c.connect(con);
|
||||
|
||||
|
||||
c.run();
|
||||
}
|
||||
|
||||
|
||||
std::cout << "done" << std::endl;
|
||||
|
||||
|
||||
} catch (const std::exception & e) {
|
||||
std::cout << e.what() << std::endl;
|
||||
} catch (websocketpp::lib::error_code e) {
|
||||
|
||||
@@ -29,7 +29,44 @@
|
||||
#include <websocketpp/server.hpp>
|
||||
#include <iostream>
|
||||
|
||||
typedef websocketpp::server<websocketpp::config::asio> server;
|
||||
struct testee_config : public websocketpp::config::asio {
|
||||
// pull default settings from our core config
|
||||
typedef websocketpp::config::asio core;
|
||||
|
||||
typedef core::concurrency_type concurrency_type;
|
||||
typedef core::request_type request_type;
|
||||
typedef core::response_type response_type;
|
||||
typedef core::message_type message_type;
|
||||
typedef core::con_msg_manager_type con_msg_manager_type;
|
||||
typedef core::endpoint_msg_manager_type endpoint_msg_manager_type;
|
||||
|
||||
typedef core::alog_type alog_type;
|
||||
typedef core::elog_type elog_type;
|
||||
typedef core::rng_type rng_type;
|
||||
typedef core::endpoint_base endpoint_base;
|
||||
|
||||
static bool const enable_multithreading = false;
|
||||
|
||||
struct transport_config : public core::transport_config {
|
||||
typedef core::concurrency_type concurrency_type;
|
||||
typedef core::elog_type elog_type;
|
||||
typedef core::alog_type alog_type;
|
||||
typedef core::request_type request_type;
|
||||
typedef core::response_type response_type;
|
||||
|
||||
static bool const enable_multithreading = false;
|
||||
};
|
||||
|
||||
typedef websocketpp::transport::asio::endpoint<transport_config>
|
||||
transport_type;
|
||||
|
||||
static const websocketpp::log::level elog_level =
|
||||
websocketpp::log::elevel::none;
|
||||
static const websocketpp::log::level alog_level =
|
||||
websocketpp::log::alevel::none;
|
||||
};
|
||||
|
||||
typedef websocketpp::server<testee_config> server;
|
||||
|
||||
using websocketpp::lib::placeholders::_1;
|
||||
using websocketpp::lib::placeholders::_2;
|
||||
@@ -43,11 +80,24 @@ void on_message(server* s, websocketpp::connection_hdl hdl, message_ptr msg) {
|
||||
s->send(hdl, msg->get_payload(), msg->get_opcode());
|
||||
}
|
||||
|
||||
int main() {
|
||||
// Create a server endpoint
|
||||
void on_socket_init(websocketpp::connection_hdl hdl, boost::asio::ip::tcp::socket & s) {
|
||||
boost::asio::ip::tcp::no_delay option(true);
|
||||
s.set_option(option);
|
||||
}
|
||||
|
||||
int main(int argc, char * argv[]) {
|
||||
// Create a server endpoint
|
||||
server testee_server;
|
||||
|
||||
try {
|
||||
short port = 9002;
|
||||
size_t num_threads = 1;
|
||||
|
||||
if (argc == 3) {
|
||||
port = atoi(argv[1]);
|
||||
num_threads = atoi(argv[2]);
|
||||
}
|
||||
|
||||
try {
|
||||
// Total silence
|
||||
testee_server.clear_access_channels(websocketpp::log::alevel::all);
|
||||
testee_server.clear_error_channels(websocketpp::log::alevel::all);
|
||||
@@ -57,19 +107,34 @@ int main() {
|
||||
|
||||
// Register our message handler
|
||||
testee_server.set_message_handler(bind(&on_message,&testee_server,::_1,::_2));
|
||||
testee_server.set_socket_init_handler(bind(&on_socket_init,::_1,::_2));
|
||||
|
||||
// Listen on port 9002
|
||||
testee_server.listen(9002);
|
||||
// Listen on specified port with extended listen backlog
|
||||
testee_server.set_listen_backlog(8192);
|
||||
testee_server.listen(port);
|
||||
|
||||
// Start the server accept loop
|
||||
testee_server.start_accept();
|
||||
|
||||
// Start the ASIO io_service run loop
|
||||
testee_server.run();
|
||||
// Start the ASIO io_service run loop
|
||||
if (num_threads == 1) {
|
||||
testee_server.run();
|
||||
} else {
|
||||
typedef websocketpp::lib::shared_ptr<websocketpp::lib::thread> thread_ptr;
|
||||
std::vector<thread_ptr> ts;
|
||||
for (size_t i = 0; i < num_threads; i++) {
|
||||
ts.push_back(thread_ptr(new websocketpp::lib::thread(&server::run, &testee_server)));
|
||||
}
|
||||
|
||||
for (size_t i = 0; i < num_threads; i++) {
|
||||
ts[i]->join();
|
||||
}
|
||||
}
|
||||
|
||||
} catch (const std::exception & e) {
|
||||
std::cout << e.what() << std::endl;
|
||||
std::cout << "exception: " << e.what() << std::endl;
|
||||
} catch (websocketpp::lib::error_code e) {
|
||||
std::cout << e.message() << std::endl;
|
||||
std::cout << "error code: " << e.message() << std::endl;
|
||||
} catch (...) {
|
||||
std::cout << "other exception" << std::endl;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,11 @@
|
||||
|
||||
file (GLOB SOURCE_FILES *.cpp)
|
||||
file (GLOB HEADER_FILES *.hpp)
|
||||
|
||||
init_target (utility_client)
|
||||
|
||||
build_executable (${TARGET_NAME} ${SOURCE_FILES} ${HEADER_FILES})
|
||||
|
||||
link_boost ()
|
||||
final_target ()
|
||||
|
||||
@@ -6,7 +6,6 @@ Import('env_cpp11')
|
||||
Import('boostlibs')
|
||||
Import('platform_libs')
|
||||
Import('polyfill_libs')
|
||||
Import('tls_libs')
|
||||
|
||||
env = env.Clone ()
|
||||
env_cpp11 = env_cpp11.Clone ()
|
||||
@@ -15,10 +14,10 @@ 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]
|
||||
ALL_LIBS = boostlibs(['system'],env_cpp11) + [platform_libs] + [polyfill_libs]
|
||||
prgs += env_cpp11.Program('utility_client', ["utility_client.cpp"], LIBS = ALL_LIBS)
|
||||
else:
|
||||
ALL_LIBS = boostlibs(['system','random'],env) + [platform_libs] + [polyfill_libs] + [tls_libs]
|
||||
ALL_LIBS = boostlibs(['system','random'],env) + [platform_libs] + [polyfill_libs]
|
||||
prgs += env.Program('utility_client', ["utility_client.cpp"], LIBS = ALL_LIBS)
|
||||
|
||||
Return('prgs')
|
||||
@@ -1,126 +1,270 @@
|
||||
/**
|
||||
* This example is presently used as a scratch space. It may or may not be broken
|
||||
* at any given time.
|
||||
/*
|
||||
* 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:
|
||||
* * 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.
|
||||
*/
|
||||
|
||||
#include <websocketpp/config/asio_client.hpp>
|
||||
// **NOTE:** This file is a snapshot of the WebSocket++ utility client tutorial.
|
||||
// Additional related material can be found in the tutorials/utility_client
|
||||
// directory of the WebSocket++ repository.
|
||||
|
||||
#include <websocketpp/config/asio_no_tls_client.hpp>
|
||||
#include <websocketpp/client.hpp>
|
||||
|
||||
#include <websocketpp/common/thread.hpp>
|
||||
#include <websocketpp/common/memory.hpp>
|
||||
|
||||
#include <cstdlib>
|
||||
#include <iostream>
|
||||
#include <chrono>
|
||||
#include <map>
|
||||
#include <string>
|
||||
#include <sstream>
|
||||
|
||||
typedef websocketpp::client<websocketpp::config::asio_tls_client> client;
|
||||
typedef websocketpp::client<websocketpp::config::asio_client> client;
|
||||
|
||||
using websocketpp::lib::placeholders::_1;
|
||||
using websocketpp::lib::placeholders::_2;
|
||||
using websocketpp::lib::bind;
|
||||
|
||||
// pull out the type of messages sent by our config
|
||||
typedef websocketpp::config::asio_tls_client::message_type::ptr message_ptr;
|
||||
typedef websocketpp::lib::shared_ptr<boost::asio::ssl::context> context_ptr;
|
||||
typedef client::connection_ptr connection_ptr;
|
||||
|
||||
|
||||
|
||||
class perftest {
|
||||
class connection_metadata {
|
||||
public:
|
||||
typedef perftest type;
|
||||
typedef std::chrono::duration<int,std::micro> dur_type;
|
||||
|
||||
perftest () {
|
||||
m_endpoint.set_access_channels(websocketpp::log::alevel::all);
|
||||
m_endpoint.set_error_channels(websocketpp::log::elevel::all);
|
||||
|
||||
// Initialize ASIO
|
||||
m_endpoint.init_asio();
|
||||
|
||||
// Register our handlers
|
||||
m_endpoint.set_socket_init_handler(bind(&type::on_socket_init,this,::_1));
|
||||
m_endpoint.set_tls_init_handler(bind(&type::on_tls_init,this,::_1));
|
||||
m_endpoint.set_message_handler(bind(&type::on_message,this,::_1,::_2));
|
||||
m_endpoint.set_open_handler(bind(&type::on_open,this,::_1));
|
||||
m_endpoint.set_close_handler(bind(&type::on_close,this,::_1));
|
||||
}
|
||||
|
||||
void start(std::string uri) {
|
||||
websocketpp::lib::error_code ec;
|
||||
client::connection_ptr con = m_endpoint.get_connection(uri, ec);
|
||||
|
||||
if (ec) {
|
||||
m_endpoint.get_alog().write(websocketpp::log::alevel::app,ec.message());
|
||||
}
|
||||
|
||||
//con->set_proxy("http://humupdates.uchicago.edu:8443");
|
||||
|
||||
m_endpoint.connect(con);
|
||||
|
||||
// Start the ASIO io_service run loop
|
||||
m_start = std::chrono::high_resolution_clock::now();
|
||||
m_endpoint.run();
|
||||
}
|
||||
|
||||
void on_socket_init(websocketpp::connection_hdl hdl) {
|
||||
m_socket_init = std::chrono::high_resolution_clock::now();
|
||||
}
|
||||
|
||||
context_ptr on_tls_init(websocketpp::connection_hdl hdl) {
|
||||
m_tls_init = std::chrono::high_resolution_clock::now();
|
||||
context_ptr ctx(new boost::asio::ssl::context(boost::asio::ssl::context::tlsv1));
|
||||
typedef websocketpp::lib::shared_ptr<connection_metadata> ptr;
|
||||
|
||||
try {
|
||||
ctx->set_options(boost::asio::ssl::context::default_workarounds |
|
||||
boost::asio::ssl::context::no_sslv2 |
|
||||
boost::asio::ssl::context::single_dh_use);
|
||||
} catch (std::exception& e) {
|
||||
std::cout << e.what() << std::endl;
|
||||
}
|
||||
return ctx;
|
||||
connection_metadata(int id, websocketpp::connection_hdl hdl, std::string uri)
|
||||
: m_id(id)
|
||||
, m_hdl(hdl)
|
||||
, m_status("Connecting")
|
||||
, m_uri(uri)
|
||||
, m_server("N/A")
|
||||
{}
|
||||
|
||||
void on_open(client * c, websocketpp::connection_hdl hdl) {
|
||||
m_status = "Open";
|
||||
|
||||
client::connection_ptr con = c->get_con_from_hdl(hdl);
|
||||
m_server = con->get_response_header("Server");
|
||||
}
|
||||
|
||||
void on_fail(client * c, websocketpp::connection_hdl hdl) {
|
||||
m_status = "Failed";
|
||||
|
||||
client::connection_ptr con = c->get_con_from_hdl(hdl);
|
||||
m_server = con->get_response_header("Server");
|
||||
m_error_reason = con->get_ec().message();
|
||||
}
|
||||
|
||||
void on_open(websocketpp::connection_hdl hdl) {
|
||||
m_open = std::chrono::high_resolution_clock::now();
|
||||
m_endpoint.send(hdl, "", websocketpp::frame::opcode::text);
|
||||
void on_close(client * c, websocketpp::connection_hdl hdl) {
|
||||
m_status = "Closed";
|
||||
client::connection_ptr con = c->get_con_from_hdl(hdl);
|
||||
std::stringstream s;
|
||||
s << "close code: " << con->get_remote_close_code() << " ("
|
||||
<< websocketpp::close::status::get_string(con->get_remote_close_code())
|
||||
<< "), close reason: " << con->get_remote_close_reason();
|
||||
m_error_reason = s.str();
|
||||
}
|
||||
void on_message(websocketpp::connection_hdl hdl, message_ptr msg) {
|
||||
m_message = std::chrono::high_resolution_clock::now();
|
||||
m_endpoint.close(hdl,websocketpp::close::status::going_away,"");
|
||||
|
||||
websocketpp::connection_hdl get_hdl() const {
|
||||
return m_hdl;
|
||||
}
|
||||
void on_close(websocketpp::connection_hdl hdl) {
|
||||
m_close = std::chrono::high_resolution_clock::now();
|
||||
|
||||
std::cout << "Socket Init: " << std::chrono::duration_cast<dur_type>(m_socket_init-m_start).count() << std::endl;
|
||||
std::cout << "TLS Init: " << std::chrono::duration_cast<dur_type>(m_tls_init-m_start).count() << std::endl;
|
||||
std::cout << "Open: " << std::chrono::duration_cast<dur_type>(m_open-m_start).count() << std::endl;
|
||||
std::cout << "Message: " << std::chrono::duration_cast<dur_type>(m_message-m_start).count() << std::endl;
|
||||
std::cout << "Close: " << std::chrono::duration_cast<dur_type>(m_close-m_start).count() << std::endl;
|
||||
|
||||
int get_id() const {
|
||||
return m_id;
|
||||
}
|
||||
|
||||
std::string get_status() const {
|
||||
return m_status;
|
||||
}
|
||||
|
||||
friend std::ostream & operator<< (std::ostream & out, connection_metadata const & data);
|
||||
private:
|
||||
client m_endpoint;
|
||||
|
||||
std::chrono::high_resolution_clock::time_point m_start;
|
||||
std::chrono::high_resolution_clock::time_point m_socket_init;
|
||||
std::chrono::high_resolution_clock::time_point m_tls_init;
|
||||
std::chrono::high_resolution_clock::time_point m_open;
|
||||
std::chrono::high_resolution_clock::time_point m_message;
|
||||
std::chrono::high_resolution_clock::time_point m_close;
|
||||
int m_id;
|
||||
websocketpp::connection_hdl m_hdl;
|
||||
std::string m_status;
|
||||
std::string m_uri;
|
||||
std::string m_server;
|
||||
std::string m_error_reason;
|
||||
};
|
||||
|
||||
int main(int argc, char* argv[]) {
|
||||
std::string uri = "wss://echo.websocket.org";
|
||||
|
||||
if (argc == 2) {
|
||||
uri = argv[1];
|
||||
}
|
||||
|
||||
try {
|
||||
perftest endpoint;
|
||||
endpoint.start(uri);
|
||||
} catch (const std::exception & e) {
|
||||
std::cout << e.what() << std::endl;
|
||||
} catch (websocketpp::lib::error_code e) {
|
||||
std::cout << e.message() << std::endl;
|
||||
} catch (...) {
|
||||
std::cout << "other exception" << std::endl;
|
||||
std::ostream & operator<< (std::ostream & out, connection_metadata const & data) {
|
||||
out << "> URI: " << data.m_uri << "\n"
|
||||
<< "> Status: " << data.m_status << "\n"
|
||||
<< "> Remote Server: " << (data.m_server.empty() ? "None Specified" : data.m_server) << "\n"
|
||||
<< "> Error/close reason: " << (data.m_error_reason.empty() ? "N/A" : data.m_error_reason);
|
||||
|
||||
return out;
|
||||
}
|
||||
|
||||
class websocket_endpoint {
|
||||
public:
|
||||
websocket_endpoint () : m_next_id(0) {
|
||||
m_endpoint.clear_access_channels(websocketpp::log::alevel::all);
|
||||
m_endpoint.clear_error_channels(websocketpp::log::elevel::all);
|
||||
|
||||
m_endpoint.init_asio();
|
||||
m_endpoint.start_perpetual();
|
||||
|
||||
m_thread.reset(new websocketpp::lib::thread(&client::run, &m_endpoint));
|
||||
}
|
||||
|
||||
~websocket_endpoint() {
|
||||
m_endpoint.stop_perpetual();
|
||||
|
||||
for (con_list::const_iterator it = m_connection_list.begin(); it != m_connection_list.end(); ++it) {
|
||||
if (it->second->get_status() != "Open") {
|
||||
// Only close open connections
|
||||
continue;
|
||||
}
|
||||
|
||||
std::cout << "> Closing connection " << it->second->get_id() << std::endl;
|
||||
|
||||
websocketpp::lib::error_code ec;
|
||||
m_endpoint.close(it->second->get_hdl(), websocketpp::close::status::going_away, "", ec);
|
||||
if (ec) {
|
||||
std::cout << "> Error closing connection " << it->second->get_id() << ": "
|
||||
<< ec.message() << std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
m_thread->join();
|
||||
}
|
||||
|
||||
int connect(std::string const & uri) {
|
||||
websocketpp::lib::error_code ec;
|
||||
|
||||
client::connection_ptr con = m_endpoint.get_connection(uri, ec);
|
||||
|
||||
if (ec) {
|
||||
std::cout << "> Connect initialization error: " << ec.message() << std::endl;
|
||||
return -1;
|
||||
}
|
||||
|
||||
int new_id = m_next_id++;
|
||||
connection_metadata::ptr metadata_ptr(new connection_metadata(new_id, con->get_handle(), uri));
|
||||
m_connection_list[new_id] = metadata_ptr;
|
||||
|
||||
con->set_open_handler(websocketpp::lib::bind(
|
||||
&connection_metadata::on_open,
|
||||
metadata_ptr,
|
||||
&m_endpoint,
|
||||
websocketpp::lib::placeholders::_1
|
||||
));
|
||||
con->set_fail_handler(websocketpp::lib::bind(
|
||||
&connection_metadata::on_fail,
|
||||
metadata_ptr,
|
||||
&m_endpoint,
|
||||
websocketpp::lib::placeholders::_1
|
||||
));
|
||||
con->set_close_handler(websocketpp::lib::bind(
|
||||
&connection_metadata::on_close,
|
||||
metadata_ptr,
|
||||
&m_endpoint,
|
||||
websocketpp::lib::placeholders::_1
|
||||
));
|
||||
|
||||
m_endpoint.connect(con);
|
||||
|
||||
return new_id;
|
||||
}
|
||||
|
||||
void close(int id, websocketpp::close::status::value code, std::string reason) {
|
||||
websocketpp::lib::error_code ec;
|
||||
|
||||
con_list::iterator metadata_it = m_connection_list.find(id);
|
||||
if (metadata_it == m_connection_list.end()) {
|
||||
std::cout << "> No connection found with id " << id << std::endl;
|
||||
return;
|
||||
}
|
||||
|
||||
m_endpoint.close(metadata_it->second->get_hdl(), code, reason, ec);
|
||||
if (ec) {
|
||||
std::cout << "> Error initiating close: " << ec.message() << std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
connection_metadata::ptr get_metadata(int id) const {
|
||||
con_list::const_iterator metadata_it = m_connection_list.find(id);
|
||||
if (metadata_it == m_connection_list.end()) {
|
||||
return connection_metadata::ptr();
|
||||
} else {
|
||||
return metadata_it->second;
|
||||
}
|
||||
}
|
||||
private:
|
||||
typedef std::map<int,connection_metadata::ptr> con_list;
|
||||
|
||||
client m_endpoint;
|
||||
websocketpp::lib::shared_ptr<websocketpp::lib::thread> m_thread;
|
||||
|
||||
con_list m_connection_list;
|
||||
int m_next_id;
|
||||
};
|
||||
|
||||
int main() {
|
||||
bool done = false;
|
||||
std::string input;
|
||||
websocket_endpoint endpoint;
|
||||
|
||||
while (!done) {
|
||||
std::cout << "Enter Command: ";
|
||||
std::getline(std::cin, input);
|
||||
|
||||
if (input == "quit") {
|
||||
done = true;
|
||||
} else if (input == "help") {
|
||||
std::cout
|
||||
<< "\nCommand List:\n"
|
||||
<< "connect <ws uri>\n"
|
||||
<< "close <connection id> [<close code:default=1000>] [<close reason>]\n"
|
||||
<< "show <connection id>\n"
|
||||
<< "help: Display this help text\n"
|
||||
<< "quit: Exit the program\n"
|
||||
<< std::endl;
|
||||
} else if (input.substr(0,7) == "connect") {
|
||||
int id = endpoint.connect(input.substr(8));
|
||||
if (id != -1) {
|
||||
std::cout << "> Created connection with id " << id << std::endl;
|
||||
}
|
||||
} else if (input.substr(0,5) == "close") {
|
||||
std::stringstream ss(input);
|
||||
|
||||
std::string cmd;
|
||||
int id;
|
||||
int close_code = websocketpp::close::status::normal;
|
||||
std::string reason = "";
|
||||
|
||||
ss >> cmd >> id >> close_code;
|
||||
std::getline(ss,reason);
|
||||
|
||||
endpoint.close(id, close_code, reason);
|
||||
} else if (input.substr(0,4) == "show") {
|
||||
int id = atoi(input.substr(5).c_str());
|
||||
|
||||
connection_metadata::ptr metadata = endpoint.get_metadata(id);
|
||||
if (metadata) {
|
||||
std::cout << *metadata << std::endl;
|
||||
} else {
|
||||
std::cout << "> Unknown connection id " << id << std::endl;
|
||||
}
|
||||
} else {
|
||||
std::cout << "> Unrecognized Command" << std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
WebSocket++ (0.3.0-alpha3)
|
||||
WebSocket++ (0.3.0-alpha4)
|
||||
==========================
|
||||
|
||||
WebSocket++ is a header only C++ library that implements RFC6455 The WebSocket
|
||||
@@ -22,22 +22,22 @@ Get Involved
|
||||
|
||||
[](https://travis-ci.org/zaphoyd/websocketpp)
|
||||
|
||||
**Project Website**
|
||||
**Project Website**
|
||||
http://www.zaphoyd.com/websocketpp/
|
||||
|
||||
**User Manual**
|
||||
**User Manual**
|
||||
http://www.zaphoyd.com/websocketpp/manual/
|
||||
|
||||
**GitHub Repository**
|
||||
**GitHub Repository**
|
||||
https://github.com/zaphoyd/websocketpp/
|
||||
|
||||
**Announcements Mailing List**
|
||||
**Announcements Mailing List**
|
||||
http://groups.google.com/group/websocketpp-announcements/
|
||||
|
||||
**IRC Channel**
|
||||
**IRC Channel**
|
||||
#websocketpp (freenode)
|
||||
|
||||
**Discussion / Development / Support Mailing List / Forum**
|
||||
**Discussion / Development / Support Mailing List / Forum**
|
||||
http://groups.google.com/group/websocketpp/
|
||||
|
||||
Author
|
||||
|
||||
+12
-9
@@ -10,16 +10,18 @@ Complete & Tested:
|
||||
- 32 bit support
|
||||
- Logging
|
||||
- Client role
|
||||
|
||||
Implimented, needs more testing
|
||||
- TLS support
|
||||
- echo_server & echo_server_tls
|
||||
- External io_service support
|
||||
- socket_init_handler
|
||||
- tls_init_handler
|
||||
- message_handler
|
||||
- ping_handler
|
||||
- pong_handler
|
||||
- open_handler
|
||||
- close_handler
|
||||
- echo_server & echo_server_tls
|
||||
|
||||
Implemented, needs more testing
|
||||
- TLS support
|
||||
- External io_service support
|
||||
- socket_init_handler
|
||||
- tls_init_handler
|
||||
- tcp_init_handler
|
||||
- exception/error handling
|
||||
- Subprotocol negotiation
|
||||
@@ -30,8 +32,7 @@ Implimented, needs more testing
|
||||
- Visual Studio / Windows support
|
||||
- Timeouts
|
||||
- CMake build/install support
|
||||
- open_handler
|
||||
- close_handler
|
||||
|
||||
- validate_handler
|
||||
- http_handler
|
||||
|
||||
@@ -39,3 +40,5 @@ Future feature roadmap
|
||||
- Extension support
|
||||
- permessage_compress extension
|
||||
- Message buffer pool
|
||||
- flow control
|
||||
- tutorials & documentation
|
||||
@@ -11,10 +11,10 @@
|
||||
* * 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
|
||||
*
|
||||
* 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;
|
||||
@@ -22,7 +22,7 @@
|
||||
* 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.
|
||||
*
|
||||
*
|
||||
*/
|
||||
//#define BOOST_TEST_DYN_LINK
|
||||
#define BOOST_TEST_MODULE connection
|
||||
@@ -30,15 +30,15 @@
|
||||
|
||||
#include "connection_tu2.hpp"
|
||||
|
||||
// NOTE: these tests currently test against hardcoded output values. I am not
|
||||
// sure how problematic this will be. If issues arise like order of headers the
|
||||
// NOTE: these tests currently test against hardcoded output values. I am not
|
||||
// sure how problematic this will be. If issues arise like order of headers the
|
||||
// output should be parsed by http::response and have values checked directly
|
||||
|
||||
BOOST_AUTO_TEST_CASE( basic_http_request ) {
|
||||
std::string input = "GET / HTTP/1.1\r\nHost: www.example.com\r\n\r\n";
|
||||
std::string output = "HTTP/1.1 426 Upgrade Required\r\nServer: " +
|
||||
std::string output = "HTTP/1.1 426 Upgrade Required\r\nServer: " +
|
||||
std::string(websocketpp::user_agent)+"\r\n\r\n";
|
||||
|
||||
|
||||
std::string o2 = run_server_test(input);
|
||||
|
||||
BOOST_CHECK(o2 == output);
|
||||
@@ -46,15 +46,15 @@ BOOST_AUTO_TEST_CASE( basic_http_request ) {
|
||||
|
||||
struct connection_extension {
|
||||
connection_extension() : extension_value(5) {}
|
||||
|
||||
|
||||
int extension_method() {
|
||||
return extension_value;
|
||||
}
|
||||
|
||||
|
||||
bool is_server() const {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
int extension_value;
|
||||
};
|
||||
|
||||
@@ -72,17 +72,16 @@ struct stub_config : public websocketpp::config::core {
|
||||
typedef core::elog_type elog_type;
|
||||
|
||||
typedef core::rng_type rng_type;
|
||||
|
||||
|
||||
typedef core::transport_type transport_type;
|
||||
|
||||
|
||||
typedef core::endpoint_base endpoint_base;
|
||||
typedef connection_extension connection_base;
|
||||
};
|
||||
|
||||
struct connection_setup {
|
||||
connection_setup(bool server)
|
||||
: c(server,"",alog,elog,rng) {}
|
||||
|
||||
connection_setup(bool p_is_server) : c(p_is_server, "", alog, elog, rng) {}
|
||||
|
||||
websocketpp::lib::error_code ec;
|
||||
stub_config::alog_type alog;
|
||||
stub_config::elog_type elog;
|
||||
@@ -106,19 +105,19 @@ bool validate_set_ua(server* s, websocketpp::connection_hdl hdl) {
|
||||
|
||||
void http_func(server* s, websocketpp::connection_hdl hdl) {
|
||||
server::connection_ptr con = s->get_con_from_hdl(hdl);
|
||||
|
||||
|
||||
std::string res = con->get_resource();
|
||||
|
||||
|
||||
con->set_body(res);
|
||||
con->set_status(websocketpp::http::status_code::ok);
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE( connection_extensions ) {
|
||||
connection_setup env(true);
|
||||
|
||||
|
||||
BOOST_CHECK( env.c.extension_value == 5 );
|
||||
BOOST_CHECK( env.c.extension_method() == 5 );
|
||||
|
||||
|
||||
BOOST_CHECK( env.c.is_server() == true );
|
||||
}
|
||||
|
||||
@@ -127,10 +126,10 @@ BOOST_AUTO_TEST_CASE( basic_websocket_request ) {
|
||||
std::string output = "HTTP/1.1 101 Switching Protocols\r\nConnection: upgrade\r\nSec-WebSocket-Accept: s3pPLMBiTxaQ9kYGzzhZRbK+xOo=\r\nServer: ";
|
||||
output+=websocketpp::user_agent;
|
||||
output+="\r\nUpgrade: websocket\r\n\r\n";
|
||||
|
||||
|
||||
server s;
|
||||
s.set_message_handler(bind(&echo_func,&s,::_1,::_2));
|
||||
|
||||
|
||||
BOOST_CHECK(run_server_test(s,input) == output);
|
||||
}
|
||||
|
||||
@@ -139,74 +138,102 @@ BOOST_AUTO_TEST_CASE( http_request ) {
|
||||
std::string output = "HTTP/1.1 200 OK\r\nContent-Length: 8\r\nServer: ";
|
||||
output+=websocketpp::user_agent;
|
||||
output+="\r\n\r\n/foo/bar";
|
||||
|
||||
|
||||
server s;
|
||||
s.set_http_handler(bind(&http_func,&s,::_1));
|
||||
|
||||
|
||||
BOOST_CHECK_EQUAL(run_server_test(s,input), output);
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE( request_no_server_header ) {
|
||||
std::string input = "GET / HTTP/1.1\r\nHost: www.example.com\r\nConnection: upgrade\r\nUpgrade: websocket\r\nSec-WebSocket-Version: 13\r\nSec-WebSocket-Key: dGhlIHNhbXBsZSBub25jZQ==\r\nOrigin: http://www.example.com\r\n\r\n";
|
||||
std::string output = "HTTP/1.1 101 Switching Protocols\r\nConnection: upgrade\r\nSec-WebSocket-Accept: s3pPLMBiTxaQ9kYGzzhZRbK+xOo=\r\nUpgrade: websocket\r\n\r\n";
|
||||
|
||||
|
||||
server s;
|
||||
s.set_user_agent("");
|
||||
s.set_message_handler(bind(&echo_func,&s,::_1,::_2));
|
||||
|
||||
|
||||
BOOST_CHECK_EQUAL(run_server_test(s,input), output);
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE( request_no_server_header_override ) {
|
||||
std::string input = "GET / HTTP/1.1\r\nHost: www.example.com\r\nConnection: upgrade\r\nUpgrade: websocket\r\nSec-WebSocket-Version: 13\r\nSec-WebSocket-Key: dGhlIHNhbXBsZSBub25jZQ==\r\nOrigin: http://www.example.com\r\n\r\n";
|
||||
std::string output = "HTTP/1.1 101 Switching Protocols\r\nConnection: upgrade\r\nSec-WebSocket-Accept: s3pPLMBiTxaQ9kYGzzhZRbK+xOo=\r\nServer: foo\r\nUpgrade: websocket\r\n\r\n";
|
||||
|
||||
|
||||
server s;
|
||||
s.set_user_agent("");
|
||||
s.set_message_handler(bind(&echo_func,&s,::_1,::_2));
|
||||
s.set_validate_handler(bind(&validate_set_ua,&s,::_1));
|
||||
|
||||
|
||||
BOOST_CHECK_EQUAL(run_server_test(s,input), output);
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE( basic_client_websocket ) {
|
||||
std::string uri = "ws://localhost";
|
||||
|
||||
|
||||
//std::string output = "HTTP/1.1 101 Switching Protocols\r\nConnection: upgrade\r\nSec-WebSocket-Accept: s3pPLMBiTxaQ9kYGzzhZRbK+xOo=\r\nServer: foo\r\nUpgrade: websocket\r\n\r\n";
|
||||
|
||||
std::string ref = "GET / HTTP/1.1\r\nConnection: Upgrade\r\nHost: localhost\r\nSec-WebSocket-Key: AAAAAAAAAAAAAAAAAAAAAA==\r\nSec-WebSocket-Version: 13\r\nUpgrade: websocket\r\nUser-Agent: foo\r\n\r\n";
|
||||
|
||||
|
||||
std::string ref = "GET / HTTP/1.1\r\nConnection: Upgrade\r\nFoo: Bar\r\nHost: localhost\r\nSec-WebSocket-Key: AAAAAAAAAAAAAAAAAAAAAA==\r\nSec-WebSocket-Version: 13\r\nUpgrade: websocket\r\nUser-Agent: foo\r\n\r\n";
|
||||
|
||||
std::stringstream output;
|
||||
|
||||
|
||||
client e;
|
||||
e.set_access_channels(websocketpp::log::alevel::none);
|
||||
e.set_error_channels(websocketpp::log::elevel::none);
|
||||
e.set_user_agent("foo");
|
||||
e.register_ostream(&output);
|
||||
|
||||
|
||||
client::connection_ptr con;
|
||||
websocketpp::lib::error_code ec;
|
||||
con = e.get_connection(uri, ec);
|
||||
con->append_header("Foo","Bar");
|
||||
e.connect(con);
|
||||
|
||||
|
||||
BOOST_CHECK_EQUAL(ref, output.str());
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE( set_max_message_size ) {
|
||||
std::string input = "GET / HTTP/1.1\r\nHost: www.example.com\r\nConnection: upgrade\r\nUpgrade: websocket\r\nSec-WebSocket-Version: 13\r\nSec-WebSocket-Key: dGhlIHNhbXBsZSBub25jZQ==\r\n\r\n";
|
||||
|
||||
// After the handshake, add a single frame with a message that is too long.
|
||||
char frame0[10] = {char(0x82), char(0x83), 0x00, 0x00, 0x00, 0x00, 0x01, 0x01, 0x01};
|
||||
input.append(frame0, 10);
|
||||
|
||||
std::string output = "HTTP/1.1 101 Switching Protocols\r\nConnection: upgrade\r\nSec-WebSocket-Accept: s3pPLMBiTxaQ9kYGzzhZRbK+xOo=\r\nServer: foo\r\nUpgrade: websocket\r\n\r\n";
|
||||
|
||||
// After the handshake, add a single frame with a close message with message too big
|
||||
// error code.
|
||||
char frame1[4] = {char(0x88), 0x19, 0x03, char(0xf1)};
|
||||
output.append(frame1, 4);
|
||||
output.append("A message was too large");
|
||||
|
||||
server s;
|
||||
s.set_user_agent("");
|
||||
s.set_validate_handler(bind(&validate_set_ua,&s,::_1));
|
||||
s.set_max_message_size(2);
|
||||
|
||||
BOOST_CHECK_EQUAL(run_server_test(s,input), output);
|
||||
}
|
||||
|
||||
// TODO: set max message size in client endpoint test case
|
||||
// TODO: set max message size mid connection test case
|
||||
// TODO: [maybe] set max message size in open handler
|
||||
|
||||
/*
|
||||
|
||||
BOOST_AUTO_TEST_CASE( user_reject_origin ) {
|
||||
std::string input = "GET / HTTP/1.1\r\nHost: www.example.com\r\nConnection: upgrade\r\nUpgrade: websocket\r\nSec-WebSocket-Version: 13\r\nSec-WebSocket-Key: dGhlIHNhbXBsZSBub25jZQ==\r\nOrigin: http://www.example2.com\r\n\r\n";
|
||||
std::string output = "HTTP/1.1 403 Forbidden\r\nServer: "+websocketpp::USER_AGENT+"\r\n\r\n";
|
||||
|
||||
|
||||
BOOST_CHECK(run_server_test(input) == output);
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE( basic_text_message ) {
|
||||
std::string input = "GET / HTTP/1.1\r\nHost: www.example.com\r\nConnection: upgrade\r\nUpgrade: websocket\r\nSec-WebSocket-Version: 13\r\nSec-WebSocket-Key: dGhlIHNhbXBsZSBub25jZQ==\r\nOrigin: http://www.example.com\r\n\r\n";
|
||||
|
||||
|
||||
unsigned char frames[8] = {0x82,0x82,0xFF,0xFF,0xFF,0xFF,0xD5,0xD5};
|
||||
input.append(reinterpret_cast<char*>(frames),8);
|
||||
|
||||
|
||||
std::string output = "HTTP/1.1 101 Switching Protocols\r\nConnection: Upgrade\r\nSec-WebSocket-Accept: s3pPLMBiTxaQ9kYGzzhZRbK+xOo=\r\nServer: "+websocketpp::USER_AGENT+"\r\nUpgrade: websocket\r\n\r\n**";
|
||||
|
||||
BOOST_CHECK( run_server_test(input) == output);
|
||||
|
||||
@@ -11,10 +11,10 @@
|
||||
* * 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
|
||||
*
|
||||
* 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;
|
||||
@@ -22,7 +22,7 @@
|
||||
* 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.
|
||||
*
|
||||
*
|
||||
*/
|
||||
|
||||
#include "connection_tu2.hpp"
|
||||
@@ -39,19 +39,19 @@ std::string run_server_test(std::string input) {
|
||||
std::string run_server_test(server & s, std::string input) {
|
||||
server::connection_ptr con;
|
||||
std::stringstream output;
|
||||
|
||||
|
||||
s.clear_access_channels(websocketpp::log::alevel::all);
|
||||
s.clear_error_channels(websocketpp::log::elevel::all);
|
||||
|
||||
|
||||
s.register_ostream(&output);
|
||||
|
||||
|
||||
con = s.get_connection();
|
||||
con->start();
|
||||
|
||||
|
||||
std::stringstream channel;
|
||||
|
||||
|
||||
channel << input;
|
||||
channel >> *con;
|
||||
|
||||
|
||||
return output.str();
|
||||
}
|
||||
}
|
||||
@@ -11,10 +11,10 @@
|
||||
* * 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
|
||||
*
|
||||
* 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;
|
||||
@@ -22,7 +22,7 @@
|
||||
* 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.
|
||||
*
|
||||
*
|
||||
*/
|
||||
|
||||
#include <iostream>
|
||||
@@ -36,7 +36,7 @@
|
||||
|
||||
typedef websocketpp::server<websocketpp::config::core> server;
|
||||
/// NOTE: the "server" config is being used for the client here because we don't
|
||||
/// want to pull in the real RNG. A better way to do this might be a custom
|
||||
/// want to pull in the real RNG. A better way to do this might be a custom
|
||||
/// client config with the RNG explicitly stubbed out.
|
||||
typedef websocketpp::client<websocketpp::config::core> client;
|
||||
typedef websocketpp::config::core::message_type::ptr message_ptr;
|
||||
@@ -47,4 +47,4 @@ using websocketpp::lib::bind;
|
||||
|
||||
void echo_func(server* s, websocketpp::connection_hdl hdl, message_ptr msg);
|
||||
std::string run_server_test(std::string input);
|
||||
std::string run_server_test(server & s, std::string input);
|
||||
std::string run_server_test(server & s, std::string input);
|
||||
+12
-12
@@ -11,10 +11,10 @@
|
||||
* * 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
|
||||
*
|
||||
* 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;
|
||||
@@ -22,7 +22,7 @@
|
||||
* 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.
|
||||
*
|
||||
*
|
||||
*/
|
||||
//#define BOOST_TEST_DYN_LINK
|
||||
#define BOOST_TEST_MODULE endpoint
|
||||
@@ -59,15 +59,15 @@ BOOST_AUTO_TEST_CASE( initialize_server_asio_external ) {
|
||||
|
||||
struct endpoint_extension {
|
||||
endpoint_extension() : extension_value(5) {}
|
||||
|
||||
|
||||
int extension_method() {
|
||||
return extension_value;
|
||||
}
|
||||
|
||||
|
||||
bool is_server() const {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
int extension_value;
|
||||
};
|
||||
|
||||
@@ -85,17 +85,17 @@ struct stub_config : public websocketpp::config::core {
|
||||
typedef core::elog_type elog_type;
|
||||
|
||||
typedef core::rng_type rng_type;
|
||||
|
||||
|
||||
typedef core::transport_type transport_type;
|
||||
|
||||
|
||||
typedef endpoint_extension endpoint_base;
|
||||
};
|
||||
|
||||
BOOST_AUTO_TEST_CASE( endpoint_extensions ) {
|
||||
websocketpp::server<stub_config> s;
|
||||
|
||||
|
||||
BOOST_CHECK( s.extension_value == 5 );
|
||||
BOOST_CHECK( s.extension_method() == 5 );
|
||||
|
||||
|
||||
BOOST_CHECK( s.is_server() == true );
|
||||
}
|
||||
@@ -11,10 +11,10 @@
|
||||
* * 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
|
||||
*
|
||||
* 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;
|
||||
@@ -22,7 +22,7 @@
|
||||
* 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.
|
||||
*
|
||||
*
|
||||
*/
|
||||
//#define BOOST_TEST_DYN_LINK
|
||||
#define BOOST_TEST_MODULE extension
|
||||
|
||||
@@ -11,10 +11,10 @@
|
||||
* * 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
|
||||
*
|
||||
* 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;
|
||||
@@ -22,7 +22,7 @@
|
||||
* 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.
|
||||
*
|
||||
*
|
||||
*/
|
||||
//#define BOOST_TEST_DYN_LINK
|
||||
#define BOOST_TEST_MODULE permessage_deflate
|
||||
@@ -83,8 +83,8 @@ BOOST_AUTO_TEST_CASE( enabled_starts_disabled ) {
|
||||
|
||||
BOOST_AUTO_TEST_CASE( negotiation_empty_attr ) {
|
||||
ext_vars v;
|
||||
|
||||
v.esp = v.exts.negotiate(v.attr);
|
||||
|
||||
v.esp = v.exts.negotiate(v.attr);
|
||||
BOOST_CHECK( v.exts.is_enabled() );
|
||||
BOOST_CHECK_EQUAL( v.esp.first, websocketpp::lib::error_code() );
|
||||
BOOST_CHECK_EQUAL( v.esp.second, "permessage-deflate");
|
||||
@@ -93,8 +93,8 @@ BOOST_AUTO_TEST_CASE( negotiation_empty_attr ) {
|
||||
BOOST_AUTO_TEST_CASE( negotiation_invalid_attr ) {
|
||||
ext_vars v;
|
||||
v.attr["foo"] = "bar";
|
||||
|
||||
v.esp = v.exts.negotiate(v.attr);
|
||||
|
||||
v.esp = v.exts.negotiate(v.attr);
|
||||
BOOST_CHECK( !v.exts.is_enabled() );
|
||||
BOOST_CHECK_EQUAL( v.esp.first, pmde::make_error_code(pmde::invalid_attributes) );
|
||||
BOOST_CHECK_EQUAL( v.esp.second, "");
|
||||
@@ -104,8 +104,8 @@ BOOST_AUTO_TEST_CASE( negotiation_invalid_attr ) {
|
||||
BOOST_AUTO_TEST_CASE( negotiate_s2c_no_context_takeover_invalid ) {
|
||||
ext_vars v;
|
||||
v.attr["s2c_no_context_takeover"] = "foo";
|
||||
|
||||
v.esp = v.exts.negotiate(v.attr);
|
||||
|
||||
v.esp = v.exts.negotiate(v.attr);
|
||||
BOOST_CHECK( !v.exts.is_enabled() );
|
||||
BOOST_CHECK_EQUAL( v.esp.first, pmde::make_error_code(pmde::invalid_attribute_value) );
|
||||
BOOST_CHECK_EQUAL( v.esp.second, "");
|
||||
@@ -114,8 +114,8 @@ BOOST_AUTO_TEST_CASE( negotiate_s2c_no_context_takeover_invalid ) {
|
||||
BOOST_AUTO_TEST_CASE( negotiate_s2c_no_context_takeover ) {
|
||||
ext_vars v;
|
||||
v.attr["s2c_no_context_takeover"] = "";
|
||||
|
||||
v.esp = v.exts.negotiate(v.attr);
|
||||
|
||||
v.esp = v.exts.negotiate(v.attr);
|
||||
BOOST_CHECK( v.exts.is_enabled() );
|
||||
BOOST_CHECK_EQUAL( v.esp.first, websocketpp::lib::error_code() );
|
||||
BOOST_CHECK_EQUAL( v.esp.second, "permessage-deflate; s2c_no_context_takeover");
|
||||
@@ -123,9 +123,9 @@ BOOST_AUTO_TEST_CASE( negotiate_s2c_no_context_takeover ) {
|
||||
|
||||
BOOST_AUTO_TEST_CASE( negotiate_s2c_no_context_takeover_server_initiated ) {
|
||||
ext_vars v;
|
||||
|
||||
|
||||
v.exts.enable_s2c_no_context_takeover();
|
||||
v.esp = v.exts.negotiate(v.attr);
|
||||
v.esp = v.exts.negotiate(v.attr);
|
||||
BOOST_CHECK( v.exts.is_enabled() );
|
||||
BOOST_CHECK_EQUAL( v.esp.first, websocketpp::lib::error_code() );
|
||||
BOOST_CHECK_EQUAL( v.esp.second, "permessage-deflate; s2c_no_context_takeover");
|
||||
@@ -135,8 +135,8 @@ BOOST_AUTO_TEST_CASE( negotiate_s2c_no_context_takeover_server_initiated ) {
|
||||
BOOST_AUTO_TEST_CASE( negotiate_c2s_no_context_takeover_invalid ) {
|
||||
ext_vars v;
|
||||
v.attr["c2s_no_context_takeover"] = "foo";
|
||||
|
||||
v.esp = v.exts.negotiate(v.attr);
|
||||
|
||||
v.esp = v.exts.negotiate(v.attr);
|
||||
BOOST_CHECK( !v.exts.is_enabled() );
|
||||
BOOST_CHECK_EQUAL( v.esp.first, pmde::make_error_code(pmde::invalid_attribute_value) );
|
||||
BOOST_CHECK_EQUAL( v.esp.second, "");
|
||||
@@ -145,8 +145,8 @@ BOOST_AUTO_TEST_CASE( negotiate_c2s_no_context_takeover_invalid ) {
|
||||
BOOST_AUTO_TEST_CASE( negotiate_c2s_no_context_takeover ) {
|
||||
ext_vars v;
|
||||
v.attr["c2s_no_context_takeover"] = "";
|
||||
|
||||
v.esp = v.exts.negotiate(v.attr);
|
||||
|
||||
v.esp = v.exts.negotiate(v.attr);
|
||||
BOOST_CHECK( v.exts.is_enabled() );
|
||||
BOOST_CHECK_EQUAL( v.esp.first, websocketpp::lib::error_code() );
|
||||
BOOST_CHECK_EQUAL( v.esp.second, "permessage-deflate; c2s_no_context_takeover");
|
||||
@@ -154,9 +154,9 @@ BOOST_AUTO_TEST_CASE( negotiate_c2s_no_context_takeover ) {
|
||||
|
||||
BOOST_AUTO_TEST_CASE( negotiate_c2s_no_context_takeover_server_initiated ) {
|
||||
ext_vars v;
|
||||
|
||||
|
||||
v.exts.enable_c2s_no_context_takeover();
|
||||
v.esp = v.exts.negotiate(v.attr);
|
||||
v.esp = v.exts.negotiate(v.attr);
|
||||
BOOST_CHECK( v.exts.is_enabled() );
|
||||
BOOST_CHECK_EQUAL( v.esp.first, websocketpp::lib::error_code() );
|
||||
BOOST_CHECK_EQUAL( v.esp.second, "permessage-deflate; c2s_no_context_takeover");
|
||||
@@ -166,7 +166,7 @@ BOOST_AUTO_TEST_CASE( negotiate_c2s_no_context_takeover_server_initiated ) {
|
||||
// Negotiate s2c_max_window_bits
|
||||
BOOST_AUTO_TEST_CASE( negotiate_s2c_max_window_bits_invalid ) {
|
||||
ext_vars v;
|
||||
|
||||
|
||||
std::vector<std::string> values;
|
||||
values.push_back("");
|
||||
values.push_back("foo");
|
||||
@@ -176,8 +176,8 @@ BOOST_AUTO_TEST_CASE( negotiate_s2c_max_window_bits_invalid ) {
|
||||
std::vector<std::string>::const_iterator it;
|
||||
for (it = values.begin(); it != values.end(); ++it) {
|
||||
v.attr["s2c_max_window_bits"] = *it;
|
||||
|
||||
v.esp = v.exts.negotiate(v.attr);
|
||||
|
||||
v.esp = v.exts.negotiate(v.attr);
|
||||
BOOST_CHECK( !v.exts.is_enabled() );
|
||||
BOOST_CHECK_EQUAL( v.esp.first, pmde::make_error_code(pmde::invalid_attribute_value) );
|
||||
BOOST_CHECK_EQUAL( v.esp.second, "");
|
||||
@@ -187,15 +187,15 @@ BOOST_AUTO_TEST_CASE( negotiate_s2c_max_window_bits_invalid ) {
|
||||
BOOST_AUTO_TEST_CASE( negotiate_s2c_max_window_bits_valid ) {
|
||||
ext_vars v;
|
||||
v.attr["s2c_max_window_bits"] = "8";
|
||||
|
||||
v.esp = v.exts.negotiate(v.attr);
|
||||
|
||||
v.esp = v.exts.negotiate(v.attr);
|
||||
BOOST_CHECK( v.exts.is_enabled() );
|
||||
BOOST_CHECK_EQUAL( v.esp.first, websocketpp::lib::error_code() );
|
||||
BOOST_CHECK_EQUAL( v.esp.second, "permessage-deflate; s2c_max_window_bits=8");
|
||||
|
||||
v.attr["s2c_max_window_bits"] = "15";
|
||||
|
||||
v.esp = v.exts.negotiate(v.attr);
|
||||
|
||||
v.esp = v.exts.negotiate(v.attr);
|
||||
BOOST_CHECK( v.exts.is_enabled() );
|
||||
BOOST_CHECK_EQUAL( v.esp.first, websocketpp::lib::error_code() );
|
||||
BOOST_CHECK_EQUAL( v.esp.second, "permessage-deflate");
|
||||
@@ -214,9 +214,9 @@ BOOST_AUTO_TEST_CASE( invalid_set_s2c_max_window_bits ) {
|
||||
BOOST_AUTO_TEST_CASE( negotiate_s2c_max_window_bits_decline ) {
|
||||
ext_vars v;
|
||||
v.attr["s2c_max_window_bits"] = "8";
|
||||
|
||||
|
||||
v.ec = v.exts.set_s2c_max_window_bits(15,pmd_mode::decline);
|
||||
v.esp = v.exts.negotiate(v.attr);
|
||||
v.esp = v.exts.negotiate(v.attr);
|
||||
BOOST_CHECK( v.exts.is_enabled() );
|
||||
BOOST_CHECK_EQUAL( v.ec, websocketpp::lib::error_code() );
|
||||
BOOST_CHECK_EQUAL( v.esp.first, websocketpp::lib::error_code() );
|
||||
@@ -226,7 +226,7 @@ BOOST_AUTO_TEST_CASE( negotiate_s2c_max_window_bits_decline ) {
|
||||
BOOST_AUTO_TEST_CASE( negotiate_s2c_max_window_bits_accept ) {
|
||||
ext_vars v;
|
||||
v.attr["s2c_max_window_bits"] = "8";
|
||||
|
||||
|
||||
v.ec = v.exts.set_s2c_max_window_bits(15,pmd_mode::accept);
|
||||
v.esp = v.exts.negotiate(v.attr);
|
||||
BOOST_CHECK( v.exts.is_enabled() );
|
||||
@@ -238,7 +238,7 @@ BOOST_AUTO_TEST_CASE( negotiate_s2c_max_window_bits_accept ) {
|
||||
BOOST_AUTO_TEST_CASE( negotiate_s2c_max_window_bits_largest ) {
|
||||
ext_vars v;
|
||||
v.attr["s2c_max_window_bits"] = "8";
|
||||
|
||||
|
||||
v.ec = v.exts.set_s2c_max_window_bits(15,pmd_mode::largest);
|
||||
v.esp = v.exts.negotiate(v.attr);
|
||||
BOOST_CHECK( v.exts.is_enabled() );
|
||||
@@ -250,7 +250,7 @@ BOOST_AUTO_TEST_CASE( negotiate_s2c_max_window_bits_largest ) {
|
||||
BOOST_AUTO_TEST_CASE( negotiate_s2c_max_window_bits_smallest ) {
|
||||
ext_vars v;
|
||||
v.attr["s2c_max_window_bits"] = "8";
|
||||
|
||||
|
||||
v.ec = v.exts.set_s2c_max_window_bits(15,pmd_mode::smallest);
|
||||
v.esp = v.exts.negotiate(v.attr);
|
||||
BOOST_CHECK( v.exts.is_enabled() );
|
||||
@@ -262,7 +262,7 @@ BOOST_AUTO_TEST_CASE( negotiate_s2c_max_window_bits_smallest ) {
|
||||
// Negotiate s2c_max_window_bits
|
||||
BOOST_AUTO_TEST_CASE( negotiate_c2s_max_window_bits_invalid ) {
|
||||
ext_vars v;
|
||||
|
||||
|
||||
std::vector<std::string> values;
|
||||
values.push_back("foo");
|
||||
values.push_back("7");
|
||||
@@ -271,8 +271,8 @@ BOOST_AUTO_TEST_CASE( negotiate_c2s_max_window_bits_invalid ) {
|
||||
std::vector<std::string>::const_iterator it;
|
||||
for (it = values.begin(); it != values.end(); ++it) {
|
||||
v.attr["c2s_max_window_bits"] = *it;
|
||||
|
||||
v.esp = v.exts.negotiate(v.attr);
|
||||
|
||||
v.esp = v.exts.negotiate(v.attr);
|
||||
BOOST_CHECK( !v.exts.is_enabled() );
|
||||
BOOST_CHECK_EQUAL( v.esp.first, pmde::make_error_code(pmde::invalid_attribute_value) );
|
||||
BOOST_CHECK_EQUAL( v.esp.second, "");
|
||||
@@ -283,19 +283,19 @@ BOOST_AUTO_TEST_CASE( negotiate_c2s_max_window_bits_valid ) {
|
||||
ext_vars v;
|
||||
|
||||
v.attr["c2s_max_window_bits"] = "";
|
||||
v.esp = v.exts.negotiate(v.attr);
|
||||
v.esp = v.exts.negotiate(v.attr);
|
||||
BOOST_CHECK( v.exts.is_enabled() );
|
||||
BOOST_CHECK_EQUAL( v.esp.first, websocketpp::lib::error_code() );
|
||||
BOOST_CHECK_EQUAL( v.esp.second, "permessage-deflate");
|
||||
|
||||
v.attr["c2s_max_window_bits"] = "8";
|
||||
v.esp = v.exts.negotiate(v.attr);
|
||||
v.esp = v.exts.negotiate(v.attr);
|
||||
BOOST_CHECK( v.exts.is_enabled() );
|
||||
BOOST_CHECK_EQUAL( v.esp.first, websocketpp::lib::error_code() );
|
||||
BOOST_CHECK_EQUAL( v.esp.second, "permessage-deflate; c2s_max_window_bits=8");
|
||||
|
||||
v.attr["c2s_max_window_bits"] = "15";
|
||||
v.esp = v.exts.negotiate(v.attr);
|
||||
v.esp = v.exts.negotiate(v.attr);
|
||||
BOOST_CHECK( v.exts.is_enabled() );
|
||||
BOOST_CHECK_EQUAL( v.esp.first, websocketpp::lib::error_code() );
|
||||
BOOST_CHECK_EQUAL( v.esp.second, "permessage-deflate");
|
||||
@@ -314,9 +314,9 @@ BOOST_AUTO_TEST_CASE( invalid_set_c2s_max_window_bits ) {
|
||||
BOOST_AUTO_TEST_CASE( negotiate_c2s_max_window_bits_decline ) {
|
||||
ext_vars v;
|
||||
v.attr["c2s_max_window_bits"] = "8";
|
||||
|
||||
|
||||
v.ec = v.exts.set_c2s_max_window_bits(8,pmd_mode::decline);
|
||||
v.esp = v.exts.negotiate(v.attr);
|
||||
v.esp = v.exts.negotiate(v.attr);
|
||||
BOOST_CHECK( v.exts.is_enabled() );
|
||||
BOOST_CHECK_EQUAL( v.ec, websocketpp::lib::error_code() );
|
||||
BOOST_CHECK_EQUAL( v.esp.first, websocketpp::lib::error_code() );
|
||||
@@ -326,7 +326,7 @@ BOOST_AUTO_TEST_CASE( negotiate_c2s_max_window_bits_decline ) {
|
||||
BOOST_AUTO_TEST_CASE( negotiate_c2s_max_window_bits_accept ) {
|
||||
ext_vars v;
|
||||
v.attr["c2s_max_window_bits"] = "8";
|
||||
|
||||
|
||||
v.ec = v.exts.set_c2s_max_window_bits(15,pmd_mode::accept);
|
||||
v.esp = v.exts.negotiate(v.attr);
|
||||
BOOST_CHECK( v.exts.is_enabled() );
|
||||
@@ -338,7 +338,7 @@ BOOST_AUTO_TEST_CASE( negotiate_c2s_max_window_bits_accept ) {
|
||||
BOOST_AUTO_TEST_CASE( negotiate_c2s_max_window_bits_largest ) {
|
||||
ext_vars v;
|
||||
v.attr["c2s_max_window_bits"] = "8";
|
||||
|
||||
|
||||
v.ec = v.exts.set_c2s_max_window_bits(15,pmd_mode::largest);
|
||||
v.esp = v.exts.negotiate(v.attr);
|
||||
BOOST_CHECK( v.exts.is_enabled() );
|
||||
@@ -350,7 +350,7 @@ BOOST_AUTO_TEST_CASE( negotiate_c2s_max_window_bits_largest ) {
|
||||
BOOST_AUTO_TEST_CASE( negotiate_c2s_max_window_bits_smallest ) {
|
||||
ext_vars v;
|
||||
v.attr["c2s_max_window_bits"] = "8";
|
||||
|
||||
|
||||
v.ec = v.exts.set_c2s_max_window_bits(15,pmd_mode::smallest);
|
||||
v.esp = v.exts.negotiate(v.attr);
|
||||
BOOST_CHECK( v.exts.is_enabled() );
|
||||
@@ -363,11 +363,11 @@ BOOST_AUTO_TEST_CASE( negotiate_c2s_max_window_bits_smallest ) {
|
||||
// Combinations with 2
|
||||
BOOST_AUTO_TEST_CASE( negotiate_two_client_initiated1 ) {
|
||||
ext_vars v;
|
||||
|
||||
|
||||
v.attr["s2c_no_context_takeover"] = "";
|
||||
v.attr["c2s_no_context_takeover"] = "";
|
||||
|
||||
v.esp = v.exts.negotiate(v.attr);
|
||||
v.esp = v.exts.negotiate(v.attr);
|
||||
BOOST_CHECK( v.exts.is_enabled() );
|
||||
BOOST_CHECK_EQUAL( v.esp.first, websocketpp::lib::error_code() );
|
||||
BOOST_CHECK_EQUAL( v.esp.second, "permessage-deflate; s2c_no_context_takeover; c2s_no_context_takeover");
|
||||
@@ -375,11 +375,11 @@ BOOST_AUTO_TEST_CASE( negotiate_two_client_initiated1 ) {
|
||||
|
||||
BOOST_AUTO_TEST_CASE( negotiate_two_client_initiated2 ) {
|
||||
ext_vars v;
|
||||
|
||||
|
||||
v.attr["s2c_no_context_takeover"] = "";
|
||||
v.attr["s2c_max_window_bits"] = "10";
|
||||
|
||||
v.esp = v.exts.negotiate(v.attr);
|
||||
v.esp = v.exts.negotiate(v.attr);
|
||||
BOOST_CHECK( v.exts.is_enabled() );
|
||||
BOOST_CHECK_EQUAL( v.esp.first, websocketpp::lib::error_code() );
|
||||
BOOST_CHECK_EQUAL( v.esp.second, "permessage-deflate; s2c_no_context_takeover; s2c_max_window_bits=10");
|
||||
@@ -387,11 +387,11 @@ BOOST_AUTO_TEST_CASE( negotiate_two_client_initiated2 ) {
|
||||
|
||||
BOOST_AUTO_TEST_CASE( negotiate_two_client_initiated3 ) {
|
||||
ext_vars v;
|
||||
|
||||
|
||||
v.attr["s2c_no_context_takeover"] = "";
|
||||
v.attr["c2s_max_window_bits"] = "10";
|
||||
|
||||
v.esp = v.exts.negotiate(v.attr);
|
||||
v.esp = v.exts.negotiate(v.attr);
|
||||
BOOST_CHECK( v.exts.is_enabled() );
|
||||
BOOST_CHECK_EQUAL( v.esp.first, websocketpp::lib::error_code() );
|
||||
BOOST_CHECK_EQUAL( v.esp.second, "permessage-deflate; s2c_no_context_takeover; c2s_max_window_bits=10");
|
||||
@@ -399,11 +399,11 @@ BOOST_AUTO_TEST_CASE( negotiate_two_client_initiated3 ) {
|
||||
|
||||
BOOST_AUTO_TEST_CASE( negotiate_two_client_initiated4 ) {
|
||||
ext_vars v;
|
||||
|
||||
|
||||
v.attr["c2s_no_context_takeover"] = "";
|
||||
v.attr["s2c_max_window_bits"] = "10";
|
||||
|
||||
v.esp = v.exts.negotiate(v.attr);
|
||||
v.esp = v.exts.negotiate(v.attr);
|
||||
BOOST_CHECK( v.exts.is_enabled() );
|
||||
BOOST_CHECK_EQUAL( v.esp.first, websocketpp::lib::error_code() );
|
||||
BOOST_CHECK_EQUAL( v.esp.second, "permessage-deflate; c2s_no_context_takeover; s2c_max_window_bits=10");
|
||||
@@ -411,11 +411,11 @@ BOOST_AUTO_TEST_CASE( negotiate_two_client_initiated4 ) {
|
||||
|
||||
BOOST_AUTO_TEST_CASE( negotiate_two_client_initiated5 ) {
|
||||
ext_vars v;
|
||||
|
||||
|
||||
v.attr["c2s_no_context_takeover"] = "";
|
||||
v.attr["c2s_max_window_bits"] = "10";
|
||||
|
||||
v.esp = v.exts.negotiate(v.attr);
|
||||
v.esp = v.exts.negotiate(v.attr);
|
||||
BOOST_CHECK( v.exts.is_enabled() );
|
||||
BOOST_CHECK_EQUAL( v.esp.first, websocketpp::lib::error_code() );
|
||||
BOOST_CHECK_EQUAL( v.esp.second, "permessage-deflate; c2s_no_context_takeover; c2s_max_window_bits=10");
|
||||
@@ -423,11 +423,11 @@ BOOST_AUTO_TEST_CASE( negotiate_two_client_initiated5 ) {
|
||||
|
||||
BOOST_AUTO_TEST_CASE( negotiate_two_client_initiated6 ) {
|
||||
ext_vars v;
|
||||
|
||||
|
||||
v.attr["s2c_max_window_bits"] = "10";
|
||||
v.attr["c2s_max_window_bits"] = "10";
|
||||
|
||||
v.esp = v.exts.negotiate(v.attr);
|
||||
v.esp = v.exts.negotiate(v.attr);
|
||||
BOOST_CHECK( v.exts.is_enabled() );
|
||||
BOOST_CHECK_EQUAL( v.esp.first, websocketpp::lib::error_code() );
|
||||
BOOST_CHECK_EQUAL( v.esp.second, "permessage-deflate; s2c_max_window_bits=10; c2s_max_window_bits=10");
|
||||
@@ -435,12 +435,12 @@ BOOST_AUTO_TEST_CASE( negotiate_two_client_initiated6 ) {
|
||||
|
||||
BOOST_AUTO_TEST_CASE( negotiate_three_client_initiated1 ) {
|
||||
ext_vars v;
|
||||
|
||||
|
||||
v.attr["s2c_no_context_takeover"] = "";
|
||||
v.attr["c2s_no_context_takeover"] = "";
|
||||
v.attr["s2c_max_window_bits"] = "10";
|
||||
|
||||
v.esp = v.exts.negotiate(v.attr);
|
||||
v.esp = v.exts.negotiate(v.attr);
|
||||
BOOST_CHECK( v.exts.is_enabled() );
|
||||
BOOST_CHECK_EQUAL( v.esp.first, websocketpp::lib::error_code() );
|
||||
BOOST_CHECK_EQUAL( v.esp.second, "permessage-deflate; s2c_no_context_takeover; c2s_no_context_takeover; s2c_max_window_bits=10");
|
||||
@@ -448,12 +448,12 @@ BOOST_AUTO_TEST_CASE( negotiate_three_client_initiated1 ) {
|
||||
|
||||
BOOST_AUTO_TEST_CASE( negotiate_three_client_initiated2 ) {
|
||||
ext_vars v;
|
||||
|
||||
|
||||
v.attr["s2c_no_context_takeover"] = "";
|
||||
v.attr["c2s_no_context_takeover"] = "";
|
||||
v.attr["c2s_max_window_bits"] = "10";
|
||||
|
||||
v.esp = v.exts.negotiate(v.attr);
|
||||
v.esp = v.exts.negotiate(v.attr);
|
||||
BOOST_CHECK( v.exts.is_enabled() );
|
||||
BOOST_CHECK_EQUAL( v.esp.first, websocketpp::lib::error_code() );
|
||||
BOOST_CHECK_EQUAL( v.esp.second, "permessage-deflate; s2c_no_context_takeover; c2s_no_context_takeover; c2s_max_window_bits=10");
|
||||
@@ -461,12 +461,12 @@ BOOST_AUTO_TEST_CASE( negotiate_three_client_initiated2 ) {
|
||||
|
||||
BOOST_AUTO_TEST_CASE( negotiate_three_client_initiated3 ) {
|
||||
ext_vars v;
|
||||
|
||||
|
||||
v.attr["s2c_no_context_takeover"] = "";
|
||||
v.attr["s2c_max_window_bits"] = "10";
|
||||
v.attr["c2s_max_window_bits"] = "10";
|
||||
|
||||
v.esp = v.exts.negotiate(v.attr);
|
||||
v.esp = v.exts.negotiate(v.attr);
|
||||
BOOST_CHECK( v.exts.is_enabled() );
|
||||
BOOST_CHECK_EQUAL( v.esp.first, websocketpp::lib::error_code() );
|
||||
BOOST_CHECK_EQUAL( v.esp.second, "permessage-deflate; s2c_no_context_takeover; s2c_max_window_bits=10; c2s_max_window_bits=10");
|
||||
@@ -474,12 +474,12 @@ BOOST_AUTO_TEST_CASE( negotiate_three_client_initiated3 ) {
|
||||
|
||||
BOOST_AUTO_TEST_CASE( negotiate_three_client_initiated4 ) {
|
||||
ext_vars v;
|
||||
|
||||
|
||||
v.attr["c2s_no_context_takeover"] = "";
|
||||
v.attr["s2c_max_window_bits"] = "10";
|
||||
v.attr["c2s_max_window_bits"] = "10";
|
||||
|
||||
v.esp = v.exts.negotiate(v.attr);
|
||||
v.esp = v.exts.negotiate(v.attr);
|
||||
BOOST_CHECK( v.exts.is_enabled() );
|
||||
BOOST_CHECK_EQUAL( v.esp.first, websocketpp::lib::error_code() );
|
||||
BOOST_CHECK_EQUAL( v.esp.second, "permessage-deflate; c2s_no_context_takeover; s2c_max_window_bits=10; c2s_max_window_bits=10");
|
||||
@@ -487,13 +487,13 @@ BOOST_AUTO_TEST_CASE( negotiate_three_client_initiated4 ) {
|
||||
|
||||
BOOST_AUTO_TEST_CASE( negotiate_four_client_initiated ) {
|
||||
ext_vars v;
|
||||
|
||||
|
||||
v.attr["s2c_no_context_takeover"] = "";
|
||||
v.attr["c2s_no_context_takeover"] = "";
|
||||
v.attr["s2c_max_window_bits"] = "10";
|
||||
v.attr["c2s_max_window_bits"] = "10";
|
||||
|
||||
v.esp = v.exts.negotiate(v.attr);
|
||||
v.esp = v.exts.negotiate(v.attr);
|
||||
BOOST_CHECK( v.exts.is_enabled() );
|
||||
BOOST_CHECK_EQUAL( v.esp.first, websocketpp::lib::error_code() );
|
||||
BOOST_CHECK_EQUAL( v.esp.second, "permessage-deflate; s2c_no_context_takeover; c2s_no_context_takeover; s2c_max_window_bits=10; c2s_max_window_bits=10");
|
||||
@@ -503,16 +503,16 @@ BOOST_AUTO_TEST_CASE( negotiate_four_client_initiated ) {
|
||||
/*
|
||||
BOOST_AUTO_TEST_CASE( compress_data ) {
|
||||
ext_vars v;
|
||||
|
||||
|
||||
std::string in = "Hello";
|
||||
std::string out;
|
||||
std::string in2;
|
||||
std::string out2;
|
||||
|
||||
|
||||
v.exts.init();
|
||||
|
||||
v.ec = v.exts.compress(in,out);
|
||||
|
||||
|
||||
std::cout << "in : " << websocketpp::utility::to_hex(in) << std::endl;
|
||||
BOOST_CHECK_EQUAL( v.ec, websocketpp::lib::error_code() );
|
||||
std::cout << "out: " << websocketpp::utility::to_hex(out) << std::endl;
|
||||
@@ -520,7 +520,7 @@ BOOST_AUTO_TEST_CASE( compress_data ) {
|
||||
in2 = out;
|
||||
|
||||
v.ec = v.exts.decompress(reinterpret_cast<const uint8_t *>(in2.data()),in2.size(),out2);
|
||||
|
||||
|
||||
BOOST_CHECK_EQUAL( v.ec, websocketpp::lib::error_code() );
|
||||
std::cout << "out: " << websocketpp::utility::to_hex(out2) << std::endl;
|
||||
BOOST_CHECK_EQUAL( out, out2 );
|
||||
@@ -528,16 +528,16 @@ BOOST_AUTO_TEST_CASE( compress_data ) {
|
||||
|
||||
BOOST_AUTO_TEST_CASE( decompress_data ) {
|
||||
ext_vars v;
|
||||
|
||||
|
||||
uint8_t in[12] = {0xf2, 0x48, 0xcd, 0xc9, 0xc9, 0x07, 0x00, 0x00, 0x00, 0xff, 0xff};
|
||||
std::string out;
|
||||
|
||||
|
||||
v.exts.init();
|
||||
|
||||
v.ec = v.exts.decompress(in,12,out);
|
||||
|
||||
|
||||
BOOST_CHECK_EQUAL( v.ec, websocketpp::lib::error_code() );
|
||||
std::cout << "out: " << websocketpp::utility::to_hex(out) << std::endl;
|
||||
BOOST_CHECK( false );
|
||||
}
|
||||
*/
|
||||
*/
|
||||
+236
-189
@@ -11,10 +11,10 @@
|
||||
* * 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
|
||||
*
|
||||
* 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;
|
||||
@@ -22,7 +22,7 @@
|
||||
* 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.
|
||||
*
|
||||
*
|
||||
*/
|
||||
//#define BOOST_TEST_DYN_LINK
|
||||
#define BOOST_TEST_MODULE http_parser
|
||||
@@ -35,7 +35,7 @@
|
||||
|
||||
BOOST_AUTO_TEST_CASE( is_token_char ) {
|
||||
// Valid characters
|
||||
|
||||
|
||||
// misc
|
||||
BOOST_CHECK( websocketpp::http::is_token_char('!') );
|
||||
BOOST_CHECK( websocketpp::http::is_token_char('#') );
|
||||
@@ -51,29 +51,29 @@ BOOST_AUTO_TEST_CASE( is_token_char ) {
|
||||
BOOST_CHECK( websocketpp::http::is_token_char('_') );
|
||||
BOOST_CHECK( websocketpp::http::is_token_char('`') );
|
||||
BOOST_CHECK( websocketpp::http::is_token_char('~') );
|
||||
|
||||
|
||||
// numbers
|
||||
for (int i = 0x30; i < 0x3a; i++) {
|
||||
BOOST_CHECK( websocketpp::http::is_token_char((unsigned char)(i)) );
|
||||
}
|
||||
|
||||
|
||||
// upper
|
||||
for (int i = 0x41; i < 0x5b; i++) {
|
||||
BOOST_CHECK( websocketpp::http::is_token_char((unsigned char)(i)) );
|
||||
}
|
||||
|
||||
|
||||
// lower
|
||||
for (int i = 0x61; i < 0x7b; i++) {
|
||||
BOOST_CHECK( websocketpp::http::is_token_char((unsigned char)(i)) );
|
||||
}
|
||||
|
||||
|
||||
// invalid characters
|
||||
|
||||
|
||||
// lower unprintable
|
||||
for (int i = 0; i < 33; i++) {
|
||||
BOOST_CHECK( !websocketpp::http::is_token_char((unsigned char)(i)) );
|
||||
}
|
||||
|
||||
|
||||
// misc
|
||||
BOOST_CHECK( !websocketpp::http::is_token_char('(') );
|
||||
BOOST_CHECK( !websocketpp::http::is_token_char(')') );
|
||||
@@ -92,12 +92,12 @@ BOOST_AUTO_TEST_CASE( is_token_char ) {
|
||||
BOOST_CHECK( !websocketpp::http::is_token_char('=') );
|
||||
BOOST_CHECK( !websocketpp::http::is_token_char('{') );
|
||||
BOOST_CHECK( !websocketpp::http::is_token_char('}') );
|
||||
|
||||
|
||||
// upper unprintable and out of ascii range
|
||||
for (int i = 127; i < 256; i++) {
|
||||
BOOST_CHECK( !websocketpp::http::is_token_char((unsigned char)(i)) );
|
||||
}
|
||||
|
||||
|
||||
// is not
|
||||
BOOST_CHECK( !websocketpp::http::is_not_token_char('!') );
|
||||
BOOST_CHECK( websocketpp::http::is_not_token_char('(') );
|
||||
@@ -130,7 +130,7 @@ BOOST_AUTO_TEST_CASE( extract_quoted_string ) {
|
||||
std::string d5 = "foo";
|
||||
|
||||
std::pair<std::string,std::string::const_iterator> ret;
|
||||
|
||||
|
||||
using websocketpp::http::parser::extract_quoted_string;
|
||||
|
||||
ret = extract_quoted_string(d1.begin(),d1.end());
|
||||
@@ -158,7 +158,7 @@ BOOST_AUTO_TEST_CASE( extract_all_lws ) {
|
||||
std::string d1 = " foo bar";
|
||||
d1.append(1,char(9));
|
||||
d1.append("baz\r\n d\r\n \r\n e\r\nf");
|
||||
|
||||
|
||||
std::string::const_iterator ret;
|
||||
|
||||
ret = websocketpp::http::parser::extract_all_lws(d1.begin(),d1.end());
|
||||
@@ -227,33 +227,33 @@ BOOST_AUTO_TEST_CASE( extract_parameters ) {
|
||||
websocketpp::http::parameter_list p;
|
||||
websocketpp::http::attribute_list a;
|
||||
std::string::const_iterator it;
|
||||
|
||||
|
||||
using websocketpp::http::parser::extract_parameters;
|
||||
|
||||
it = extract_parameters(s1.begin(),s1.end(),p);
|
||||
BOOST_CHECK( it == s1.begin() );
|
||||
|
||||
|
||||
p.clear();
|
||||
it = extract_parameters(s2.begin(),s2.end(),p);
|
||||
BOOST_CHECK( it == s2.end() );
|
||||
BOOST_CHECK_EQUAL( p.size(), 1 );
|
||||
BOOST_CHECK( p[0].first == "foo" );
|
||||
BOOST_CHECK_EQUAL( p[0].second.size(), 0 );
|
||||
|
||||
|
||||
p.clear();
|
||||
it = extract_parameters(s3.begin(),s3.end(),p);
|
||||
BOOST_CHECK( it == s3.begin()+5 );
|
||||
BOOST_CHECK_EQUAL( p.size(), 1 );
|
||||
BOOST_CHECK( p[0].first == "foo" );
|
||||
BOOST_CHECK_EQUAL( p[0].second.size(), 0 );
|
||||
|
||||
|
||||
p.clear();
|
||||
it = extract_parameters(s4.begin(),s4.end(),p);
|
||||
BOOST_CHECK( it == s4.end() );
|
||||
BOOST_CHECK_EQUAL( p.size(), 1 );
|
||||
BOOST_CHECK( p[0].first == "foo" );
|
||||
BOOST_CHECK_EQUAL( p[0].second.size(), 0 );
|
||||
|
||||
|
||||
p.clear();
|
||||
it = extract_parameters(s5.begin(),s5.end(),p);
|
||||
BOOST_CHECK( it == s5.end() );
|
||||
@@ -262,7 +262,7 @@ BOOST_AUTO_TEST_CASE( extract_parameters ) {
|
||||
BOOST_CHECK_EQUAL( p[0].second.size(), 0 );
|
||||
BOOST_CHECK( p[1].first == "bar" );
|
||||
BOOST_CHECK_EQUAL( p[1].second.size(), 0 );
|
||||
|
||||
|
||||
p.clear();
|
||||
it = extract_parameters(s6.begin(),s6.end(),p);
|
||||
BOOST_CHECK( it == s6.end() );
|
||||
@@ -272,7 +272,7 @@ BOOST_AUTO_TEST_CASE( extract_parameters ) {
|
||||
BOOST_CHECK_EQUAL( a.size(), 1 );
|
||||
BOOST_CHECK( a.find("bar") != a.end() );
|
||||
BOOST_CHECK_EQUAL( a.find("bar")->second, "" );
|
||||
|
||||
|
||||
p.clear();
|
||||
it = extract_parameters(s7.begin(),s7.end(),p);
|
||||
BOOST_CHECK( it == s7.end() );
|
||||
@@ -285,7 +285,7 @@ BOOST_AUTO_TEST_CASE( extract_parameters ) {
|
||||
BOOST_CHECK( p[1].first == "bar" );
|
||||
a = p[1].second;
|
||||
BOOST_CHECK_EQUAL( a.size(), 0 );
|
||||
|
||||
|
||||
p.clear();
|
||||
it = extract_parameters(s8.begin(),s8.end(),p);
|
||||
BOOST_CHECK( it == s8.end() );
|
||||
@@ -297,7 +297,7 @@ BOOST_AUTO_TEST_CASE( extract_parameters ) {
|
||||
BOOST_CHECK_EQUAL( a.find("bar")->second, "" );
|
||||
BOOST_CHECK( a.find("baz") != a.end() );
|
||||
BOOST_CHECK_EQUAL( a.find("baz")->second, "" );
|
||||
|
||||
|
||||
p.clear();
|
||||
it = extract_parameters(s9.begin(),s9.end(),p);
|
||||
BOOST_CHECK( it == s9.end() );
|
||||
@@ -307,7 +307,7 @@ BOOST_AUTO_TEST_CASE( extract_parameters ) {
|
||||
BOOST_CHECK_EQUAL( a.size(), 1 );
|
||||
BOOST_CHECK( a.find("bar") != a.end() );
|
||||
BOOST_CHECK_EQUAL( a.find("bar")->second, "baz" );
|
||||
|
||||
|
||||
p.clear();
|
||||
it = extract_parameters(s10.begin(),s10.end(),p);
|
||||
BOOST_CHECK( it == s10.end() );
|
||||
@@ -319,7 +319,7 @@ BOOST_AUTO_TEST_CASE( extract_parameters ) {
|
||||
BOOST_CHECK_EQUAL( a.find("bar")->second, "baz" );
|
||||
BOOST_CHECK( a.find("boo") != a.end() );
|
||||
BOOST_CHECK_EQUAL( a.find("boo")->second, "" );
|
||||
|
||||
|
||||
p.clear();
|
||||
it = extract_parameters(s11.begin(),s11.end(),p);
|
||||
BOOST_CHECK( it == s11.end() );
|
||||
@@ -333,7 +333,7 @@ BOOST_AUTO_TEST_CASE( extract_parameters ) {
|
||||
BOOST_CHECK_EQUAL( a.find("boo")->second, "" );
|
||||
a = p[1].second;
|
||||
BOOST_CHECK_EQUAL( a.size(), 0 );
|
||||
|
||||
|
||||
p.clear();
|
||||
it = extract_parameters(s12.begin(),s12.end(),p);
|
||||
BOOST_CHECK( it == s12.end() );
|
||||
@@ -343,7 +343,7 @@ BOOST_AUTO_TEST_CASE( extract_parameters ) {
|
||||
BOOST_CHECK_EQUAL( a.size(), 1 );
|
||||
BOOST_CHECK( a.find("bar") != a.end() );
|
||||
BOOST_CHECK_EQUAL( a.find("bar")->second, "a b c" );
|
||||
|
||||
|
||||
p.clear();
|
||||
it = extract_parameters(s13.begin(),s13.end(),p);
|
||||
BOOST_CHECK( it == s13.end() );
|
||||
@@ -355,9 +355,29 @@ BOOST_AUTO_TEST_CASE( extract_parameters ) {
|
||||
BOOST_CHECK_EQUAL( a.find("bar")->second, "a \"b\" c" );
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE( strip_lws ) {
|
||||
std::string test1 = "foo";
|
||||
std::string test2 = " foo ";
|
||||
std::string test3 = "foo ";
|
||||
std::string test4 = " foo";
|
||||
std::string test5 = " foo ";
|
||||
std::string test6 = " \r\n foo ";
|
||||
std::string test7 = " \t foo ";
|
||||
std::string test8 = " \t ";
|
||||
|
||||
BOOST_CHECK_EQUAL( websocketpp::http::parser::strip_lws(test1), "foo" );
|
||||
BOOST_CHECK_EQUAL( websocketpp::http::parser::strip_lws(test2), "foo" );
|
||||
BOOST_CHECK_EQUAL( websocketpp::http::parser::strip_lws(test3), "foo" );
|
||||
BOOST_CHECK_EQUAL( websocketpp::http::parser::strip_lws(test4), "foo" );
|
||||
BOOST_CHECK_EQUAL( websocketpp::http::parser::strip_lws(test5), "foo" );
|
||||
BOOST_CHECK_EQUAL( websocketpp::http::parser::strip_lws(test6), "foo" );
|
||||
BOOST_CHECK_EQUAL( websocketpp::http::parser::strip_lws(test7), "foo" );
|
||||
BOOST_CHECK_EQUAL( websocketpp::http::parser::strip_lws(test8), "" );
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE( case_insensitive_headers ) {
|
||||
websocketpp::http::parser::parser r;
|
||||
|
||||
|
||||
r.replace_header("foo","bar");
|
||||
|
||||
BOOST_CHECK_EQUAL( r.get_header("foo"), "bar" );
|
||||
@@ -367,89 +387,89 @@ BOOST_AUTO_TEST_CASE( case_insensitive_headers ) {
|
||||
|
||||
BOOST_AUTO_TEST_CASE( case_insensitive_headers_overwrite ) {
|
||||
websocketpp::http::parser::parser r;
|
||||
|
||||
|
||||
r.replace_header("foo","bar");
|
||||
|
||||
BOOST_CHECK_EQUAL( r.get_header("foo"), "bar" );
|
||||
BOOST_CHECK_EQUAL( r.get_header("Foo"), "bar" );
|
||||
|
||||
|
||||
r.replace_header("Foo","baz");
|
||||
|
||||
|
||||
BOOST_CHECK_EQUAL( r.get_header("foo"), "baz" );
|
||||
BOOST_CHECK_EQUAL( r.get_header("Foo"), "baz" );
|
||||
|
||||
|
||||
r.remove_header("FoO");
|
||||
|
||||
|
||||
BOOST_CHECK_EQUAL( r.get_header("foo"), "" );
|
||||
BOOST_CHECK_EQUAL( r.get_header("Foo"), "" );
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE( blank_consume ) {
|
||||
websocketpp::http::parser::request r;
|
||||
|
||||
|
||||
std::string raw = "";
|
||||
|
||||
|
||||
bool exception = false;
|
||||
|
||||
|
||||
try {
|
||||
r.consume(raw.c_str(),raw.size());
|
||||
} catch (...) {
|
||||
exception = true;
|
||||
}
|
||||
|
||||
|
||||
BOOST_CHECK( exception == false );
|
||||
BOOST_CHECK( r.ready() == false );
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE( blank_request ) {
|
||||
websocketpp::http::parser::request r;
|
||||
|
||||
|
||||
std::string raw = "\r\n\r\n";
|
||||
|
||||
|
||||
bool exception = false;
|
||||
|
||||
|
||||
try {
|
||||
r.consume(raw.c_str(),raw.size());
|
||||
} catch (...) {
|
||||
exception = true;
|
||||
}
|
||||
|
||||
|
||||
BOOST_CHECK( exception == true );
|
||||
BOOST_CHECK( r.ready() == false );
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE( bad_request_no_host ) {
|
||||
websocketpp::http::parser::request r;
|
||||
|
||||
|
||||
std::string raw = "GET / HTTP/1.1\r\n\r\n";
|
||||
|
||||
|
||||
bool exception = false;
|
||||
|
||||
|
||||
try {
|
||||
r.consume(raw.c_str(),raw.size());
|
||||
} catch (...) {
|
||||
exception = true;
|
||||
}
|
||||
|
||||
|
||||
BOOST_CHECK( exception == true );
|
||||
BOOST_CHECK( r.ready() == false );
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE( basic_request ) {
|
||||
websocketpp::http::parser::request r;
|
||||
|
||||
|
||||
std::string raw = "GET / HTTP/1.1\r\nHost: www.example.com\r\n\r\n";
|
||||
|
||||
|
||||
bool exception = false;
|
||||
size_t pos = 0;
|
||||
|
||||
|
||||
try {
|
||||
pos = r.consume(raw.c_str(),raw.size());
|
||||
} catch (std::exception &e) {
|
||||
exception = true;
|
||||
std::cout << e.what() << std::endl;
|
||||
}
|
||||
|
||||
|
||||
BOOST_CHECK( exception == false );
|
||||
BOOST_CHECK( pos == 41 );
|
||||
BOOST_CHECK( r.ready() == true );
|
||||
@@ -461,18 +481,18 @@ BOOST_AUTO_TEST_CASE( basic_request ) {
|
||||
|
||||
BOOST_AUTO_TEST_CASE( trailing_body_characters ) {
|
||||
websocketpp::http::parser::request r;
|
||||
|
||||
|
||||
std::string raw = "GET / HTTP/1.1\r\nHost: www.example.com\r\n\r\na";
|
||||
|
||||
|
||||
bool exception = false;
|
||||
size_t pos = 0;
|
||||
|
||||
|
||||
try {
|
||||
pos = r.consume(raw.c_str(),raw.size());
|
||||
} catch (...) {
|
||||
exception = true;
|
||||
}
|
||||
|
||||
|
||||
BOOST_CHECK( exception == false );
|
||||
BOOST_CHECK( pos == 41 );
|
||||
BOOST_CHECK( r.ready() == true );
|
||||
@@ -484,13 +504,13 @@ BOOST_AUTO_TEST_CASE( trailing_body_characters ) {
|
||||
|
||||
BOOST_AUTO_TEST_CASE( basic_split1 ) {
|
||||
websocketpp::http::parser::request r;
|
||||
|
||||
|
||||
std::string raw = "GET / HTTP/1.1\r\n";
|
||||
std::string raw2 = "Host: www.example.com\r\n\r\na";
|
||||
|
||||
|
||||
bool exception = false;
|
||||
size_t pos = 0;
|
||||
|
||||
|
||||
try {
|
||||
pos += r.consume(raw.c_str(),raw.size());
|
||||
pos += r.consume(raw2.c_str(),raw2.size());
|
||||
@@ -498,7 +518,7 @@ BOOST_AUTO_TEST_CASE( basic_split1 ) {
|
||||
exception = true;
|
||||
std::cout << e.what() << std::endl;
|
||||
}
|
||||
|
||||
|
||||
BOOST_CHECK( exception == false );
|
||||
BOOST_CHECK( pos == 41 );
|
||||
BOOST_CHECK( r.ready() == true );
|
||||
@@ -510,13 +530,13 @@ BOOST_AUTO_TEST_CASE( basic_split1 ) {
|
||||
|
||||
BOOST_AUTO_TEST_CASE( basic_split2 ) {
|
||||
websocketpp::http::parser::request r;
|
||||
|
||||
|
||||
std::string raw = "GET / HTTP/1.1\r\nHost: www.example.com\r";
|
||||
std::string raw2 = "\n\r\na";
|
||||
|
||||
|
||||
bool exception = false;
|
||||
size_t pos = 0;
|
||||
|
||||
|
||||
try {
|
||||
pos += r.consume(raw.c_str(),raw.size());
|
||||
pos += r.consume(raw2.c_str(),raw2.size());
|
||||
@@ -524,7 +544,7 @@ BOOST_AUTO_TEST_CASE( basic_split2 ) {
|
||||
exception = true;
|
||||
std::cout << e.what() << std::endl;
|
||||
}
|
||||
|
||||
|
||||
BOOST_CHECK( exception == false );
|
||||
BOOST_CHECK( pos == 41 );
|
||||
BOOST_CHECK( r.ready() == true );
|
||||
@@ -536,12 +556,12 @@ BOOST_AUTO_TEST_CASE( basic_split2 ) {
|
||||
|
||||
BOOST_AUTO_TEST_CASE( max_header_len ) {
|
||||
websocketpp::http::parser::request r;
|
||||
|
||||
|
||||
std::string raw(websocketpp::http::max_header_size+1,'*');
|
||||
|
||||
|
||||
bool exception = false;
|
||||
size_t pos = 0;
|
||||
|
||||
|
||||
try {
|
||||
pos += r.consume(raw.c_str(),raw.size());
|
||||
} catch (const websocketpp::http::exception& e) {
|
||||
@@ -549,19 +569,19 @@ BOOST_AUTO_TEST_CASE( max_header_len ) {
|
||||
exception = true;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
BOOST_CHECK( exception == true );
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE( max_header_len_split ) {
|
||||
websocketpp::http::parser::request r;
|
||||
|
||||
|
||||
std::string raw(websocketpp::http::max_header_size-1,'*');
|
||||
std::string raw2(2,'*');
|
||||
|
||||
|
||||
bool exception = false;
|
||||
size_t pos = 0;
|
||||
|
||||
|
||||
try {
|
||||
pos += r.consume(raw.c_str(),raw.size());
|
||||
pos += r.consume(raw2.c_str(),raw2.size());
|
||||
@@ -570,24 +590,24 @@ BOOST_AUTO_TEST_CASE( max_header_len_split ) {
|
||||
exception = true;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
BOOST_CHECK( exception == true );
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE( firefox_full_request ) {
|
||||
websocketpp::http::parser::request r;
|
||||
|
||||
|
||||
std::string raw = "GET / HTTP/1.1\r\nHost: localhost:5000\r\nUser-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.7; rv:10.0) Gecko/20100101 Firefox/10.0\r\nAccept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8\r\nAccept-Language: en-us,en;q=0.5\r\nAccept-Encoding: gzip, deflate\r\nConnection: keep-alive, Upgrade\r\nSec-WebSocket-Version: 8\r\nSec-WebSocket-Origin: http://zaphoyd.com\r\nSec-WebSocket-Key: pFik//FxwFk0riN4ZiPFjQ==\r\nPragma: no-cache\r\nCache-Control: no-cache\r\nUpgrade: websocket\r\n\r\n";
|
||||
|
||||
|
||||
bool exception = false;
|
||||
size_t pos = 0;
|
||||
|
||||
|
||||
try {
|
||||
pos += r.consume(raw.c_str(),raw.size());
|
||||
} catch (...) {
|
||||
exception = true;
|
||||
}
|
||||
|
||||
|
||||
BOOST_CHECK( exception == false );
|
||||
BOOST_CHECK( pos == 482 );
|
||||
BOOST_CHECK( r.ready() == true );
|
||||
@@ -610,270 +630,297 @@ BOOST_AUTO_TEST_CASE( firefox_full_request ) {
|
||||
|
||||
BOOST_AUTO_TEST_CASE( bad_method ) {
|
||||
websocketpp::http::parser::request r;
|
||||
|
||||
|
||||
std::string raw = "GE]T / HTTP/1.1\r\nHost: www.example.com\r\n\r\n";
|
||||
|
||||
|
||||
bool exception = false;
|
||||
|
||||
|
||||
try {
|
||||
r.consume(raw.c_str(),raw.size());
|
||||
} catch (...) {
|
||||
exception = true;
|
||||
}
|
||||
|
||||
|
||||
BOOST_CHECK( exception == true );
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE( bad_header_name ) {
|
||||
websocketpp::http::parser::request r;
|
||||
|
||||
|
||||
std::string raw = "GET / HTTP/1.1\r\nHo]st: www.example.com\r\n\r\n";
|
||||
|
||||
|
||||
bool exception = false;
|
||||
|
||||
|
||||
try {
|
||||
r.consume(raw.c_str(),raw.size());
|
||||
} catch (...) {
|
||||
exception = true;
|
||||
}
|
||||
|
||||
|
||||
BOOST_CHECK( exception == true );
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE( old_http_version ) {
|
||||
websocketpp::http::parser::request r;
|
||||
|
||||
|
||||
std::string raw = "GET / HTTP/1.0\r\nHost: www.example.com\r\n\r\n";
|
||||
|
||||
|
||||
bool exception = false;
|
||||
size_t pos = 0;
|
||||
|
||||
|
||||
try {
|
||||
pos = r.consume(raw.c_str(),raw.size());
|
||||
} catch (...) {
|
||||
exception = true;
|
||||
}
|
||||
|
||||
|
||||
BOOST_CHECK( exception == false );
|
||||
BOOST_CHECK( pos == 41 );
|
||||
BOOST_CHECK_EQUAL( pos, 41 );
|
||||
BOOST_CHECK( r.ready() == true );
|
||||
BOOST_CHECK( r.get_version() == "HTTP/1.0" );
|
||||
BOOST_CHECK( r.get_method() == "GET" );
|
||||
BOOST_CHECK( r.get_uri() == "/" );
|
||||
BOOST_CHECK( r.get_header("Host") == "www.example.com" );
|
||||
BOOST_CHECK_EQUAL( r.get_version(), "HTTP/1.0" );
|
||||
BOOST_CHECK_EQUAL( r.get_method(), "GET" );
|
||||
BOOST_CHECK_EQUAL( r.get_uri(), "/" );
|
||||
BOOST_CHECK_EQUAL( r.get_header("Host"), "www.example.com" );
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE( new_http_version1 ) {
|
||||
websocketpp::http::parser::request r;
|
||||
|
||||
|
||||
std::string raw = "GET / HTTP/1.12\r\nHost: www.example.com\r\n\r\n";
|
||||
|
||||
|
||||
bool exception = false;
|
||||
size_t pos = 0;
|
||||
|
||||
|
||||
try {
|
||||
pos = r.consume(raw.c_str(),raw.size());
|
||||
} catch (...) {
|
||||
exception = true;
|
||||
}
|
||||
|
||||
|
||||
BOOST_CHECK( exception == false );
|
||||
BOOST_CHECK( pos == 42 );
|
||||
BOOST_CHECK_EQUAL( pos, 42 );
|
||||
BOOST_CHECK( r.ready() == true );
|
||||
BOOST_CHECK( r.get_version() == "HTTP/1.12" );
|
||||
BOOST_CHECK( r.get_method() == "GET" );
|
||||
BOOST_CHECK( r.get_uri() == "/" );
|
||||
BOOST_CHECK( r.get_header("Host") == "www.example.com" );
|
||||
BOOST_CHECK_EQUAL( r.get_version(), "HTTP/1.12" );
|
||||
BOOST_CHECK_EQUAL( r.get_method(), "GET" );
|
||||
BOOST_CHECK_EQUAL( r.get_uri(), "/" );
|
||||
BOOST_CHECK_EQUAL( r.get_header("Host"), "www.example.com" );
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE( new_http_version2 ) {
|
||||
websocketpp::http::parser::request r;
|
||||
|
||||
|
||||
std::string raw = "GET / HTTP/12.12\r\nHost: www.example.com\r\n\r\n";
|
||||
|
||||
|
||||
bool exception = false;
|
||||
size_t pos = 0;
|
||||
|
||||
|
||||
try {
|
||||
pos = r.consume(raw.c_str(),raw.size());
|
||||
} catch (...) {
|
||||
exception = true;
|
||||
}
|
||||
|
||||
|
||||
BOOST_CHECK( exception == false );
|
||||
BOOST_CHECK( pos == 43 );
|
||||
BOOST_CHECK_EQUAL( pos, 43 );
|
||||
BOOST_CHECK( r.ready() == true );
|
||||
BOOST_CHECK( r.get_version() == "HTTP/12.12" );
|
||||
BOOST_CHECK( r.get_method() == "GET" );
|
||||
BOOST_CHECK( r.get_uri() == "/" );
|
||||
BOOST_CHECK( r.get_header("Host") == "www.example.com" );
|
||||
BOOST_CHECK_EQUAL( r.get_version(), "HTTP/12.12" );
|
||||
BOOST_CHECK_EQUAL( r.get_method(), "GET" );
|
||||
BOOST_CHECK_EQUAL( r.get_uri(), "/" );
|
||||
BOOST_CHECK_EQUAL( r.get_header("Host"), "www.example.com" );
|
||||
}
|
||||
|
||||
/* commented out due to not being implemented yet
|
||||
|
||||
BOOST_AUTO_TEST_CASE( new_http_version3 ) {
|
||||
websocketpp::http::parser::request r;
|
||||
|
||||
|
||||
std::string raw = "GET / HTTPS/12.12\r\nHost: www.example.com\r\n\r\n";
|
||||
|
||||
|
||||
bool exception = false;
|
||||
size_t pos = 0;
|
||||
|
||||
|
||||
try {
|
||||
pos = r.consume(raw.c_str(),raw.size());
|
||||
} catch (...) {
|
||||
exception = true;
|
||||
}
|
||||
|
||||
|
||||
BOOST_CHECK( exception == true );
|
||||
}
|
||||
}*/
|
||||
|
||||
BOOST_AUTO_TEST_CASE( header_whitespace1 ) {
|
||||
websocketpp::http::parser::request r;
|
||||
|
||||
|
||||
std::string raw = "GET / HTTP/1.1\r\nHost: www.example.com \r\n\r\n";
|
||||
|
||||
|
||||
bool exception = false;
|
||||
size_t pos = 0;
|
||||
|
||||
|
||||
try {
|
||||
pos = r.consume(raw.c_str(),raw.size());
|
||||
} catch (...) {
|
||||
exception = true;
|
||||
}
|
||||
|
||||
|
||||
BOOST_CHECK( exception == false );
|
||||
BOOST_CHECK( pos == 43 );
|
||||
BOOST_CHECK_EQUAL( pos, 43 );
|
||||
BOOST_CHECK( r.ready() == true );
|
||||
BOOST_CHECK( r.get_version() == "HTTP/1.1" );
|
||||
BOOST_CHECK( r.get_method() == "GET" );
|
||||
BOOST_CHECK( r.get_uri() == "/" );
|
||||
BOOST_CHECK( r.get_header("Host") == "www.example.com" );
|
||||
BOOST_CHECK_EQUAL( r.get_version(), "HTTP/1.1" );
|
||||
BOOST_CHECK_EQUAL( r.get_method(), "GET" );
|
||||
BOOST_CHECK_EQUAL( r.get_uri(), "/" );
|
||||
BOOST_CHECK_EQUAL( r.get_header("Host"), "www.example.com" );
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE( header_whitespace2 ) {
|
||||
websocketpp::http::parser::request r;
|
||||
|
||||
|
||||
std::string raw = "GET / HTTP/1.1\r\nHost:www.example.com\r\n\r\n";
|
||||
|
||||
|
||||
bool exception = false;
|
||||
size_t pos = 0;
|
||||
|
||||
|
||||
try {
|
||||
pos = r.consume(raw.c_str(),raw.size());
|
||||
} catch (...) {
|
||||
exception = true;
|
||||
}
|
||||
|
||||
|
||||
BOOST_CHECK( exception == false );
|
||||
BOOST_CHECK( pos == 40 );
|
||||
BOOST_CHECK_EQUAL( pos, 40 );
|
||||
BOOST_CHECK( r.ready() == true );
|
||||
BOOST_CHECK( r.get_version() == "HTTP/1.1" );
|
||||
BOOST_CHECK( r.get_method() == "GET" );
|
||||
BOOST_CHECK( r.get_uri() == "/" );
|
||||
BOOST_CHECK( r.get_header("Host") == "www.example.com" );
|
||||
}*/
|
||||
BOOST_CHECK_EQUAL( r.get_version(), "HTTP/1.1" );
|
||||
BOOST_CHECK_EQUAL( r.get_method(), "GET" );
|
||||
BOOST_CHECK_EQUAL( r.get_uri(), "/" );
|
||||
BOOST_CHECK_EQUAL( r.get_header("Host"), "www.example.com" );
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE( header_aggregation ) {
|
||||
websocketpp::http::parser::request r;
|
||||
|
||||
|
||||
std::string raw = "GET / HTTP/1.1\r\nHost: www.example.com\r\nFoo: bar\r\nFoo: bat\r\n\r\n";
|
||||
|
||||
|
||||
bool exception = false;
|
||||
size_t pos = 0;
|
||||
|
||||
|
||||
try {
|
||||
pos = r.consume(raw.c_str(),raw.size());
|
||||
} catch (...) {
|
||||
exception = true;
|
||||
}
|
||||
|
||||
|
||||
BOOST_CHECK( exception == false );
|
||||
BOOST_CHECK( pos == 61 );
|
||||
BOOST_CHECK_EQUAL( pos, 61 );
|
||||
BOOST_CHECK( r.ready() == true );
|
||||
BOOST_CHECK( r.get_version() == "HTTP/1.1" );
|
||||
BOOST_CHECK( r.get_method() == "GET" );
|
||||
BOOST_CHECK( r.get_uri() == "/" );
|
||||
BOOST_CHECK( r.get_header("Foo") == "bar, bat" );
|
||||
BOOST_CHECK_EQUAL( r.get_version(), "HTTP/1.1" );
|
||||
BOOST_CHECK_EQUAL( r.get_method(), "GET" );
|
||||
BOOST_CHECK_EQUAL( r.get_uri(), "/" );
|
||||
BOOST_CHECK_EQUAL( r.get_header("Foo"), "bar, bat" );
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE( wikipedia_example_response ) {
|
||||
websocketpp::http::parser::response r;
|
||||
|
||||
|
||||
std::string raw = "HTTP/1.1 101 Switching Protocols\r\nUpgrade: websocket\r\nConnection: Upgrade\r\nSec-WebSocket-Accept: HSmrc0sMlYUkAGmm5OPpG2HaGWk=\r\nSec-WebSocket-Protocol: chat\r\n\r\n";
|
||||
|
||||
|
||||
bool exception = false;
|
||||
size_t pos = 0;
|
||||
|
||||
|
||||
try {
|
||||
pos += r.consume(raw.c_str(),raw.size());
|
||||
} catch (std::exception &e) {
|
||||
exception = true;
|
||||
std::cout << e.what() << std::endl;
|
||||
}
|
||||
|
||||
|
||||
BOOST_CHECK( exception == false );
|
||||
BOOST_CHECK( pos == 159 );
|
||||
BOOST_CHECK_EQUAL( pos, 159 );
|
||||
BOOST_CHECK( r.headers_ready() == true );
|
||||
BOOST_CHECK( r.get_version() == "HTTP/1.1" );
|
||||
BOOST_CHECK( r.get_status_code() == websocketpp::http::status_code::switching_protocols );
|
||||
BOOST_CHECK( r.get_status_msg() == "Switching Protocols" );
|
||||
BOOST_CHECK( r.get_header("Upgrade") == "websocket" );
|
||||
BOOST_CHECK( r.get_header("Connection") == "Upgrade" );
|
||||
BOOST_CHECK( r.get_header("Sec-WebSocket-Accept") == "HSmrc0sMlYUkAGmm5OPpG2HaGWk=" );
|
||||
BOOST_CHECK( r.get_header("Sec-WebSocket-Protocol") == "chat" );
|
||||
BOOST_CHECK_EQUAL( r.get_version(), "HTTP/1.1" );
|
||||
BOOST_CHECK_EQUAL( r.get_status_code(), websocketpp::http::status_code::switching_protocols );
|
||||
BOOST_CHECK_EQUAL( r.get_status_msg(), "Switching Protocols" );
|
||||
BOOST_CHECK_EQUAL( r.get_header("Upgrade"), "websocket" );
|
||||
BOOST_CHECK_EQUAL( r.get_header("Connection"), "Upgrade" );
|
||||
BOOST_CHECK_EQUAL( r.get_header("Sec-WebSocket-Accept"), "HSmrc0sMlYUkAGmm5OPpG2HaGWk=" );
|
||||
BOOST_CHECK_EQUAL( r.get_header("Sec-WebSocket-Protocol"), "chat" );
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE( response_with_non_standard_lws ) {
|
||||
websocketpp::http::parser::response r;
|
||||
|
||||
std::string raw = "HTTP/1.1 101 Switching Protocols\r\nUpgrade: websocket\r\nConnection: Upgrade\r\nSec-WebSocket-Accept:HSmrc0sMlYUkAGmm5OPpG2HaGWk=\r\nSec-WebSocket-Protocol: chat\r\n\r\n";
|
||||
|
||||
bool exception = false;
|
||||
size_t pos = 0;
|
||||
|
||||
try {
|
||||
pos += r.consume(raw.c_str(),raw.size());
|
||||
} catch (std::exception &e) {
|
||||
exception = true;
|
||||
std::cout << e.what() << std::endl;
|
||||
}
|
||||
|
||||
BOOST_CHECK( exception == false );
|
||||
BOOST_CHECK_EQUAL( pos, 158 );
|
||||
BOOST_CHECK( r.headers_ready() );
|
||||
BOOST_CHECK_EQUAL( r.get_version(), "HTTP/1.1" );
|
||||
BOOST_CHECK_EQUAL( r.get_status_code(), websocketpp::http::status_code::switching_protocols );
|
||||
BOOST_CHECK_EQUAL( r.get_status_msg(), "Switching Protocols" );
|
||||
BOOST_CHECK_EQUAL( r.get_header("Upgrade"), "websocket" );
|
||||
BOOST_CHECK_EQUAL( r.get_header("Connection"), "Upgrade" );
|
||||
BOOST_CHECK_EQUAL( r.get_header("Sec-WebSocket-Accept"), "HSmrc0sMlYUkAGmm5OPpG2HaGWk=" );
|
||||
BOOST_CHECK_EQUAL( r.get_header("Sec-WebSocket-Protocol"), "chat" );
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE( plain_http_response ) {
|
||||
websocketpp::http::parser::response r;
|
||||
|
||||
|
||||
std::string raw = "HTTP/1.1 200 OK\r\nDate: Thu, 10 May 2012 11:59:25 GMT\r\nServer: Apache/2.2.21 (Unix) mod_ssl/2.2.21 OpenSSL/0.9.8r DAV/2 PHP/5.3.8 with Suhosin-Patch\r\nLast-Modified: Tue, 30 Mar 2010 17:41:28 GMT\r\nETag: \"16799d-55-4830823a78200\"\r\nAccept-Ranges: bytes\r\nContent-Length: 85\r\nVary: Accept-Encoding\r\nContent-Type: text/html\r\n\r\n<!doctype html>\n<html>\n<head>\n<title>Thor</title>\n</head>\n<body> \n<p>Thor</p>\n</body>";
|
||||
|
||||
|
||||
bool exception = false;
|
||||
size_t pos = 0;
|
||||
|
||||
|
||||
try {
|
||||
pos += r.consume(raw.c_str(),raw.size());
|
||||
} catch (std::exception &e) {
|
||||
exception = true;
|
||||
std::cout << e.what() << std::endl;
|
||||
}
|
||||
|
||||
|
||||
BOOST_CHECK( exception == false );
|
||||
BOOST_CHECK( pos == 405 );
|
||||
BOOST_CHECK_EQUAL( pos, 405 );
|
||||
BOOST_CHECK( r.headers_ready() == true );
|
||||
BOOST_CHECK( r.ready() == true );
|
||||
BOOST_CHECK( r.get_version() == "HTTP/1.1" );
|
||||
BOOST_CHECK( r.get_status_code() == websocketpp::http::status_code::ok );
|
||||
BOOST_CHECK( r.get_status_msg() == "OK" );
|
||||
BOOST_CHECK( r.get_header("Date") == "Thu, 10 May 2012 11:59:25 GMT" );
|
||||
BOOST_CHECK( r.get_header("Server") == "Apache/2.2.21 (Unix) mod_ssl/2.2.21 OpenSSL/0.9.8r DAV/2 PHP/5.3.8 with Suhosin-Patch" );
|
||||
BOOST_CHECK( r.get_header("Last-Modified") == "Tue, 30 Mar 2010 17:41:28 GMT" );
|
||||
BOOST_CHECK( r.get_header("ETag") == "\"16799d-55-4830823a78200\"" );
|
||||
BOOST_CHECK( r.get_header("Accept-Ranges") == "bytes" );
|
||||
BOOST_CHECK( r.get_header("Content-Length") == "85" );
|
||||
BOOST_CHECK( r.get_header("Vary") == "Accept-Encoding" );
|
||||
BOOST_CHECK( r.get_header("Content-Type") == "text/html" );
|
||||
BOOST_CHECK( r.get_body() == "<!doctype html>\n<html>\n<head>\n<title>Thor</title>\n</head>\n<body> \n<p>Thor</p>\n</body>" );
|
||||
BOOST_CHECK_EQUAL( r.get_version(), "HTTP/1.1" );
|
||||
BOOST_CHECK_EQUAL( r.get_status_code(), websocketpp::http::status_code::ok );
|
||||
BOOST_CHECK_EQUAL( r.get_status_msg(), "OK" );
|
||||
BOOST_CHECK_EQUAL( r.get_header("Date"), "Thu, 10 May 2012 11:59:25 GMT" );
|
||||
BOOST_CHECK_EQUAL( r.get_header("Server"), "Apache/2.2.21 (Unix) mod_ssl/2.2.21 OpenSSL/0.9.8r DAV/2 PHP/5.3.8 with Suhosin-Patch" );
|
||||
BOOST_CHECK_EQUAL( r.get_header("Last-Modified"), "Tue, 30 Mar 2010 17:41:28 GMT" );
|
||||
BOOST_CHECK_EQUAL( r.get_header("ETag"), "\"16799d-55-4830823a78200\"" );
|
||||
BOOST_CHECK_EQUAL( r.get_header("Accept-Ranges"), "bytes" );
|
||||
BOOST_CHECK_EQUAL( r.get_header("Content-Length"), "85" );
|
||||
BOOST_CHECK_EQUAL( r.get_header("Vary"), "Accept-Encoding" );
|
||||
BOOST_CHECK_EQUAL( r.get_header("Content-Type"), "text/html" );
|
||||
BOOST_CHECK_EQUAL( r.get_body(), "<!doctype html>\n<html>\n<head>\n<title>Thor</title>\n</head>\n<body> \n<p>Thor</p>\n</body>" );
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE( parse_istream ) {
|
||||
websocketpp::http::parser::response r;
|
||||
|
||||
|
||||
std::stringstream s;
|
||||
|
||||
|
||||
s << "HTTP/1.1 200 OK\r\nDate: Thu, 10 May 2012 11:59:25 GMT\r\nServer: Apache/2.2.21 (Unix) mod_ssl/2.2.21 OpenSSL/0.9.8r DAV/2 PHP/5.3.8 with Suhosin-Patch\r\nLast-Modified: Tue, 30 Mar 2010 17:41:28 GMT\r\nETag: \"16799d-55-4830823a78200\"\r\nAccept-Ranges: bytes\r\nContent-Length: 85\r\nVary: Accept-Encoding\r\nContent-Type: text/html\r\n\r\n<!doctype html>\n<html>\n<head>\n<title>Thor</title>\n</head>\n<body> \n<p>Thor</p>\n</body>";
|
||||
|
||||
|
||||
bool exception = false;
|
||||
size_t pos = 0;
|
||||
|
||||
|
||||
try {
|
||||
pos += r.consume(s);
|
||||
} catch (std::exception &e) {
|
||||
exception = true;
|
||||
std::cout << e.what() << std::endl;
|
||||
}
|
||||
|
||||
|
||||
BOOST_CHECK_EQUAL( exception, false );
|
||||
BOOST_CHECK_EQUAL( pos, 405 );
|
||||
BOOST_CHECK_EQUAL( r.headers_ready(), true );
|
||||
@@ -882,40 +929,40 @@ BOOST_AUTO_TEST_CASE( parse_istream ) {
|
||||
|
||||
BOOST_AUTO_TEST_CASE( write_request_basic ) {
|
||||
websocketpp::http::parser::request r;
|
||||
|
||||
|
||||
std::string raw = "GET / HTTP/1.1\r\n\r\n";
|
||||
|
||||
|
||||
r.set_version("HTTP/1.1");
|
||||
r.set_method("GET");
|
||||
r.set_uri("/");
|
||||
|
||||
BOOST_CHECK( r.raw() == raw );
|
||||
|
||||
BOOST_CHECK_EQUAL( r.raw(), raw );
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE( write_request_with_header ) {
|
||||
websocketpp::http::parser::request r;
|
||||
|
||||
|
||||
std::string raw = "GET / HTTP/1.1\r\nHost: http://example.com\r\n\r\n";
|
||||
|
||||
|
||||
r.set_version("HTTP/1.1");
|
||||
r.set_method("GET");
|
||||
r.set_uri("/");
|
||||
r.replace_header("Host","http://example.com");
|
||||
|
||||
BOOST_CHECK( r.raw() == raw );
|
||||
|
||||
BOOST_CHECK_EQUAL( r.raw(), raw );
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE( write_request_with_body ) {
|
||||
websocketpp::http::parser::request r;
|
||||
|
||||
|
||||
std::string raw = "POST / HTTP/1.1\r\nContent-Length: 48\r\nContent-Type: application/x-www-form-urlencoded\r\nHost: http://example.com\r\n\r\nlicenseID=string&content=string¶msXML=string";
|
||||
|
||||
|
||||
r.set_version("HTTP/1.1");
|
||||
r.set_method("POST");
|
||||
r.set_uri("/");
|
||||
r.replace_header("Host","http://example.com");
|
||||
r.replace_header("Content-Type","application/x-www-form-urlencoded");
|
||||
r.set_body("licenseID=string&content=string¶msXML=string");
|
||||
|
||||
BOOST_CHECK( r.raw() == raw );
|
||||
|
||||
BOOST_CHECK_EQUAL( r.raw(), raw );
|
||||
}
|
||||
+33
-33
@@ -11,10 +11,10 @@
|
||||
* * 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
|
||||
*
|
||||
* 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;
|
||||
@@ -22,7 +22,7 @@
|
||||
* 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.
|
||||
*
|
||||
*
|
||||
*/
|
||||
|
||||
#include <websocketpp/http/parser.hpp>
|
||||
@@ -36,18 +36,18 @@ public:
|
||||
}
|
||||
~scoped_timer() {
|
||||
std::chrono::nanoseconds time_taken = std::chrono::steady_clock::now()-m_start;
|
||||
|
||||
|
||||
//nanoseconds_per_test
|
||||
|
||||
|
||||
//tests_per_second
|
||||
|
||||
|
||||
//1000000000.0/(double(time_taken.count())/1000.0)
|
||||
|
||||
|
||||
std::cout << 1000000000.0/(double(time_taken.count())/1000.0) << std::endl;
|
||||
|
||||
|
||||
//std::cout << (1.0/double(time_taken.count())) * double(1000000000*1000) << std::endl;
|
||||
}
|
||||
|
||||
|
||||
private:
|
||||
std::string m_id;
|
||||
std::chrono::steady_clock::time_point m_start;
|
||||
@@ -55,87 +55,87 @@ private:
|
||||
|
||||
int main() {
|
||||
std::string raw = "GET / HTTP/1.1\r\nHost: www.example.com\r\n\r\n";
|
||||
|
||||
|
||||
std::string firefox = "GET / HTTP/1.1\r\nHost: localhost:5000\r\nUser-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.7; rv:10.0) Gecko/20100101 Firefox/10.0\r\nAccept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8\r\nAccept-Language: en-us,en;q=0.5\r\nAccept-Encoding: gzip, deflate\r\nConnection: keep-alive, Upgrade\r\nSec-WebSocket-Version: 8\r\nSec-WebSocket-Origin: http://zaphoyd.com\r\nSec-WebSocket-Key: pFik//FxwFk0riN4ZiPFjQ==\r\nPragma: no-cache\r\nCache-Control: no-cache\r\nUpgrade: websocket\r\n\r\n";
|
||||
|
||||
|
||||
std::string firefox1 = "GET / HTTP/1.1\r\nHost: localhost:5000\r\nUser-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.7; rv:10.0) Gecko/20100101 Firefox/10.0\r\nAccept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8\r\nAccept-Language: en-us,en;q=0.5\r\n";
|
||||
|
||||
|
||||
std::string firefox2 = "Accept-Encoding: gzip, deflate\r\nConnection: keep-alive, Upgrade\r\nSec-WebSocket-Version: 8\r\nSec-WebSocket-Origin: http://zaphoyd.com\r\nSec-WebSocket-Key: pFik//FxwFk0riN4ZiPFjQ==\r\nPragma: no-cache\r\nCache-Control: no-cache\r\nUpgrade: websocket\r\n\r\n";
|
||||
|
||||
{
|
||||
|
||||
{
|
||||
scoped_timer timer("Simplest 1 chop");
|
||||
for (int i = 0; i < 1000; i++) {
|
||||
websocketpp::http::parser::request r;
|
||||
|
||||
|
||||
try {
|
||||
r.consume(raw.c_str(),raw.size());
|
||||
} catch (...) {
|
||||
std::cout << "exception" << std::endl;
|
||||
}
|
||||
|
||||
|
||||
if (!r.ready()) {
|
||||
std::cout << "error" << std::endl;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
{
|
||||
|
||||
{
|
||||
scoped_timer timer("FireFox, 1 chop, consume old");
|
||||
for (int i = 0; i < 1000; i++) {
|
||||
websocketpp::http::parser::request r;
|
||||
|
||||
|
||||
try {
|
||||
r.consume2(firefox.c_str(),firefox.size());
|
||||
} catch (...) {
|
||||
std::cout << "exception" << std::endl;
|
||||
}
|
||||
|
||||
|
||||
if (!r.ready()) {
|
||||
std::cout << "error" << std::endl;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
{
|
||||
|
||||
{
|
||||
scoped_timer timer("FireFox, 1 chop");
|
||||
for (int i = 0; i < 1000; i++) {
|
||||
websocketpp::http::parser::request r;
|
||||
|
||||
|
||||
try {
|
||||
r.consume(firefox.c_str(),firefox.size());
|
||||
} catch (...) {
|
||||
std::cout << "exception" << std::endl;
|
||||
}
|
||||
|
||||
|
||||
if (!r.ready()) {
|
||||
std::cout << "error" << std::endl;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
{
|
||||
|
||||
|
||||
|
||||
{
|
||||
scoped_timer timer("FireFox, 2 chop");
|
||||
for (int i = 0; i < 1000; i++) {
|
||||
websocketpp::http::parser::request r;
|
||||
|
||||
|
||||
try {
|
||||
r.consume(firefox1.c_str(),firefox1.size());
|
||||
r.consume(firefox2.c_str(),firefox2.size());
|
||||
} catch (...) {
|
||||
std::cout << "exception" << std::endl;
|
||||
}
|
||||
|
||||
|
||||
if (!r.ready()) {
|
||||
std::cout << "error" << std::endl;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
||||
+16
-16
@@ -11,10 +11,10 @@
|
||||
* * 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
|
||||
*
|
||||
* 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;
|
||||
@@ -22,7 +22,7 @@
|
||||
* 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.
|
||||
*
|
||||
*
|
||||
*/
|
||||
//#define BOOST_TEST_DYN_LINK
|
||||
#define BOOST_TEST_MODULE basic_log
|
||||
@@ -36,16 +36,16 @@
|
||||
|
||||
BOOST_AUTO_TEST_CASE( is_token_char ) {
|
||||
typedef websocketpp::log::basic<websocketpp::concurrency::none,websocketpp::log::elevel> error_log;
|
||||
|
||||
|
||||
error_log elog;
|
||||
|
||||
|
||||
BOOST_CHECK( elog.static_test(websocketpp::log::elevel::info ) == true );
|
||||
BOOST_CHECK( elog.static_test(websocketpp::log::elevel::warn ) == true );
|
||||
BOOST_CHECK( elog.static_test(websocketpp::log::elevel::rerror ) == true );
|
||||
BOOST_CHECK( elog.static_test(websocketpp::log::elevel::fatal ) == true );
|
||||
|
||||
|
||||
elog.set_channels(websocketpp::log::elevel::info);
|
||||
|
||||
|
||||
elog.write(websocketpp::log::elevel::info,"Information");
|
||||
elog.write(websocketpp::log::elevel::warn,"A warning");
|
||||
elog.write(websocketpp::log::elevel::rerror,"A error");
|
||||
@@ -54,13 +54,13 @@ BOOST_AUTO_TEST_CASE( is_token_char ) {
|
||||
|
||||
BOOST_AUTO_TEST_CASE( access_clear ) {
|
||||
typedef websocketpp::log::basic<websocketpp::concurrency::none,websocketpp::log::alevel> access_log;
|
||||
|
||||
|
||||
std::stringstream out;
|
||||
access_log logger(0xffffffff,&out);
|
||||
|
||||
|
||||
// clear all channels
|
||||
logger.clear_channels(0xffffffff);
|
||||
|
||||
|
||||
// writes shouldn't happen
|
||||
logger.write(websocketpp::log::alevel::devel,"devel");
|
||||
//std::cout << "|" << out.str() << "|" << std::endl;
|
||||
@@ -69,13 +69,13 @@ BOOST_AUTO_TEST_CASE( access_clear ) {
|
||||
|
||||
BOOST_AUTO_TEST_CASE( basic_concurrency ) {
|
||||
typedef websocketpp::log::basic<websocketpp::concurrency::basic,websocketpp::log::alevel> access_log;
|
||||
|
||||
|
||||
std::stringstream out;
|
||||
access_log logger(0xffffffff,&out);
|
||||
|
||||
|
||||
logger.set_channels(0xffffffff);
|
||||
|
||||
|
||||
logger.write(websocketpp::log::alevel::devel,"devel");
|
||||
//std::cout << "|" << out.str() << "|" << std::endl;
|
||||
BOOST_CHECK( out.str().size() > 0 );
|
||||
}
|
||||
}
|
||||
@@ -11,10 +11,10 @@
|
||||
* * 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
|
||||
*
|
||||
* 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;
|
||||
@@ -22,7 +22,7 @@
|
||||
* 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.
|
||||
*
|
||||
*
|
||||
*/
|
||||
//#define BOOST_TEST_DYN_LINK
|
||||
#define BOOST_TEST_MODULE message_buffer_alloc
|
||||
@@ -36,7 +36,7 @@
|
||||
template <template <class> class con_msg_manager>
|
||||
struct stub {
|
||||
typedef websocketpp::lib::shared_ptr<stub> ptr;
|
||||
|
||||
|
||||
typedef con_msg_manager<stub> con_msg_man_type;
|
||||
typedef typename con_msg_man_type::ptr con_msg_man_ptr;
|
||||
typedef typename con_msg_man_type::weak_ptr con_msg_man_weak_ptr;
|
||||
@@ -55,16 +55,16 @@ struct stub {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
websocketpp::frame::opcode::value m_opcode;
|
||||
con_msg_man_weak_ptr m_manager;
|
||||
size_t m_size;
|
||||
};
|
||||
|
||||
BOOST_AUTO_TEST_CASE( basic_get_message ) {
|
||||
typedef stub<websocketpp::message_buffer::alloc::con_msg_manager>
|
||||
typedef stub<websocketpp::message_buffer::alloc::con_msg_manager>
|
||||
message_type;
|
||||
typedef websocketpp::message_buffer::alloc::con_msg_manager<message_type>
|
||||
typedef websocketpp::message_buffer::alloc::con_msg_manager<message_type>
|
||||
con_msg_man_type;
|
||||
|
||||
con_msg_man_type::ptr manager(new con_msg_man_type());
|
||||
@@ -77,13 +77,13 @@ BOOST_AUTO_TEST_CASE( basic_get_message ) {
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE( basic_get_manager ) {
|
||||
typedef stub<websocketpp::message_buffer::alloc::con_msg_manager>
|
||||
typedef stub<websocketpp::message_buffer::alloc::con_msg_manager>
|
||||
message_type;
|
||||
typedef websocketpp::message_buffer::alloc::con_msg_manager<message_type>
|
||||
typedef websocketpp::message_buffer::alloc::con_msg_manager<message_type>
|
||||
con_msg_man_type;
|
||||
typedef websocketpp::message_buffer::alloc::endpoint_msg_manager
|
||||
<con_msg_man_type> endpoint_manager_type;
|
||||
|
||||
|
||||
endpoint_manager_type em;
|
||||
con_msg_man_type::ptr manager = em.get_manager();
|
||||
message_type::ptr msg = manager->get_message(websocketpp::frame::opcode::TEXT,512);
|
||||
|
||||
@@ -11,10 +11,10 @@
|
||||
* * 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
|
||||
*
|
||||
* 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;
|
||||
@@ -22,7 +22,7 @@
|
||||
* 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.
|
||||
*
|
||||
*
|
||||
*/
|
||||
//#define BOOST_TEST_DYN_LINK
|
||||
#define BOOST_TEST_MODULE message
|
||||
@@ -37,7 +37,7 @@ template <typename message>
|
||||
struct stub {
|
||||
typedef websocketpp::lib::weak_ptr<stub> weak_ptr;
|
||||
typedef websocketpp::lib::shared_ptr<stub> ptr;
|
||||
|
||||
|
||||
stub() : recycled(false) {}
|
||||
|
||||
bool recycle(message * msg) {
|
||||
@@ -54,7 +54,7 @@ BOOST_AUTO_TEST_CASE( basic_size_check ) {
|
||||
|
||||
stub_type::ptr s(new stub_type());
|
||||
message_type::ptr msg(new message_type(s,websocketpp::frame::opcode::TEXT,500));
|
||||
|
||||
|
||||
BOOST_CHECK(msg->get_payload().capacity() >= 500);
|
||||
}
|
||||
|
||||
|
||||
@@ -11,10 +11,10 @@
|
||||
* * 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
|
||||
*
|
||||
* 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;
|
||||
@@ -22,7 +22,7 @@
|
||||
* 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.
|
||||
*
|
||||
*
|
||||
*/
|
||||
//#define BOOST_TEST_DYN_LINK
|
||||
#define BOOST_TEST_MODULE hybi_00_processor
|
||||
@@ -40,37 +40,37 @@ BOOST_AUTO_TEST_CASE( exact_match ) {
|
||||
websocketpp::http::parser::request r;
|
||||
websocketpp::http::parser::response response;
|
||||
websocketpp::processor::hybi00<websocketpp::http::parser::request,websocketpp::http::parser::response> p(false);
|
||||
|
||||
|
||||
std::string handshake = "GET / HTTP/1.1\r\nHost: www.example.com\r\nConnection: upgrade\r\nUpgrade: websocket\r\nOrigin: http://example.com\r\nSec-WebSocket-Key1: 3e6b263 4 17 80\r\nSec-WebSocket-Key2: 17 9 G`ZD9 2 2b 7X 3 /r90\r\n\r\n";
|
||||
|
||||
|
||||
r.consume(handshake.c_str(),handshake.size());
|
||||
r.replace_header("Sec-WebSocket-Key3","WjN}|M(6");
|
||||
|
||||
|
||||
BOOST_CHECK(websocketpp::processor::is_websocket_handshake(r));
|
||||
BOOST_CHECK(websocketpp::processor::get_websocket_version(r) == p.get_version());
|
||||
BOOST_CHECK(p.validate_handshake(r));
|
||||
|
||||
|
||||
websocketpp::uri_ptr u;
|
||||
bool exception;
|
||||
|
||||
|
||||
try {
|
||||
u = p.get_uri(r);
|
||||
} catch (const websocketpp::uri_exception& e) {
|
||||
exception = true;
|
||||
}
|
||||
|
||||
|
||||
BOOST_CHECK(exception == false);
|
||||
BOOST_CHECK(u->get_secure() == false);
|
||||
BOOST_CHECK(u->get_host() == "www.example.com");
|
||||
BOOST_CHECK(u->get_resource() == "/");
|
||||
BOOST_CHECK(u->get_port() == websocketpp::URI_DEFAULT_PORT);
|
||||
|
||||
|
||||
p.process_handshake(r,response);
|
||||
|
||||
|
||||
BOOST_CHECK(response.get_header("Connection") == "Upgrade");
|
||||
BOOST_CHECK(response.get_header("Upgrade") == "websocket");
|
||||
BOOST_CHECK(response.get_header("Sec-WebSocket-Origin") == "http://example.com");
|
||||
|
||||
|
||||
BOOST_CHECK(response.get_header("Sec-WebSocket-Location") == "ws://www.example.com/");
|
||||
BOOST_CHECK(response.get_header("Sec-WebSocket-Key3") == "n`9eBk9z$R8pOtVb");
|
||||
}
|
||||
@@ -78,12 +78,12 @@ BOOST_AUTO_TEST_CASE( exact_match ) {
|
||||
BOOST_AUTO_TEST_CASE( non_get_method ) {
|
||||
websocketpp::http::parser::request r;
|
||||
websocketpp::processor::hybi00<websocketpp::http::parser::request,websocketpp::http::parser::response> p(false);
|
||||
|
||||
|
||||
std::string handshake = "POST / HTTP/1.1\r\nHost: www.example.com\r\nConnection: upgrade\r\nUpgrade: websocket\r\nSec-WebSocket-Key1: 3e6b263 4 17 80\r\nSec-WebSocket-Key2: 17 9 G`ZD9 2 2b 7X 3 /r90\r\n\r\n";
|
||||
|
||||
|
||||
r.consume(handshake.c_str(),handshake.size());
|
||||
r.replace_header("Sec-WebSocket-Key3","janelle!");
|
||||
|
||||
|
||||
BOOST_CHECK(websocketpp::processor::is_websocket_handshake(r));
|
||||
BOOST_CHECK(websocketpp::processor::get_websocket_version(r) == p.get_version());
|
||||
BOOST_CHECK(!p.validate_handshake(r));
|
||||
@@ -92,12 +92,12 @@ BOOST_AUTO_TEST_CASE( non_get_method ) {
|
||||
BOOST_AUTO_TEST_CASE( old_http_version ) {
|
||||
websocketpp::http::parser::request r;
|
||||
websocketpp::processor::hybi00<websocketpp::http::parser::request,websocketpp::http::parser::response> p(false);
|
||||
|
||||
|
||||
std::string handshake = "GET / HTTP/1.0\r\nHost: www.example.com\r\nConnection: upgrade\r\nUpgrade: websocket\r\nSec-WebSocket-Key1: 3e6b263 4 17 80\r\nSec-WebSocket-Key2: 17 9 G`ZD9 2 2b 7X 3 /r90\r\n\r\n";
|
||||
|
||||
|
||||
r.consume(handshake.c_str(),handshake.size());
|
||||
r.replace_header("Sec-WebSocket-Key3","janelle!");
|
||||
|
||||
|
||||
BOOST_CHECK(websocketpp::processor::is_websocket_handshake(r));
|
||||
BOOST_CHECK(websocketpp::processor::get_websocket_version(r) == p.get_version());
|
||||
BOOST_CHECK(!p.validate_handshake(r));
|
||||
@@ -106,12 +106,12 @@ BOOST_AUTO_TEST_CASE( old_http_version ) {
|
||||
BOOST_AUTO_TEST_CASE( missing_handshake_key1 ) {
|
||||
websocketpp::http::parser::request r;
|
||||
websocketpp::processor::hybi00<websocketpp::http::parser::request,websocketpp::http::parser::response> p(false);
|
||||
|
||||
|
||||
std::string handshake = "GET / HTTP/1.1\r\nHost: www.example.com\r\nConnection: upgrade\r\nUpgrade: websocket\r\nSec-WebSocket-Key1: 3e6b263 4 17 80\r\n\r\n";
|
||||
|
||||
|
||||
r.consume(handshake.c_str(),handshake.size());
|
||||
r.replace_header("Sec-WebSocket-Key3","janelle!");
|
||||
|
||||
|
||||
BOOST_CHECK(websocketpp::processor::is_websocket_handshake(r));
|
||||
BOOST_CHECK(websocketpp::processor::get_websocket_version(r) == p.get_version());
|
||||
BOOST_CHECK(!p.validate_handshake(r));
|
||||
@@ -120,12 +120,12 @@ BOOST_AUTO_TEST_CASE( missing_handshake_key1 ) {
|
||||
BOOST_AUTO_TEST_CASE( missing_handshake_key2 ) {
|
||||
websocketpp::http::parser::request r;
|
||||
websocketpp::processor::hybi00<websocketpp::http::parser::request,websocketpp::http::parser::response> p(false);
|
||||
|
||||
|
||||
std::string handshake = "GET / HTTP/1.1\r\nHost: www.example.com\r\nConnection: upgrade\r\nUpgrade: websocket\r\nSec-WebSocket-Key2: 17 9 G`ZD9 2 2b 7X 3 /r90\r\n\r\n";
|
||||
|
||||
|
||||
r.consume(handshake.c_str(),handshake.size());
|
||||
r.replace_header("Sec-WebSocket-Key3","janelle!");
|
||||
|
||||
|
||||
BOOST_CHECK(websocketpp::processor::is_websocket_handshake(r));
|
||||
BOOST_CHECK(websocketpp::processor::get_websocket_version(r) == p.get_version());
|
||||
BOOST_CHECK(!p.validate_handshake(r));
|
||||
@@ -136,21 +136,21 @@ BOOST_AUTO_TEST_CASE( bad_host ) {
|
||||
websocketpp::processor::hybi00<websocketpp::http::parser::request,websocketpp::http::parser::response> p(false);
|
||||
websocketpp::uri_ptr u;
|
||||
bool exception = false;
|
||||
|
||||
|
||||
std::string handshake = "GET / HTTP/1.1\r\nHost: www.example.com:70000\r\nConnection: upgrade\r\nUpgrade: websocket\r\nSec-WebSocket-Key2: 17 9 G`ZD9 2 2b 7X 3 /r90\r\n\r\n";
|
||||
|
||||
|
||||
r.consume(handshake.c_str(),handshake.size());
|
||||
r.replace_header("Sec-WebSocket-Key3","janelle!");
|
||||
|
||||
|
||||
BOOST_CHECK(websocketpp::processor::is_websocket_handshake(r));
|
||||
BOOST_CHECK(websocketpp::processor::get_websocket_version(r) == p.get_version());
|
||||
BOOST_CHECK(!p.validate_handshake(r));
|
||||
|
||||
|
||||
try {
|
||||
u = p.get_uri(r);
|
||||
} catch (const websocketpp::uri_exception& e) {
|
||||
exception = true;
|
||||
}
|
||||
|
||||
|
||||
BOOST_CHECK(exception == true);
|
||||
}
|
||||
}
|
||||
@@ -28,7 +28,7 @@ prgs += env.Program('test_extension_permessage_compress_boost', ["test_extension
|
||||
|
||||
if env_cpp11.has_key('WSPP_CPP11_ENABLED'):
|
||||
BOOST_LIBS_CPP11 = boostlibs(['unit_test_framework'],env_cpp11) + [platform_libs] + [polyfill_libs] + ['z']
|
||||
# no C++11 features are used in processor so there are no C++11 versions of
|
||||
# no C++11 features are used in processor so there are no C++11 versions of
|
||||
# these tests.
|
||||
objs += env_cpp11.Object('test_processor_stl.o', ["processor.cpp"], LIBS = BOOST_LIBS_CPP11)
|
||||
objs += env_cpp11.Object('test_hybi13_stl.o', ["hybi13.cpp"], LIBS = BOOST_LIBS_CPP11)
|
||||
@@ -36,7 +36,7 @@ if env_cpp11.has_key('WSPP_CPP11_ENABLED'):
|
||||
objs += env_cpp11.Object('test_hybi07_stl.o', ["hybi07.cpp"], LIBS = BOOST_LIBS_CPP11)
|
||||
objs += env_cpp11.Object('test_hybi00_stl.o', ["hybi00.cpp"], LIBS = BOOST_LIBS_CPP11)
|
||||
objs += env_cpp11.Object('test_extension_permessage_compress_stl.o', ["extension_permessage_compress.cpp"], LIBS = BOOST_LIBS_CPP11 + ['z'])
|
||||
|
||||
|
||||
prgs += env_cpp11.Program('test_processor_stl', ["test_processor_stl.o"], LIBS = BOOST_LIBS_CPP11)
|
||||
prgs += env_cpp11.Program('test_hybi13_stl', ["test_hybi13_stl.o"], LIBS = BOOST_LIBS_CPP11)
|
||||
prgs += env_cpp11.Program('test_hybi08_stl', ["test_hybi08_stl.o"], LIBS = BOOST_LIBS_CPP11)
|
||||
|
||||
@@ -11,10 +11,10 @@
|
||||
* * 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
|
||||
*
|
||||
* 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;
|
||||
@@ -22,7 +22,7 @@
|
||||
* 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.
|
||||
*
|
||||
*
|
||||
*/
|
||||
//#define BOOST_TEST_DYN_LINK
|
||||
#define BOOST_TEST_MODULE extension_permessage_deflate
|
||||
@@ -38,7 +38,7 @@
|
||||
struct config {
|
||||
typedef websocketpp::http::parser::request request_type;
|
||||
};
|
||||
typedef websocketpp::extensions::permessage_deflate::enabled<config>
|
||||
typedef websocketpp::extensions::permessage_deflate::enabled<config>
|
||||
compressor_type;
|
||||
|
||||
using namespace websocketpp;
|
||||
@@ -50,23 +50,23 @@ BOOST_AUTO_TEST_CASE( deflate_init ) {
|
||||
|
||||
neg_ret = compressor.negotiate(attributes);
|
||||
|
||||
BOOST_CHECK_EQUAL( neg_ret.first,
|
||||
BOOST_CHECK_EQUAL( neg_ret.first,
|
||||
extensions::permessage_deflate::error::invalid_parameters );*/
|
||||
|
||||
|
||||
/**
|
||||
* Window size is primarily controlled by the writer. A stream can only be
|
||||
* read by a window size equal to or greater than the one use to compress
|
||||
* it initially. The default windows size is also the maximum window size.
|
||||
* it initially. The default windows size is also the maximum window size.
|
||||
* Thus:
|
||||
*
|
||||
* Outbound window size can be limited unilaterally under the assumption
|
||||
* that the opposite end will be using the default (maximum size which can
|
||||
* read anything)
|
||||
*
|
||||
* Inbound window size must be limited by asking the remote endpoint to
|
||||
* Inbound window size must be limited by asking the remote endpoint to
|
||||
* do so and it agreeing.
|
||||
*
|
||||
* Context takeover is also primarily controlled by the writer. If the
|
||||
*
|
||||
* Context takeover is also primarily controlled by the writer. If the
|
||||
* compressor does not clear its context between messages then the reader
|
||||
* can't either.
|
||||
*
|
||||
@@ -81,17 +81,17 @@ BOOST_AUTO_TEST_CASE( deflate_init ) {
|
||||
* - whether or not to request that the server disallow context takeover
|
||||
*
|
||||
* Server must answer in the following ways
|
||||
* - If client requested a window size limit, is the window size limit
|
||||
* - If client requested a window size limit, is the window size limit
|
||||
* acceptable?
|
||||
* - If client allows window limit requests, should we send one?
|
||||
* - If client requested no context takeover, should we accept?
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
* All Defaults
|
||||
* Req: permessage-compress; method=deflate
|
||||
* Ans: permessage-compress; method=deflate
|
||||
*
|
||||
*
|
||||
* # Client wants to limit the size of inbound windows from server
|
||||
* permessage-compress; method="deflate; s2c_max_window_bits=8, deflate"
|
||||
* Ans: permessage-compress; method="deflate; s2c_max_window_bits=8"
|
||||
@@ -99,13 +99,13 @@ BOOST_AUTO_TEST_CASE( deflate_init ) {
|
||||
* Ans: permessage-compress; method=deflate
|
||||
*
|
||||
* # Server wants to limit the size of inbound windows from client
|
||||
* Client:
|
||||
* Client:
|
||||
* permessage-compress; method="deflate; c2s_max_window_bits, deflate"
|
||||
*
|
||||
*
|
||||
* Server:
|
||||
* permessage-compress; method="deflate; c2s_max_window_bits=8"
|
||||
*
|
||||
* # Client wants to
|
||||
*
|
||||
* # Client wants to
|
||||
*
|
||||
*
|
||||
*
|
||||
@@ -113,7 +113,7 @@ BOOST_AUTO_TEST_CASE( deflate_init ) {
|
||||
*
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -144,30 +144,30 @@ BOOST_AUTO_TEST_CASE( deflate_init ) {
|
||||
attributes.push_back(http::parser::attribute("s2c_max_window_bits","9"));
|
||||
ec = d.init(attributes);
|
||||
BOOST_CHECK( !ec);
|
||||
|
||||
|
||||
attributes.clear();
|
||||
ec = d.init(attributes);
|
||||
BOOST_CHECK( !ec);
|
||||
|
||||
|
||||
processor::extensions::deflate_engine de;
|
||||
|
||||
|
||||
unsigned char test_in[] = "HelloHelloHelloHello";
|
||||
unsigned char test_out[30];
|
||||
|
||||
|
||||
uLongf test_out_size = 30;
|
||||
|
||||
|
||||
int ret;
|
||||
|
||||
ret = compress(test_out, &test_out_size, test_in, 20);
|
||||
|
||||
ret = compress(test_out, &test_out_size, test_in, 20);
|
||||
|
||||
std::cout << ret << std::endl
|
||||
<< websocketpp::utility::to_hex(test_in,20) << std::endl
|
||||
<< websocketpp::utility::to_hex(test_out,test_out_size) << std::endl;
|
||||
|
||||
|
||||
std::string input = "Hello";
|
||||
std::string output = "";
|
||||
ec = de.compress(input,output);
|
||||
|
||||
|
||||
BOOST_CHECK( ec == processor::extensions::error::uninitialized );
|
||||
|
||||
//std::cout << ec.message() << websocketpp::utility::to_hex(output) << std::endl;
|
||||
@@ -180,7 +180,7 @@ BOOST_AUTO_TEST_CASE( deflate_init ) {
|
||||
std::cout << ec.message() << std::endl
|
||||
<< websocketpp::utility::to_hex(input) << std::endl
|
||||
<< websocketpp::utility::to_hex(output) << std::endl;
|
||||
|
||||
|
||||
output = "";
|
||||
|
||||
ec = de.compress(input,output);
|
||||
|
||||
+44
-42
@@ -11,10 +11,10 @@
|
||||
* * 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
|
||||
*
|
||||
* 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;
|
||||
@@ -22,7 +22,7 @@
|
||||
* 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.
|
||||
*
|
||||
*
|
||||
*/
|
||||
//#define BOOST_TEST_DYN_LINK
|
||||
#define BOOST_TEST_MODULE hybi_00_processor
|
||||
@@ -43,15 +43,17 @@ struct stub_config {
|
||||
|
||||
typedef websocketpp::message_buffer::message
|
||||
<websocketpp::message_buffer::alloc::con_msg_manager> message_type;
|
||||
typedef websocketpp::message_buffer::alloc::con_msg_manager<message_type>
|
||||
typedef websocketpp::message_buffer::alloc::con_msg_manager<message_type>
|
||||
con_msg_manager_type;
|
||||
|
||||
static const size_t max_message_size = 16000000;
|
||||
};
|
||||
|
||||
struct processor_setup {
|
||||
processor_setup(bool server)
|
||||
processor_setup(bool server)
|
||||
: msg_manager(new stub_config::con_msg_manager_type())
|
||||
, p(false,server,msg_manager) {}
|
||||
|
||||
|
||||
websocketpp::lib::error_code ec;
|
||||
stub_config::con_msg_manager_type::ptr msg_manager;
|
||||
stub_config::request_type req;
|
||||
@@ -63,44 +65,44 @@ typedef stub_config::message_type::ptr message_ptr;
|
||||
|
||||
BOOST_AUTO_TEST_CASE( exact_match ) {
|
||||
processor_setup env(true);
|
||||
|
||||
|
||||
std::string handshake = "GET / HTTP/1.1\r\nHost: www.example.com\r\nConnection: upgrade\r\nUpgrade: websocket\r\nOrigin: http://example.com\r\nSec-WebSocket-Key1: 3e6b263 4 17 80\r\nSec-WebSocket-Key2: 17 9 G`ZD9 2 2b 7X 3 /r90\r\n\r\n";
|
||||
|
||||
|
||||
env.req.consume(handshake.c_str(),handshake.size());
|
||||
env.req.replace_header("Sec-WebSocket-Key3","WjN}|M(6");
|
||||
|
||||
|
||||
BOOST_CHECK(websocketpp::processor::is_websocket_handshake(env.req));
|
||||
BOOST_CHECK_EQUAL(websocketpp::processor::get_websocket_version(env.req), env.p.get_version());
|
||||
env.ec = env.p.validate_handshake(env.req);
|
||||
BOOST_CHECK(!env.ec);
|
||||
|
||||
|
||||
websocketpp::uri_ptr u;
|
||||
|
||||
BOOST_CHECK_NO_THROW( u = env.p.get_uri(env.req) );
|
||||
|
||||
|
||||
BOOST_CHECK_EQUAL(u->get_secure(), false);
|
||||
BOOST_CHECK_EQUAL(u->get_host(), "www.example.com");
|
||||
BOOST_CHECK_EQUAL(u->get_resource(), "/");
|
||||
BOOST_CHECK_EQUAL(u->get_port(), websocketpp::uri_default_port);
|
||||
|
||||
|
||||
env.p.process_handshake(env.req,"",env.res);
|
||||
|
||||
|
||||
BOOST_CHECK_EQUAL(env.res.get_header("Connection"), "Upgrade");
|
||||
BOOST_CHECK_EQUAL(env.res.get_header("Upgrade"), "WebSocket");
|
||||
BOOST_CHECK_EQUAL(env.res.get_header("Sec-WebSocket-Origin"), "http://example.com");
|
||||
|
||||
|
||||
BOOST_CHECK_EQUAL(env.res.get_header("Sec-WebSocket-Location"), "ws://www.example.com/");
|
||||
BOOST_CHECK_EQUAL(env.res.get_header("Sec-WebSocket-Key3"), "n`9eBk9z$R8pOtVb");
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE( non_get_method ) {
|
||||
processor_setup env(true);
|
||||
|
||||
|
||||
std::string handshake = "POST / HTTP/1.1\r\nHost: www.example.com\r\nConnection: upgrade\r\nUpgrade: websocket\r\nSec-WebSocket-Key1: 3e6b263 4 17 80\r\nSec-WebSocket-Key2: 17 9 G`ZD9 2 2b 7X 3 /r90\r\n\r\n";
|
||||
|
||||
|
||||
env.req.consume(handshake.c_str(),handshake.size());
|
||||
env.req.replace_header("Sec-WebSocket-Key3","janelle!");
|
||||
|
||||
|
||||
BOOST_CHECK(websocketpp::processor::is_websocket_handshake(env.req));
|
||||
BOOST_CHECK_EQUAL(websocketpp::processor::get_websocket_version(env.req), env.p.get_version());
|
||||
BOOST_CHECK_EQUAL( env.p.validate_handshake(env.req), websocketpp::processor::error::invalid_http_method );
|
||||
@@ -108,12 +110,12 @@ BOOST_AUTO_TEST_CASE( non_get_method ) {
|
||||
|
||||
BOOST_AUTO_TEST_CASE( old_http_version ) {
|
||||
processor_setup env(true);
|
||||
|
||||
|
||||
std::string handshake = "GET / HTTP/1.0\r\nHost: www.example.com\r\nConnection: upgrade\r\nUpgrade: websocket\r\nSec-WebSocket-Key1: 3e6b263 4 17 80\r\nSec-WebSocket-Key2: 17 9 G`ZD9 2 2b 7X 3 /r90\r\n\r\n";
|
||||
|
||||
|
||||
env.req.consume(handshake.c_str(),handshake.size());
|
||||
env.req.replace_header("Sec-WebSocket-Key3","janelle!");
|
||||
|
||||
|
||||
BOOST_CHECK(websocketpp::processor::is_websocket_handshake(env.req));
|
||||
BOOST_CHECK_EQUAL(websocketpp::processor::get_websocket_version(env.req), env.p.get_version());
|
||||
BOOST_CHECK_EQUAL( env.p.validate_handshake(env.req), websocketpp::processor::error::invalid_http_version );
|
||||
@@ -121,12 +123,12 @@ BOOST_AUTO_TEST_CASE( old_http_version ) {
|
||||
|
||||
BOOST_AUTO_TEST_CASE( missing_handshake_key1 ) {
|
||||
processor_setup env(true);
|
||||
|
||||
|
||||
std::string handshake = "GET / HTTP/1.1\r\nHost: www.example.com\r\nConnection: upgrade\r\nUpgrade: websocket\r\nSec-WebSocket-Key1: 3e6b263 4 17 80\r\n\r\n";
|
||||
|
||||
|
||||
env.req.consume(handshake.c_str(),handshake.size());
|
||||
env.req.replace_header("Sec-WebSocket-Key3","janelle!");
|
||||
|
||||
|
||||
BOOST_CHECK(websocketpp::processor::is_websocket_handshake(env.req));
|
||||
BOOST_CHECK_EQUAL(websocketpp::processor::get_websocket_version(env.req), env.p.get_version());
|
||||
BOOST_CHECK_EQUAL( env.p.validate_handshake(env.req), websocketpp::processor::error::missing_required_header );
|
||||
@@ -134,12 +136,12 @@ BOOST_AUTO_TEST_CASE( missing_handshake_key1 ) {
|
||||
|
||||
BOOST_AUTO_TEST_CASE( missing_handshake_key2 ) {
|
||||
processor_setup env(true);
|
||||
|
||||
|
||||
std::string handshake = "GET / HTTP/1.1\r\nHost: www.example.com\r\nConnection: upgrade\r\nUpgrade: websocket\r\nSec-WebSocket-Key2: 17 9 G`ZD9 2 2b 7X 3 /r90\r\n\r\n";
|
||||
|
||||
|
||||
env.req.consume(handshake.c_str(),handshake.size());
|
||||
env.req.replace_header("Sec-WebSocket-Key3","janelle!");
|
||||
|
||||
|
||||
BOOST_CHECK(websocketpp::processor::is_websocket_handshake(env.req));
|
||||
BOOST_CHECK_EQUAL(websocketpp::processor::get_websocket_version(env.req), env.p.get_version());
|
||||
BOOST_CHECK_EQUAL( env.p.validate_handshake(env.req), websocketpp::processor::error::missing_required_header );
|
||||
@@ -148,12 +150,12 @@ BOOST_AUTO_TEST_CASE( missing_handshake_key2 ) {
|
||||
BOOST_AUTO_TEST_CASE( bad_host ) {
|
||||
processor_setup env(true);
|
||||
websocketpp::uri_ptr u;
|
||||
|
||||
|
||||
std::string handshake = "GET / HTTP/1.1\r\nHost: www.example.com:70000\r\nConnection: upgrade\r\nUpgrade: websocket\r\nOrigin: http://example.com\r\nSec-WebSocket-Key1: 3e6b263 4 17 80\r\nSec-WebSocket-Key2: 17 9 G`ZD9 2 2b 7X 3 /r90\r\n\r\n";
|
||||
|
||||
|
||||
env.req.consume(handshake.c_str(),handshake.size());
|
||||
env.req.replace_header("Sec-WebSocket-Key3","janelle!");
|
||||
|
||||
|
||||
BOOST_CHECK(websocketpp::processor::is_websocket_handshake(env.req));
|
||||
BOOST_CHECK_EQUAL(websocketpp::processor::get_websocket_version(env.req), env.p.get_version());
|
||||
BOOST_CHECK( !env.p.validate_handshake(env.req) );
|
||||
@@ -163,42 +165,42 @@ BOOST_AUTO_TEST_CASE( bad_host ) {
|
||||
|
||||
BOOST_AUTO_TEST_CASE( extract_subprotocols ) {
|
||||
processor_setup env(true);
|
||||
|
||||
|
||||
std::vector<std::string> subps;
|
||||
|
||||
|
||||
BOOST_CHECK( !env.p.extract_subprotocols(env.req,subps) );
|
||||
BOOST_CHECK_EQUAL( subps.size(), 0 );
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE( prepare_data_frame_null ) {
|
||||
processor_setup env(true);
|
||||
|
||||
|
||||
message_ptr in = env.msg_manager->get_message();
|
||||
message_ptr out = env.msg_manager->get_message();
|
||||
message_ptr invalid;
|
||||
|
||||
|
||||
// empty pointers arguements should return sane error
|
||||
// empty pointers arguements should return sane error
|
||||
BOOST_CHECK_EQUAL( env.p.prepare_data_frame(invalid,invalid), websocketpp::processor::error::invalid_arguments );
|
||||
|
||||
BOOST_CHECK_EQUAL( env.p.prepare_data_frame(in,invalid), websocketpp::processor::error::invalid_arguments );
|
||||
|
||||
BOOST_CHECK_EQUAL( env.p.prepare_data_frame(invalid,out), websocketpp::processor::error::invalid_arguments );
|
||||
|
||||
|
||||
// test valid opcodes
|
||||
// text (1) should be the only valid opcode
|
||||
for (int i = 0; i < 0xF; i++) {
|
||||
in->set_opcode(websocketpp::frame::opcode::value(i));
|
||||
|
||||
|
||||
env.ec = env.p.prepare_data_frame(in,out);
|
||||
|
||||
|
||||
if (i != 1) {
|
||||
BOOST_CHECK_EQUAL( env.ec, websocketpp::processor::error::invalid_opcode );
|
||||
} else {
|
||||
BOOST_CHECK_NE( env.ec, websocketpp::processor::error::invalid_opcode );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* TODO: tests for invalid UTF8
|
||||
char buf[2] = {0x00, 0x00};
|
||||
@@ -213,15 +215,15 @@ BOOST_AUTO_TEST_CASE( prepare_data_frame_null ) {
|
||||
|
||||
BOOST_AUTO_TEST_CASE( prepare_data_frame ) {
|
||||
processor_setup env(true);
|
||||
|
||||
|
||||
message_ptr in = env.msg_manager->get_message();
|
||||
message_ptr out = env.msg_manager->get_message();
|
||||
|
||||
|
||||
in->set_opcode(websocketpp::frame::opcode::text);
|
||||
in->set_payload("foo");
|
||||
|
||||
env.ec = env.p.prepare_data_frame(in,out);
|
||||
|
||||
|
||||
unsigned char raw_header[1] = {0x00};
|
||||
unsigned char raw_payload[4] = {0x66,0x6f,0x6f,0xff};
|
||||
|
||||
|
||||
+35
-33
@@ -11,10 +11,10 @@
|
||||
* * 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
|
||||
*
|
||||
* 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;
|
||||
@@ -22,7 +22,7 @@
|
||||
* 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.
|
||||
*
|
||||
*
|
||||
*/
|
||||
//#define BOOST_TEST_DYN_LINK
|
||||
#define BOOST_TEST_MODULE hybi_07_processor
|
||||
@@ -45,16 +45,18 @@ struct stub_config {
|
||||
|
||||
typedef websocketpp::message_buffer::message
|
||||
<websocketpp::message_buffer::alloc::con_msg_manager> message_type;
|
||||
typedef websocketpp::message_buffer::alloc::con_msg_manager<message_type>
|
||||
typedef websocketpp::message_buffer::alloc::con_msg_manager<message_type>
|
||||
con_msg_manager_type;
|
||||
|
||||
|
||||
typedef websocketpp::random::none::int_generator<uint32_t> rng_type;
|
||||
|
||||
|
||||
static const size_t max_message_size = 16000000;
|
||||
|
||||
/// Extension related config
|
||||
static const bool enable_extensions = false;
|
||||
|
||||
|
||||
/// Extension specific config
|
||||
|
||||
|
||||
/// permessage_compress_config
|
||||
struct permessage_deflate_config {
|
||||
typedef stub_config::request_type request_type;
|
||||
@@ -71,28 +73,28 @@ BOOST_AUTO_TEST_CASE( exact_match ) {
|
||||
stub_config::rng_type rng;
|
||||
websocketpp::processor::hybi07<stub_config> p(false,true,msg_manager,rng);
|
||||
websocketpp::lib::error_code ec;
|
||||
|
||||
|
||||
std::string handshake = "GET / HTTP/1.1\r\nHost: www.example.com\r\nConnection: upgrade\r\nUpgrade: websocket\r\nSec-WebSocket-Version: 7\r\nSec-WebSocket-Key: dGhlIHNhbXBsZSBub25jZQ==\r\n\r\n";
|
||||
|
||||
|
||||
r.consume(handshake.c_str(),handshake.size());
|
||||
|
||||
|
||||
BOOST_CHECK(websocketpp::processor::is_websocket_handshake(r));
|
||||
BOOST_CHECK(websocketpp::processor::get_websocket_version(r) == p.get_version());
|
||||
ec = p.validate_handshake(r);
|
||||
BOOST_CHECK(!ec);
|
||||
|
||||
|
||||
websocketpp::uri_ptr u;
|
||||
|
||||
|
||||
u = p.get_uri(r);
|
||||
|
||||
|
||||
BOOST_CHECK(u->get_valid());
|
||||
BOOST_CHECK(!u->get_secure());
|
||||
BOOST_CHECK_EQUAL(u->get_host(), "www.example.com");
|
||||
BOOST_CHECK_EQUAL(u->get_resource(), "/");
|
||||
BOOST_CHECK_EQUAL(u->get_port(), websocketpp::uri_default_port);
|
||||
|
||||
|
||||
p.process_handshake(r,"",response);
|
||||
|
||||
|
||||
BOOST_CHECK_EQUAL(response.get_header("Connection"), "upgrade");
|
||||
BOOST_CHECK_EQUAL(response.get_header("Upgrade"), "websocket");
|
||||
BOOST_CHECK_EQUAL(response.get_header("Sec-WebSocket-Accept"), "s3pPLMBiTxaQ9kYGzzhZRbK+xOo=");
|
||||
@@ -107,9 +109,9 @@ BOOST_AUTO_TEST_CASE( non_get_method ) {
|
||||
websocketpp::lib::error_code ec;
|
||||
|
||||
std::string handshake = "POST / HTTP/1.1\r\nHost: www.example.com\r\nConnection: upgrade\r\nUpgrade: websocket\r\nSec-WebSocket-Version: 7\r\nSec-WebSocket-Key: foo\r\n\r\n";
|
||||
|
||||
|
||||
r.consume(handshake.c_str(),handshake.size());
|
||||
|
||||
|
||||
BOOST_CHECK(websocketpp::processor::is_websocket_handshake(r));
|
||||
BOOST_CHECK(websocketpp::processor::get_websocket_version(r) == p.get_version());
|
||||
ec = p.validate_handshake(r);
|
||||
@@ -123,11 +125,11 @@ BOOST_AUTO_TEST_CASE( old_http_version ) {
|
||||
stub_config::rng_type rng;
|
||||
websocketpp::processor::hybi07<stub_config> p(false,true,msg_manager,rng);
|
||||
websocketpp::lib::error_code ec;
|
||||
|
||||
|
||||
std::string handshake = "GET / HTTP/1.0\r\nHost: www.example.com\r\nConnection: upgrade\r\nUpgrade: websocket\r\nSec-WebSocket-Version: 7\r\nSec-WebSocket-Key: foo\r\n\r\n";
|
||||
|
||||
|
||||
r.consume(handshake.c_str(),handshake.size());
|
||||
|
||||
|
||||
BOOST_CHECK(websocketpp::processor::is_websocket_handshake(r));
|
||||
BOOST_CHECK(websocketpp::processor::get_websocket_version(r) == p.get_version());
|
||||
ec = p.validate_handshake(r);
|
||||
@@ -141,11 +143,11 @@ BOOST_AUTO_TEST_CASE( missing_handshake_key1 ) {
|
||||
stub_config::rng_type rng;
|
||||
websocketpp::processor::hybi07<stub_config> p(false,true,msg_manager,rng);
|
||||
websocketpp::lib::error_code ec;
|
||||
|
||||
|
||||
std::string handshake = "GET / HTTP/1.1\r\nHost: www.example.com\r\nConnection: upgrade\r\nUpgrade: websocket\r\nSec-WebSocket-Version: 7\r\n\r\n";
|
||||
|
||||
|
||||
r.consume(handshake.c_str(),handshake.size());
|
||||
|
||||
|
||||
BOOST_CHECK(websocketpp::processor::is_websocket_handshake(r));
|
||||
BOOST_CHECK(websocketpp::processor::get_websocket_version(r) == p.get_version());
|
||||
ec = p.validate_handshake(r);
|
||||
@@ -159,11 +161,11 @@ BOOST_AUTO_TEST_CASE( missing_handshake_key2 ) {
|
||||
stub_config::rng_type rng;
|
||||
websocketpp::processor::hybi07<stub_config> p(false,true,msg_manager,rng);
|
||||
websocketpp::lib::error_code ec;
|
||||
|
||||
|
||||
std::string handshake = "GET / HTTP/1.1\r\nHost: www.example.com\r\nConnection: upgrade\r\nUpgrade: websocket\r\nSec-WebSocket-Version: 7\r\n\r\n";
|
||||
|
||||
|
||||
r.consume(handshake.c_str(),handshake.size());
|
||||
|
||||
|
||||
BOOST_CHECK(websocketpp::processor::is_websocket_handshake(r));
|
||||
BOOST_CHECK(websocketpp::processor::get_websocket_version(r) == p.get_version());
|
||||
ec = p.validate_handshake(r);
|
||||
@@ -177,15 +179,15 @@ BOOST_AUTO_TEST_CASE( bad_host ) {
|
||||
stub_config::rng_type rng;
|
||||
websocketpp::processor::hybi07<stub_config> p(false,true,msg_manager,rng);
|
||||
websocketpp::lib::error_code ec;
|
||||
|
||||
|
||||
std::string handshake = "GET / HTTP/1.1\r\nHost: www.example.com:70000\r\nConnection: upgrade\r\nUpgrade: websocket\r\nSec-WebSocket-Version: 7\r\nSec-WebSocket-Key: foo\r\n\r\n";
|
||||
|
||||
|
||||
r.consume(handshake.c_str(),handshake.size());
|
||||
|
||||
|
||||
BOOST_CHECK(websocketpp::processor::is_websocket_handshake(r));
|
||||
BOOST_CHECK(websocketpp::processor::get_websocket_version(r) == p.get_version());
|
||||
ec = p.validate_handshake(r);
|
||||
BOOST_CHECK( !ec );
|
||||
|
||||
|
||||
BOOST_CHECK( !p.get_uri(r)->get_valid() );
|
||||
}
|
||||
+34
-32
@@ -11,10 +11,10 @@
|
||||
* * 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
|
||||
*
|
||||
* 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;
|
||||
@@ -22,7 +22,7 @@
|
||||
* 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.
|
||||
*
|
||||
*
|
||||
*/
|
||||
//#define BOOST_TEST_DYN_LINK
|
||||
#define BOOST_TEST_MODULE hybi_08_processor
|
||||
@@ -45,16 +45,18 @@ struct stub_config {
|
||||
|
||||
typedef websocketpp::message_buffer::message
|
||||
<websocketpp::message_buffer::alloc::con_msg_manager> message_type;
|
||||
typedef websocketpp::message_buffer::alloc::con_msg_manager<message_type>
|
||||
typedef websocketpp::message_buffer::alloc::con_msg_manager<message_type>
|
||||
con_msg_manager_type;
|
||||
|
||||
typedef websocketpp::random::none::int_generator<uint32_t> rng_type;
|
||||
|
||||
static const size_t max_message_size = 16000000;
|
||||
|
||||
/// Extension related config
|
||||
static const bool enable_extensions = false;
|
||||
|
||||
|
||||
/// Extension specific config
|
||||
|
||||
|
||||
/// permessage_deflate_config
|
||||
struct permessage_deflate_config {
|
||||
typedef stub_config::request_type request_type;
|
||||
@@ -71,28 +73,28 @@ BOOST_AUTO_TEST_CASE( exact_match ) {
|
||||
stub_config::rng_type rng;
|
||||
websocketpp::processor::hybi08<stub_config> p(false,true,msg_manager,rng);
|
||||
websocketpp::lib::error_code ec;
|
||||
|
||||
|
||||
std::string handshake = "GET / HTTP/1.1\r\nHost: www.example.com\r\nConnection: upgrade\r\nUpgrade: websocket\r\nSec-WebSocket-Version: 8\r\nSec-WebSocket-Key: dGhlIHNhbXBsZSBub25jZQ==\r\n\r\n";
|
||||
|
||||
|
||||
r.consume(handshake.c_str(),handshake.size());
|
||||
|
||||
|
||||
BOOST_CHECK(websocketpp::processor::is_websocket_handshake(r));
|
||||
BOOST_CHECK(websocketpp::processor::get_websocket_version(r) == p.get_version());
|
||||
ec = p.validate_handshake(r);
|
||||
BOOST_CHECK(!ec);
|
||||
|
||||
|
||||
websocketpp::uri_ptr u;
|
||||
|
||||
|
||||
u = p.get_uri(r);
|
||||
|
||||
|
||||
BOOST_CHECK(u->get_valid() == true);
|
||||
BOOST_CHECK(u->get_secure() == false);
|
||||
BOOST_CHECK(u->get_host() == "www.example.com");
|
||||
BOOST_CHECK(u->get_resource() == "/");
|
||||
BOOST_CHECK(u->get_port() == websocketpp::uri_default_port);
|
||||
|
||||
|
||||
p.process_handshake(r,"",response);
|
||||
|
||||
|
||||
BOOST_CHECK(response.get_header("Connection") == "upgrade");
|
||||
BOOST_CHECK(response.get_header("Upgrade") == "websocket");
|
||||
BOOST_CHECK(response.get_header("Sec-WebSocket-Accept") == "s3pPLMBiTxaQ9kYGzzhZRbK+xOo=");
|
||||
@@ -107,9 +109,9 @@ BOOST_AUTO_TEST_CASE( non_get_method ) {
|
||||
websocketpp::lib::error_code ec;
|
||||
|
||||
std::string handshake = "POST / HTTP/1.1\r\nHost: www.example.com\r\nConnection: upgrade\r\nUpgrade: websocket\r\nSec-WebSocket-Version: 8\r\nSec-WebSocket-Key: foo\r\n\r\n";
|
||||
|
||||
|
||||
r.consume(handshake.c_str(),handshake.size());
|
||||
|
||||
|
||||
BOOST_CHECK(websocketpp::processor::is_websocket_handshake(r));
|
||||
BOOST_CHECK(websocketpp::processor::get_websocket_version(r) == p.get_version());
|
||||
ec = p.validate_handshake(r);
|
||||
@@ -123,11 +125,11 @@ BOOST_AUTO_TEST_CASE( old_http_version ) {
|
||||
stub_config::rng_type rng;
|
||||
websocketpp::processor::hybi08<stub_config> p(false,true,msg_manager,rng);
|
||||
websocketpp::lib::error_code ec;
|
||||
|
||||
|
||||
std::string handshake = "GET / HTTP/1.0\r\nHost: www.example.com\r\nConnection: upgrade\r\nUpgrade: websocket\r\nSec-WebSocket-Version: 8\r\nSec-WebSocket-Key: foo\r\n\r\n";
|
||||
|
||||
|
||||
r.consume(handshake.c_str(),handshake.size());
|
||||
|
||||
|
||||
BOOST_CHECK(websocketpp::processor::is_websocket_handshake(r));
|
||||
BOOST_CHECK(websocketpp::processor::get_websocket_version(r) == p.get_version());
|
||||
ec = p.validate_handshake(r);
|
||||
@@ -141,11 +143,11 @@ BOOST_AUTO_TEST_CASE( missing_handshake_key1 ) {
|
||||
stub_config::rng_type rng;
|
||||
websocketpp::processor::hybi08<stub_config> p(false,true,msg_manager,rng);
|
||||
websocketpp::lib::error_code ec;
|
||||
|
||||
|
||||
std::string handshake = "GET / HTTP/1.1\r\nHost: www.example.com\r\nConnection: upgrade\r\nUpgrade: websocket\r\nSec-WebSocket-Version: 8\r\n\r\n";
|
||||
|
||||
|
||||
r.consume(handshake.c_str(),handshake.size());
|
||||
|
||||
|
||||
BOOST_CHECK(websocketpp::processor::is_websocket_handshake(r));
|
||||
BOOST_CHECK(websocketpp::processor::get_websocket_version(r) == p.get_version());
|
||||
ec = p.validate_handshake(r);
|
||||
@@ -159,11 +161,11 @@ BOOST_AUTO_TEST_CASE( missing_handshake_key2 ) {
|
||||
stub_config::rng_type rng;
|
||||
websocketpp::processor::hybi08<stub_config> p(false,true,msg_manager,rng);
|
||||
websocketpp::lib::error_code ec;
|
||||
|
||||
|
||||
std::string handshake = "GET / HTTP/1.1\r\nHost: www.example.com\r\nConnection: upgrade\r\nUpgrade: websocket\r\nSec-WebSocket-Version: 8\r\n\r\n";
|
||||
|
||||
|
||||
r.consume(handshake.c_str(),handshake.size());
|
||||
|
||||
|
||||
BOOST_CHECK(websocketpp::processor::is_websocket_handshake(r));
|
||||
BOOST_CHECK(websocketpp::processor::get_websocket_version(r) == p.get_version());
|
||||
ec = p.validate_handshake(r);
|
||||
@@ -178,18 +180,18 @@ BOOST_AUTO_TEST_CASE( bad_host ) {
|
||||
websocketpp::processor::hybi08<stub_config> p(false,true,msg_manager,rng);
|
||||
websocketpp::uri_ptr u;
|
||||
websocketpp::lib::error_code ec;
|
||||
|
||||
|
||||
std::string handshake = "GET / HTTP/1.1\r\nHost: www.example.com:70000\r\nConnection: upgrade\r\nUpgrade: websocket\r\nSec-WebSocket-Version: 8\r\nSec-WebSocket-Key: foo\r\n\r\n";
|
||||
|
||||
|
||||
r.consume(handshake.c_str(),handshake.size());
|
||||
|
||||
|
||||
BOOST_CHECK(websocketpp::processor::is_websocket_handshake(r));
|
||||
BOOST_CHECK(websocketpp::processor::get_websocket_version(r) == p.get_version());
|
||||
ec = p.validate_handshake(r);
|
||||
BOOST_CHECK( !ec );
|
||||
|
||||
|
||||
u = p.get_uri(r);
|
||||
|
||||
|
||||
BOOST_CHECK( !u->get_valid() );
|
||||
}
|
||||
|
||||
+118
-86
@@ -11,10 +11,10 @@
|
||||
* * 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
|
||||
*
|
||||
* 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;
|
||||
@@ -22,7 +22,7 @@
|
||||
* 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.
|
||||
*
|
||||
*
|
||||
*/
|
||||
//#define BOOST_TEST_DYN_LINK
|
||||
#define BOOST_TEST_MODULE hybi_13_processor
|
||||
@@ -37,7 +37,7 @@
|
||||
#include <websocketpp/http/response.hpp>
|
||||
#include <websocketpp/message_buffer/message.hpp>
|
||||
#include <websocketpp/message_buffer/alloc.hpp>
|
||||
#include <websocketpp/random/none.hpp>
|
||||
#include <websocketpp/random/none.hpp>
|
||||
|
||||
#include <websocketpp/extensions/permessage_deflate/disabled.hpp>
|
||||
#include <websocketpp/extensions/permessage_deflate/enabled.hpp>
|
||||
@@ -48,11 +48,11 @@ struct stub_config {
|
||||
|
||||
typedef websocketpp::message_buffer::message
|
||||
<websocketpp::message_buffer::alloc::con_msg_manager> message_type;
|
||||
typedef websocketpp::message_buffer::alloc::con_msg_manager<message_type>
|
||||
typedef websocketpp::message_buffer::alloc::con_msg_manager<message_type>
|
||||
con_msg_manager_type;
|
||||
|
||||
|
||||
typedef websocketpp::random::none::int_generator<uint32_t> rng_type;
|
||||
|
||||
|
||||
struct permessage_deflate_config {
|
||||
typedef stub_config::request_type request_type;
|
||||
};
|
||||
@@ -60,6 +60,7 @@ struct stub_config {
|
||||
typedef websocketpp::extensions::permessage_deflate::disabled
|
||||
<permessage_deflate_config> permessage_deflate_type;
|
||||
|
||||
static const size_t max_message_size = 16000000;
|
||||
static const bool enable_extensions = false;
|
||||
};
|
||||
|
||||
@@ -69,18 +70,19 @@ struct stub_config_ext {
|
||||
|
||||
typedef websocketpp::message_buffer::message
|
||||
<websocketpp::message_buffer::alloc::con_msg_manager> message_type;
|
||||
typedef websocketpp::message_buffer::alloc::con_msg_manager<message_type>
|
||||
typedef websocketpp::message_buffer::alloc::con_msg_manager<message_type>
|
||||
con_msg_manager_type;
|
||||
|
||||
|
||||
typedef websocketpp::random::none::int_generator<uint32_t> rng_type;
|
||||
|
||||
|
||||
struct permessage_deflate_config {
|
||||
typedef stub_config_ext::request_type request_type;
|
||||
};
|
||||
|
||||
|
||||
typedef websocketpp::extensions::permessage_deflate::enabled
|
||||
<permessage_deflate_config> permessage_deflate_type;
|
||||
|
||||
static const size_t max_message_size = 16000000;
|
||||
static const bool enable_extensions = true;
|
||||
};
|
||||
|
||||
@@ -90,10 +92,10 @@ typedef stub_config::message_type::ptr message_ptr;
|
||||
// Set up a structure that constructs new copies of all of the support structure
|
||||
// for using connection processors
|
||||
struct processor_setup {
|
||||
processor_setup(bool server)
|
||||
processor_setup(bool server)
|
||||
: msg_manager(new con_msg_manager_type())
|
||||
, p(false,server,msg_manager,rng) {}
|
||||
|
||||
|
||||
websocketpp::lib::error_code ec;
|
||||
con_msg_manager_type::ptr msg_manager;
|
||||
stub_config::rng_type rng;
|
||||
@@ -103,10 +105,10 @@ struct processor_setup {
|
||||
};
|
||||
|
||||
struct processor_setup_ext {
|
||||
processor_setup_ext(bool server)
|
||||
processor_setup_ext(bool server)
|
||||
: msg_manager(new con_msg_manager_type())
|
||||
, p(false,server,msg_manager,rng) {}
|
||||
|
||||
|
||||
websocketpp::lib::error_code ec;
|
||||
con_msg_manager_type::ptr msg_manager;
|
||||
stub_config::rng_type rng;
|
||||
@@ -117,26 +119,26 @@ struct processor_setup_ext {
|
||||
|
||||
BOOST_AUTO_TEST_CASE( exact_match ) {
|
||||
processor_setup env(true);
|
||||
|
||||
|
||||
std::string handshake = "GET / HTTP/1.1\r\nHost: www.example.com\r\nConnection: upgrade\r\nUpgrade: websocket\r\nSec-WebSocket-Version: 13\r\nSec-WebSocket-Key: dGhlIHNhbXBsZSBub25jZQ==\r\n\r\n";
|
||||
|
||||
|
||||
env.req.consume(handshake.c_str(),handshake.size());
|
||||
|
||||
|
||||
BOOST_CHECK(websocketpp::processor::is_websocket_handshake(env.req));
|
||||
BOOST_CHECK_EQUAL(websocketpp::processor::get_websocket_version(env.req), env.p.get_version());
|
||||
BOOST_CHECK(!env.p.validate_handshake(env.req));
|
||||
|
||||
|
||||
websocketpp::uri_ptr u;
|
||||
|
||||
|
||||
BOOST_CHECK_NO_THROW( u = env.p.get_uri(env.req) );
|
||||
|
||||
|
||||
BOOST_CHECK_EQUAL(u->get_secure(), false);
|
||||
BOOST_CHECK_EQUAL(u->get_host(), "www.example.com");
|
||||
BOOST_CHECK_EQUAL(u->get_resource(), "/");
|
||||
BOOST_CHECK_EQUAL(u->get_port(), websocketpp::uri_default_port);
|
||||
|
||||
|
||||
env.p.process_handshake(env.req,"",env.res);
|
||||
|
||||
|
||||
BOOST_CHECK_EQUAL(env.res.get_header("Connection"), "upgrade");
|
||||
BOOST_CHECK_EQUAL(env.res.get_header("Upgrade"), "websocket");
|
||||
BOOST_CHECK_EQUAL(env.res.get_header("Sec-WebSocket-Accept"), "s3pPLMBiTxaQ9kYGzzhZRbK+xOo=");
|
||||
@@ -146,9 +148,9 @@ BOOST_AUTO_TEST_CASE( non_get_method ) {
|
||||
processor_setup env(true);
|
||||
|
||||
std::string handshake = "POST / HTTP/1.1\r\nHost: www.example.com\r\nConnection: upgrade\r\nUpgrade: websocket\r\nSec-WebSocket-Version: 13\r\nSec-WebSocket-Key: foo\r\n\r\n";
|
||||
|
||||
|
||||
env.req.consume(handshake.c_str(),handshake.size());
|
||||
|
||||
|
||||
BOOST_CHECK(websocketpp::processor::is_websocket_handshake(env.req));
|
||||
BOOST_CHECK_EQUAL(websocketpp::processor::get_websocket_version(env.req), env.p.get_version());
|
||||
BOOST_CHECK( env.p.validate_handshake(env.req) == websocketpp::processor::error::invalid_http_method );
|
||||
@@ -156,11 +158,11 @@ BOOST_AUTO_TEST_CASE( non_get_method ) {
|
||||
|
||||
BOOST_AUTO_TEST_CASE( old_http_version ) {
|
||||
processor_setup env(true);
|
||||
|
||||
|
||||
std::string handshake = "GET / HTTP/1.0\r\nHost: www.example.com\r\nConnection: upgrade\r\nUpgrade: websocket\r\nSec-WebSocket-Version: 13\r\nSec-WebSocket-Key: foo\r\n\r\n";
|
||||
|
||||
|
||||
env.req.consume(handshake.c_str(),handshake.size());
|
||||
|
||||
|
||||
BOOST_CHECK(websocketpp::processor::is_websocket_handshake(env.req));
|
||||
BOOST_CHECK_EQUAL(websocketpp::processor::get_websocket_version(env.req), env.p.get_version());
|
||||
BOOST_CHECK_EQUAL( env.p.validate_handshake(env.req), websocketpp::processor::error::invalid_http_version );
|
||||
@@ -168,11 +170,11 @@ BOOST_AUTO_TEST_CASE( old_http_version ) {
|
||||
|
||||
BOOST_AUTO_TEST_CASE( missing_handshake_key1 ) {
|
||||
processor_setup env(true);
|
||||
|
||||
|
||||
std::string handshake = "GET / HTTP/1.1\r\nHost: www.example.com\r\nConnection: upgrade\r\nUpgrade: websocket\r\nSec-WebSocket-Version: 13\r\n\r\n";
|
||||
|
||||
|
||||
env.req.consume(handshake.c_str(),handshake.size());
|
||||
|
||||
|
||||
BOOST_CHECK( websocketpp::processor::is_websocket_handshake(env.req) );
|
||||
BOOST_CHECK_EQUAL( websocketpp::processor::get_websocket_version(env.req), env.p.get_version() );
|
||||
BOOST_CHECK_EQUAL( env.p.validate_handshake(env.req), websocketpp::processor::error::missing_required_header );
|
||||
@@ -180,11 +182,11 @@ BOOST_AUTO_TEST_CASE( missing_handshake_key1 ) {
|
||||
|
||||
BOOST_AUTO_TEST_CASE( missing_handshake_key2 ) {
|
||||
processor_setup env(true);
|
||||
|
||||
|
||||
std::string handshake = "GET / HTTP/1.1\r\nHost: www.example.com\r\nConnection: upgrade\r\nUpgrade: websocket\r\nSec-WebSocket-Version: 13\r\n\r\n";
|
||||
|
||||
|
||||
env.req.consume(handshake.c_str(),handshake.size());
|
||||
|
||||
|
||||
BOOST_CHECK( websocketpp::processor::is_websocket_handshake(env.req) );
|
||||
BOOST_CHECK_EQUAL( websocketpp::processor::get_websocket_version(env.req), env.p.get_version() );
|
||||
BOOST_CHECK_EQUAL( env.p.validate_handshake(env.req), websocketpp::processor::error::missing_required_header );
|
||||
@@ -192,14 +194,14 @@ BOOST_AUTO_TEST_CASE( missing_handshake_key2 ) {
|
||||
|
||||
BOOST_AUTO_TEST_CASE( bad_host ) {
|
||||
processor_setup env(true);
|
||||
|
||||
|
||||
std::string handshake = "GET / HTTP/1.1\r\nHost: www.example.com:70000\r\nConnection: upgrade\r\nUpgrade: websocket\r\nSec-WebSocket-Version: 13\r\nSec-WebSocket-Key: foo\r\n\r\n";
|
||||
|
||||
|
||||
env.req.consume(handshake.c_str(),handshake.size());
|
||||
|
||||
|
||||
BOOST_CHECK( websocketpp::processor::is_websocket_handshake(env.req) );
|
||||
BOOST_CHECK_EQUAL( websocketpp::processor::get_websocket_version(env.req), env.p.get_version() );
|
||||
BOOST_CHECK( !env.p.validate_handshake(env.req) );
|
||||
BOOST_CHECK( !env.p.validate_handshake(env.req) );
|
||||
BOOST_CHECK( !env.p.get_uri(env.req)->get_valid() );
|
||||
}
|
||||
|
||||
@@ -224,11 +226,11 @@ BOOST_AUTO_TEST_CASE( frame_empty_binary_unmasked ) {
|
||||
processor_setup env1(false);
|
||||
|
||||
size_t ret1 = env1.p.consume(frame,2,env1.ec);
|
||||
|
||||
|
||||
BOOST_CHECK_EQUAL( ret1, 2 );
|
||||
BOOST_CHECK( !env1.ec );
|
||||
BOOST_CHECK_EQUAL( env1.p.ready(), true );
|
||||
|
||||
BOOST_CHECK_EQUAL( env1.p.ready(), true );
|
||||
|
||||
// two separate chunks
|
||||
processor_setup env2(false);
|
||||
|
||||
@@ -245,12 +247,12 @@ BOOST_AUTO_TEST_CASE( frame_small_binary_unmasked ) {
|
||||
processor_setup env(false);
|
||||
|
||||
uint8_t frame[4] = {0x82, 0x02, 0x2A, 0x2A};
|
||||
|
||||
|
||||
BOOST_CHECK_EQUAL( env.p.get_message(), message_ptr() );
|
||||
BOOST_CHECK_EQUAL( env.p.consume(frame,4,env.ec), 4 );
|
||||
BOOST_CHECK( !env.ec );
|
||||
BOOST_CHECK_EQUAL( env.p.ready(), true );
|
||||
|
||||
|
||||
message_ptr foo = env.p.get_message();
|
||||
|
||||
BOOST_CHECK_EQUAL( env.p.get_message(), message_ptr() );
|
||||
@@ -272,7 +274,7 @@ BOOST_AUTO_TEST_CASE( frame_extended_binary_unmasked ) {
|
||||
BOOST_CHECK_EQUAL( env.p.consume(frame,130,env.ec), 130 );
|
||||
BOOST_CHECK( !env.ec );
|
||||
BOOST_CHECK_EQUAL( env.p.ready(), true );
|
||||
|
||||
|
||||
message_ptr foo = env.p.get_message();
|
||||
|
||||
BOOST_CHECK_EQUAL( env.p.get_message(), message_ptr() );
|
||||
@@ -289,7 +291,7 @@ BOOST_AUTO_TEST_CASE( frame_jumbo_binary_unmasked ) {
|
||||
BOOST_CHECK_EQUAL( env.p.consume(frame,130,env.ec), 130 );
|
||||
BOOST_CHECK( !env.ec );
|
||||
BOOST_CHECK_EQUAL( env.p.ready(), true );
|
||||
|
||||
|
||||
message_ptr foo = env.p.get_message();
|
||||
|
||||
BOOST_CHECK_EQUAL( env.p.get_message(), message_ptr() );
|
||||
@@ -315,7 +317,7 @@ BOOST_AUTO_TEST_CASE( rsv_bits_used ) {
|
||||
|
||||
for (int i = 0; i < 3; i++) {
|
||||
processor_setup env(false);
|
||||
|
||||
|
||||
BOOST_CHECK_EQUAL( env.p.get_message(), message_ptr() );
|
||||
BOOST_CHECK_GT( env.p.consume(frame[i],2,env.ec), 0 );
|
||||
BOOST_CHECK_EQUAL( env.ec, websocketpp::processor::error::invalid_rsv_bit );
|
||||
@@ -338,7 +340,7 @@ BOOST_AUTO_TEST_CASE( reserved_opcode_used ) {
|
||||
|
||||
for (int i = 0; i < 10; i++) {
|
||||
processor_setup env(false);
|
||||
|
||||
|
||||
BOOST_CHECK_EQUAL( env.p.get_message(), message_ptr() );
|
||||
BOOST_CHECK_GT( env.p.consume(frame[i],2,env.ec), 0 );
|
||||
BOOST_CHECK_EQUAL( env.ec, websocketpp::processor::error::invalid_opcode );
|
||||
@@ -370,7 +372,7 @@ BOOST_AUTO_TEST_CASE( fragmented_binary_message ) {
|
||||
BOOST_CHECK( !env0.ec );
|
||||
BOOST_CHECK_EQUAL( env0.p.ready(), true );
|
||||
BOOST_CHECK_EQUAL( env0.p.get_message()->get_payload(), "**" );
|
||||
|
||||
|
||||
// read fragmented message in two chunks
|
||||
BOOST_CHECK_EQUAL( env0.p.get_message(), message_ptr() );
|
||||
BOOST_CHECK_EQUAL( env0.p.consume(frame0,3,env0.ec), 3 );
|
||||
@@ -442,25 +444,25 @@ BOOST_AUTO_TEST_CASE( frame_small_binary_masked ) {
|
||||
BOOST_AUTO_TEST_CASE( masked_fragmented_binary_message ) {
|
||||
processor_setup env(true);
|
||||
|
||||
uint8_t frame0[14] = {0x02, 0x81, 0xAB, 0x23, 0x98, 0x45, 0x81,
|
||||
uint8_t frame0[14] = {0x02, 0x81, 0xAB, 0x23, 0x98, 0x45, 0x81,
|
||||
0x80, 0x81, 0xB8, 0x34, 0x12, 0xFF, 0x92};
|
||||
|
||||
// read fragmented message in one chunk
|
||||
BOOST_CHECK_EQUAL( env.p.get_message(), message_ptr() );
|
||||
BOOST_CHECK_EQUAL( env.p.consume(frame0,14,env.ec), 14 );
|
||||
BOOST_CHECK( !env.ec );
|
||||
BOOST_CHECK_EQUAL( env.p.ready(), true );
|
||||
BOOST_CHECK_EQUAL( env.p.ready(), true );
|
||||
BOOST_CHECK_EQUAL( env.p.get_message()->get_payload(), "**" );
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE( prepare_data_frame ) {
|
||||
processor_setup env(true);
|
||||
|
||||
|
||||
message_ptr in = env.msg_manager->get_message();
|
||||
message_ptr out = env.msg_manager->get_message();
|
||||
message_ptr invalid;
|
||||
|
||||
// empty pointers arguements should return sane error
|
||||
// empty pointers arguements should return sane error
|
||||
BOOST_CHECK_EQUAL( env.p.prepare_data_frame(invalid,invalid), websocketpp::processor::error::invalid_arguments );
|
||||
|
||||
BOOST_CHECK_EQUAL( env.p.prepare_data_frame(in,invalid), websocketpp::processor::error::invalid_arguments );
|
||||
@@ -471,43 +473,73 @@ BOOST_AUTO_TEST_CASE( prepare_data_frame ) {
|
||||
// control opcodes should return an error, data ones shouldn't
|
||||
for (int i = 0; i < 0xF; i++) {
|
||||
in->set_opcode(websocketpp::frame::opcode::value(i));
|
||||
|
||||
|
||||
env.ec = env.p.prepare_data_frame(in,out);
|
||||
|
||||
|
||||
if (websocketpp::frame::opcode::is_control(in->get_opcode())) {
|
||||
BOOST_CHECK_EQUAL( env.ec, websocketpp::processor::error::invalid_opcode );
|
||||
} else {
|
||||
BOOST_CHECK_NE( env.ec, websocketpp::processor::error::invalid_opcode );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
//in.set_payload("foo");
|
||||
|
||||
|
||||
//e = prepare_data_frame(in,out);
|
||||
|
||||
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE( single_frame_message_too_large ) {
|
||||
processor_setup env(true);
|
||||
|
||||
env.p.set_max_message_size(3);
|
||||
|
||||
uint8_t frame0[10] = {0x82, 0x84, 0x00, 0x00, 0x00, 0x00, 0x01, 0x01, 0x01, 0x01};
|
||||
|
||||
// read message that is one byte too large
|
||||
BOOST_CHECK_EQUAL( env.p.consume(frame0,10,env.ec), 6 );
|
||||
BOOST_CHECK_EQUAL( env.ec, websocketpp::processor::error::message_too_big );
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE( multiple_frame_message_too_large ) {
|
||||
processor_setup env(true);
|
||||
|
||||
env.p.set_max_message_size(4);
|
||||
|
||||
uint8_t frame0[8] = {0x02, 0x82, 0x00, 0x00, 0x00, 0x00, 0x01, 0x01};
|
||||
uint8_t frame1[9] = {0x80, 0x83, 0x00, 0x00, 0x00, 0x00, 0x01, 0x01, 0x01};
|
||||
|
||||
// read first message frame with size under the limit
|
||||
BOOST_CHECK_EQUAL( env.p.consume(frame0,8,env.ec), 8 );
|
||||
BOOST_CHECK( !env.ec );
|
||||
|
||||
// read second message frame that puts the size over the limit
|
||||
BOOST_CHECK_EQUAL( env.p.consume(frame1,9,env.ec), 6 );
|
||||
BOOST_CHECK_EQUAL( env.ec, websocketpp::processor::error::message_too_big );
|
||||
}
|
||||
|
||||
|
||||
|
||||
BOOST_AUTO_TEST_CASE( client_handshake_request ) {
|
||||
processor_setup env(false);
|
||||
|
||||
|
||||
websocketpp::uri_ptr u(new websocketpp::uri("ws://localhost/"));
|
||||
|
||||
|
||||
env.p.client_handshake_request(env.req,u, std::vector<std::string>());
|
||||
|
||||
|
||||
BOOST_CHECK_EQUAL( env.req.get_method(), "GET" );
|
||||
BOOST_CHECK_EQUAL( env.req.get_version(), "HTTP/1.1");
|
||||
BOOST_CHECK_EQUAL( env.req.get_uri(), "/");
|
||||
|
||||
|
||||
BOOST_CHECK_EQUAL( env.req.get_header("Host"), "localhost");
|
||||
BOOST_CHECK_EQUAL( env.req.get_header("Sec-WebSocket-Version"), "13");
|
||||
BOOST_CHECK_EQUAL( env.req.get_header("Connection"), "Upgrade");
|
||||
BOOST_CHECK_EQUAL( env.req.get_header("Upgrade"), "websocket");
|
||||
}
|
||||
|
||||
// TODO:
|
||||
// TODO:
|
||||
// test cases
|
||||
// - adding headers
|
||||
// - adding Upgrade header
|
||||
@@ -524,48 +556,48 @@ BOOST_AUTO_TEST_CASE( client_handshake_request ) {
|
||||
|
||||
BOOST_AUTO_TEST_CASE( client_handshake_response_404 ) {
|
||||
processor_setup env(false);
|
||||
|
||||
|
||||
std::string res = "HTTP/1.1 404 Not Found\r\n\r\n";
|
||||
env.res.consume(res.data(),res.size());
|
||||
|
||||
|
||||
BOOST_CHECK_EQUAL( env.p.validate_server_handshake_response(env.req,env.res), websocketpp::processor::error::invalid_http_status );
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE( client_handshake_response_no_upgrade ) {
|
||||
processor_setup env(false);
|
||||
|
||||
|
||||
std::string res = "HTTP/1.1 101 Switching Protocols\r\n\r\n";
|
||||
env.res.consume(res.data(),res.size());
|
||||
|
||||
|
||||
BOOST_CHECK_EQUAL( env.p.validate_server_handshake_response(env.req,env.res), websocketpp::processor::error::missing_required_header );
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE( client_handshake_response_no_connection ) {
|
||||
processor_setup env(false);
|
||||
|
||||
|
||||
std::string res = "HTTP/1.1 101 Switching Protocols\r\nUpgrade: foo, wEbsOckEt\r\n\r\n";
|
||||
env.res.consume(res.data(),res.size());
|
||||
|
||||
|
||||
BOOST_CHECK_EQUAL( env.p.validate_server_handshake_response(env.req,env.res), websocketpp::processor::error::missing_required_header );
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE( client_handshake_response_no_accept ) {
|
||||
processor_setup env(false);
|
||||
|
||||
|
||||
std::string res = "HTTP/1.1 101 Switching Protocols\r\nUpgrade: foo, wEbsOckEt\r\nConnection: bar, UpGrAdE\r\n\r\n";
|
||||
env.res.consume(res.data(),res.size());
|
||||
|
||||
|
||||
BOOST_CHECK_EQUAL( env.p.validate_server_handshake_response(env.req,env.res), websocketpp::processor::error::missing_required_header );
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE( client_handshake_response ) {
|
||||
processor_setup env(false);
|
||||
|
||||
|
||||
env.req.append_header("Sec-WebSocket-Key", "dGhlIHNhbXBsZSBub25jZQ==");
|
||||
|
||||
|
||||
std::string res = "HTTP/1.1 101 Switching Protocols\r\nUpgrade: foo, wEbsOckEt\r\nConnection: bar, UpGrAdE\r\nSec-WebSocket-Accept: s3pPLMBiTxaQ9kYGzzhZRbK+xOo=\r\n\r\n";
|
||||
env.res.consume(res.data(),res.size());
|
||||
|
||||
|
||||
BOOST_CHECK( !env.p.validate_server_handshake_response(env.req,env.res) );
|
||||
}
|
||||
|
||||
@@ -576,7 +608,7 @@ BOOST_AUTO_TEST_CASE( extensions_disabled ) {
|
||||
|
||||
std::pair<websocketpp::lib::error_code,std::string> neg_results;
|
||||
neg_results = env.p.negotiate_extensions(env.req);
|
||||
|
||||
|
||||
BOOST_CHECK_EQUAL( neg_results.first, websocketpp::processor::error::extensions_disabled );
|
||||
BOOST_CHECK_EQUAL( neg_results.second, "" );
|
||||
}
|
||||
@@ -588,7 +620,7 @@ BOOST_AUTO_TEST_CASE( extension_negotiation_blank ) {
|
||||
|
||||
std::pair<websocketpp::lib::error_code,std::string> neg_results;
|
||||
neg_results = env.p.negotiate_extensions(env.req);
|
||||
|
||||
|
||||
BOOST_CHECK( !neg_results.first );
|
||||
BOOST_CHECK_EQUAL( neg_results.second, "" );
|
||||
}
|
||||
@@ -600,7 +632,7 @@ BOOST_AUTO_TEST_CASE( extension_negotiation_unknown ) {
|
||||
|
||||
std::pair<websocketpp::lib::error_code,std::string> neg_results;
|
||||
neg_results = env.p.negotiate_extensions(env.req);
|
||||
|
||||
|
||||
BOOST_CHECK( !neg_results.first );
|
||||
BOOST_CHECK_EQUAL( neg_results.second, "" );
|
||||
}
|
||||
@@ -608,7 +640,7 @@ BOOST_AUTO_TEST_CASE( extension_negotiation_unknown ) {
|
||||
BOOST_AUTO_TEST_CASE( extract_subprotocols_empty ) {
|
||||
processor_setup env(true);
|
||||
std::vector<std::string> subps;
|
||||
|
||||
|
||||
BOOST_CHECK( !env.p.extract_subprotocols(env.req,subps) );
|
||||
BOOST_CHECK_EQUAL( subps.size(), 0 );
|
||||
}
|
||||
@@ -616,9 +648,9 @@ BOOST_AUTO_TEST_CASE( extract_subprotocols_empty ) {
|
||||
BOOST_AUTO_TEST_CASE( extract_subprotocols_one ) {
|
||||
processor_setup env(true);
|
||||
std::vector<std::string> subps;
|
||||
|
||||
|
||||
env.req.replace_header("Sec-WebSocket-Protocol","foo");
|
||||
|
||||
|
||||
BOOST_CHECK( !env.p.extract_subprotocols(env.req,subps) );
|
||||
BOOST_REQUIRE_EQUAL( subps.size(), 1 );
|
||||
BOOST_CHECK_EQUAL( subps[0], "foo" );
|
||||
@@ -627,9 +659,9 @@ BOOST_AUTO_TEST_CASE( extract_subprotocols_one ) {
|
||||
BOOST_AUTO_TEST_CASE( extract_subprotocols_multiple ) {
|
||||
processor_setup env(true);
|
||||
std::vector<std::string> subps;
|
||||
|
||||
|
||||
env.req.replace_header("Sec-WebSocket-Protocol","foo,bar");
|
||||
|
||||
|
||||
BOOST_CHECK( !env.p.extract_subprotocols(env.req,subps) );
|
||||
BOOST_REQUIRE_EQUAL( subps.size(), 2 );
|
||||
BOOST_CHECK_EQUAL( subps[0], "foo" );
|
||||
@@ -639,9 +671,9 @@ BOOST_AUTO_TEST_CASE( extract_subprotocols_multiple ) {
|
||||
BOOST_AUTO_TEST_CASE( extract_subprotocols_invalid) {
|
||||
processor_setup env(true);
|
||||
std::vector<std::string> subps;
|
||||
|
||||
|
||||
env.req.replace_header("Sec-WebSocket-Protocol","foo,bar,,,,");
|
||||
|
||||
|
||||
BOOST_CHECK_EQUAL( env.p.extract_subprotocols(env.req,subps), websocketpp::processor::error::make_error_code(websocketpp::processor::error::subprotocol_parse_error) );
|
||||
BOOST_CHECK_EQUAL( subps.size(), 0 );
|
||||
}
|
||||
@@ -654,7 +686,7 @@ BOOST_AUTO_TEST_CASE( extension_negotiation_permessage_deflate ) {
|
||||
|
||||
std::pair<websocketpp::lib::error_code,std::string> neg_results;
|
||||
neg_results = env.p.negotiate_extensions(env.req);
|
||||
|
||||
|
||||
BOOST_CHECK( !neg_results.first );
|
||||
BOOST_CHECK_EQUAL( neg_results.second, "permessage-deflate" );
|
||||
}
|
||||
|
||||
@@ -11,10 +11,10 @@
|
||||
* * 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
|
||||
*
|
||||
* 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;
|
||||
@@ -22,7 +22,7 @@
|
||||
* 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.
|
||||
*
|
||||
*
|
||||
*/
|
||||
//#define BOOST_TEST_DYN_LINK
|
||||
#define BOOST_TEST_MODULE processors
|
||||
@@ -36,100 +36,100 @@
|
||||
|
||||
BOOST_AUTO_TEST_CASE( exact_match ) {
|
||||
websocketpp::http::parser::request r;
|
||||
|
||||
|
||||
std::string handshake = "GET / HTTP/1.1\r\nHost: www.example.com\r\nConnection: upgrade\r\nUpgrade: websocket\r\n\r\n";
|
||||
|
||||
|
||||
r.consume(handshake.c_str(),handshake.size());
|
||||
|
||||
|
||||
BOOST_CHECK(websocketpp::processor::is_websocket_handshake(r));
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE( non_match ) {
|
||||
websocketpp::http::parser::request r;
|
||||
|
||||
|
||||
std::string handshake = "GET / HTTP/1.1\r\nHost: www.example.com\r\n\r\n\r\n";
|
||||
|
||||
|
||||
r.consume(handshake.c_str(),handshake.size());
|
||||
|
||||
|
||||
BOOST_CHECK(!websocketpp::processor::is_websocket_handshake(r));
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE( ci_exact_match ) {
|
||||
websocketpp::http::parser::request r;
|
||||
|
||||
|
||||
std::string handshake = "GET / HTTP/1.1\r\nHost: www.example.com\r\nConnection: UpGrAde\r\nUpgrade: WebSocket\r\n\r\n";
|
||||
|
||||
|
||||
r.consume(handshake.c_str(),handshake.size());
|
||||
|
||||
|
||||
BOOST_CHECK(websocketpp::processor::is_websocket_handshake(r));
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE( non_exact_match1 ) {
|
||||
websocketpp::http::parser::request r;
|
||||
|
||||
|
||||
std::string handshake = "GET / HTTP/1.1\r\nHost: www.example.com\r\nConnection: upgrade,foo\r\nUpgrade: websocket,foo\r\n\r\n";
|
||||
|
||||
|
||||
r.consume(handshake.c_str(),handshake.size());
|
||||
|
||||
|
||||
BOOST_CHECK(websocketpp::processor::is_websocket_handshake(r));
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE( non_exact_match2 ) {
|
||||
websocketpp::http::parser::request r;
|
||||
|
||||
|
||||
std::string handshake = "GET / HTTP/1.1\r\nHost: www.example.com\r\nConnection: keep-alive,Upgrade,foo\r\nUpgrade: foo,websocket,bar\r\n\r\n";
|
||||
|
||||
|
||||
r.consume(handshake.c_str(),handshake.size());
|
||||
|
||||
|
||||
BOOST_CHECK(websocketpp::processor::is_websocket_handshake(r));
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE( version_blank ) {
|
||||
websocketpp::http::parser::request r;
|
||||
|
||||
|
||||
std::string handshake = "GET / HTTP/1.1\r\nHost: www.example.com\r\nUpgrade: websocket\r\n\r\n";
|
||||
|
||||
|
||||
r.consume(handshake.c_str(),handshake.size());
|
||||
|
||||
|
||||
BOOST_CHECK(websocketpp::processor::get_websocket_version(r) == 0);
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE( version_7 ) {
|
||||
websocketpp::http::parser::request r;
|
||||
|
||||
|
||||
std::string handshake = "GET / HTTP/1.1\r\nHost: www.example.com\r\nUpgrade: websocket\r\nSec-WebSocket-Version: 7\r\n\r\n";
|
||||
|
||||
|
||||
r.consume(handshake.c_str(),handshake.size());
|
||||
|
||||
|
||||
BOOST_CHECK(websocketpp::processor::get_websocket_version(r) == 7);
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE( version_8 ) {
|
||||
websocketpp::http::parser::request r;
|
||||
|
||||
|
||||
std::string handshake = "GET / HTTP/1.1\r\nHost: www.example.com\r\nUpgrade: websocket\r\nSec-WebSocket-Version: 8\r\n\r\n";
|
||||
|
||||
|
||||
r.consume(handshake.c_str(),handshake.size());
|
||||
|
||||
|
||||
BOOST_CHECK(websocketpp::processor::get_websocket_version(r) == 8);
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE( version_13 ) {
|
||||
websocketpp::http::parser::request r;
|
||||
|
||||
|
||||
std::string handshake = "GET / HTTP/1.1\r\nHost: www.example.com\r\nUpgrade: websocket\r\nSec-WebSocket-Version: 13\r\n\r\n";
|
||||
|
||||
|
||||
r.consume(handshake.c_str(),handshake.size());
|
||||
|
||||
|
||||
BOOST_CHECK(websocketpp::processor::get_websocket_version(r) == 13);
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE( version_non_numeric ) {
|
||||
websocketpp::http::parser::request r;
|
||||
|
||||
|
||||
std::string handshake = "GET / HTTP/1.1\r\nHost: www.example.com\r\nUpgrade: websocket\r\nSec-WebSocket-Version: abc\r\n\r\n";
|
||||
|
||||
|
||||
r.consume(handshake.c_str(),handshake.size());
|
||||
|
||||
|
||||
BOOST_CHECK(websocketpp::processor::get_websocket_version(r) == -1);
|
||||
}
|
||||
@@ -11,10 +11,10 @@
|
||||
* * 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
|
||||
*
|
||||
* 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;
|
||||
@@ -22,7 +22,7 @@
|
||||
* 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.
|
||||
*
|
||||
*
|
||||
*/
|
||||
//#define BOOST_TEST_DYN_LINK
|
||||
#define BOOST_TEST_MODULE random_none
|
||||
@@ -33,8 +33,8 @@
|
||||
|
||||
BOOST_AUTO_TEST_CASE( does_it_compile ) {
|
||||
websocketpp::random::none::int_generator<int32_t> rng;
|
||||
|
||||
|
||||
int32_t foo = rng();
|
||||
|
||||
|
||||
BOOST_CHECK( foo == 0 );
|
||||
}
|
||||
}
|
||||
@@ -11,10 +11,10 @@
|
||||
* * 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
|
||||
*
|
||||
* 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;
|
||||
@@ -22,7 +22,7 @@
|
||||
* 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.
|
||||
*
|
||||
*
|
||||
*/
|
||||
//#define BOOST_TEST_DYN_LINK
|
||||
#define BOOST_TEST_MODULE random_device
|
||||
@@ -36,15 +36,15 @@
|
||||
|
||||
BOOST_AUTO_TEST_CASE( compiles ) {
|
||||
websocketpp::random::random_device::int_generator<int32_t,websocketpp::concurrency::none> rng;
|
||||
|
||||
|
||||
bool e = false;
|
||||
|
||||
|
||||
try {
|
||||
int32_t foo = rng();
|
||||
std::cout << foo << std::endl;
|
||||
} catch (...) {
|
||||
e = true;
|
||||
}
|
||||
|
||||
|
||||
BOOST_CHECK( e == false );
|
||||
}
|
||||
+35
-35
@@ -11,10 +11,10 @@
|
||||
* * 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
|
||||
*
|
||||
* 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;
|
||||
@@ -22,7 +22,7 @@
|
||||
* 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.
|
||||
*
|
||||
*
|
||||
*/
|
||||
//#define BOOST_TEST_DYN_LINK
|
||||
#define BOOST_TEST_MODULE client
|
||||
@@ -52,11 +52,11 @@ struct stub_config : public websocketpp::config::core {
|
||||
|
||||
//typedef core::rng_type rng_type;
|
||||
typedef websocketpp::random::random_device::int_generator<uint32_t,concurrency_type> rng_type;
|
||||
|
||||
|
||||
typedef core::transport_type transport_type;
|
||||
|
||||
|
||||
typedef core::endpoint_base endpoint_base;
|
||||
|
||||
|
||||
static const websocketpp::log::level elog_level = websocketpp::log::elevel::none;
|
||||
static const websocketpp::log::level alog_level = websocketpp::log::alevel::none;
|
||||
};
|
||||
@@ -67,27 +67,27 @@ typedef client::connection_ptr connection_ptr;
|
||||
BOOST_AUTO_TEST_CASE( invalid_uri ) {
|
||||
client c;
|
||||
websocketpp::lib::error_code ec;
|
||||
|
||||
|
||||
connection_ptr con = c.get_connection("foo", ec);
|
||||
|
||||
|
||||
BOOST_CHECK_EQUAL( ec , websocketpp::error::make_error_code(websocketpp::error::invalid_uri) );
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE( unsecure_endpoint ) {
|
||||
client c;
|
||||
websocketpp::lib::error_code ec;
|
||||
|
||||
|
||||
connection_ptr con = c.get_connection("wss://localhost/", ec);
|
||||
|
||||
|
||||
BOOST_CHECK_EQUAL( ec , websocketpp::error::make_error_code(websocketpp::error::endpoint_not_secure) );
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE( get_connection ) {
|
||||
client c;
|
||||
websocketpp::lib::error_code ec;
|
||||
|
||||
|
||||
connection_ptr con = c.get_connection("ws://localhost/", ec);
|
||||
|
||||
|
||||
BOOST_CHECK( con );
|
||||
BOOST_CHECK_EQUAL( con->get_host() , "localhost" );
|
||||
BOOST_CHECK_EQUAL( con->get_port() , 80 );
|
||||
@@ -100,34 +100,34 @@ BOOST_AUTO_TEST_CASE( connect_con ) {
|
||||
websocketpp::lib::error_code ec;
|
||||
std::stringstream out;
|
||||
std::string o;
|
||||
|
||||
|
||||
c.register_ostream(&out);
|
||||
|
||||
|
||||
connection_ptr con = c.get_connection("ws://localhost/", ec);
|
||||
c.connect(con);
|
||||
|
||||
|
||||
o = out.str();
|
||||
websocketpp::http::parser::request r;
|
||||
r.consume(o.data(),o.size());
|
||||
|
||||
|
||||
BOOST_CHECK( r.ready() );
|
||||
BOOST_CHECK_EQUAL( r.get_method(), "GET");
|
||||
BOOST_CHECK_EQUAL( r.get_version(), "HTTP/1.1");
|
||||
BOOST_CHECK_EQUAL( r.get_uri(), "/");
|
||||
|
||||
|
||||
BOOST_CHECK_EQUAL( r.get_header("Host"), "localhost");
|
||||
BOOST_CHECK_EQUAL( r.get_header("Sec-WebSocket-Version"), "13");
|
||||
BOOST_CHECK_EQUAL( r.get_header("Connection"), "Upgrade");
|
||||
BOOST_CHECK_EQUAL( r.get_header("Upgrade"), "websocket");
|
||||
|
||||
|
||||
// Key is randomly generated & User-Agent will change so just check that
|
||||
// they are not empty.
|
||||
BOOST_CHECK_NE( r.get_header("Sec-WebSocket-Key"), "");
|
||||
BOOST_CHECK_NE( r.get_header("User-Agent"), "" );
|
||||
|
||||
|
||||
// connection should have written out an opening handshake request and be in
|
||||
// the read response internal state
|
||||
|
||||
|
||||
// TODO: more tests related to reading the HTTP response
|
||||
std::stringstream channel2;
|
||||
channel2 << "e\r\n\r\n";
|
||||
@@ -138,11 +138,11 @@ BOOST_AUTO_TEST_CASE( select_subprotocol ) {
|
||||
client c;
|
||||
websocketpp::lib::error_code ec;
|
||||
using websocketpp::error::make_error_code;
|
||||
|
||||
|
||||
connection_ptr con = c.get_connection("ws://localhost/", ec);
|
||||
|
||||
|
||||
BOOST_CHECK( con );
|
||||
|
||||
|
||||
con->select_subprotocol("foo",ec);
|
||||
BOOST_CHECK_EQUAL( ec , make_error_code(websocketpp::error::server_only) );
|
||||
BOOST_CHECK_THROW( con->select_subprotocol("foo") , websocketpp::lib::error_code );
|
||||
@@ -152,14 +152,14 @@ BOOST_AUTO_TEST_CASE( add_subprotocols_invalid ) {
|
||||
client c;
|
||||
websocketpp::lib::error_code ec;
|
||||
using websocketpp::error::make_error_code;
|
||||
|
||||
|
||||
connection_ptr con = c.get_connection("ws://localhost/", ec);
|
||||
BOOST_CHECK( con );
|
||||
|
||||
|
||||
con->add_subprotocol("",ec);
|
||||
BOOST_CHECK_EQUAL( ec , make_error_code(websocketpp::error::invalid_subprotocol) );
|
||||
BOOST_CHECK_THROW( con->add_subprotocol("") , websocketpp::lib::error_code );
|
||||
|
||||
|
||||
con->add_subprotocol("foo,bar",ec);
|
||||
BOOST_CHECK_EQUAL( ec , make_error_code(websocketpp::error::invalid_subprotocol) );
|
||||
BOOST_CHECK_THROW( con->add_subprotocol("foo,bar") , websocketpp::lib::error_code );
|
||||
@@ -170,23 +170,23 @@ BOOST_AUTO_TEST_CASE( add_subprotocols ) {
|
||||
websocketpp::lib::error_code ec;
|
||||
std::stringstream out;
|
||||
std::string o;
|
||||
|
||||
|
||||
c.register_ostream(&out);
|
||||
|
||||
|
||||
connection_ptr con = c.get_connection("ws://localhost/", ec);
|
||||
BOOST_CHECK( con );
|
||||
|
||||
|
||||
con->add_subprotocol("foo",ec);
|
||||
BOOST_CHECK( !ec );
|
||||
|
||||
|
||||
BOOST_CHECK_NO_THROW( con->add_subprotocol("bar") );
|
||||
|
||||
|
||||
c.connect(con);
|
||||
|
||||
|
||||
o = out.str();
|
||||
websocketpp::http::parser::request r;
|
||||
r.consume(o.data(),o.size());
|
||||
|
||||
|
||||
BOOST_CHECK( r.ready() );
|
||||
BOOST_CHECK_EQUAL( r.get_header("Sec-WebSocket-Protocol"), "foo, bar");
|
||||
}
|
||||
|
||||
+42
-42
@@ -11,10 +11,10 @@
|
||||
* * 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
|
||||
*
|
||||
* 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;
|
||||
@@ -22,7 +22,7 @@
|
||||
* 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.
|
||||
*
|
||||
*
|
||||
*/
|
||||
//#define BOOST_TEST_DYN_LINK
|
||||
#define BOOST_TEST_MODULE server
|
||||
@@ -56,9 +56,9 @@ using websocketpp::lib::bind;
|
||||
typedef core::elog_type elog_type;
|
||||
|
||||
typedef core::rng_type rng_type;
|
||||
|
||||
|
||||
typedef core::transport_type transport_type;
|
||||
|
||||
|
||||
typedef core::endpoint_base endpoint_base;
|
||||
};*/
|
||||
|
||||
@@ -66,19 +66,19 @@ using websocketpp::lib::bind;
|
||||
std::string run_server_test(server& s, std::string input) {
|
||||
server::connection_ptr con;
|
||||
std::stringstream output;
|
||||
|
||||
|
||||
s.register_ostream(&output);
|
||||
s.clear_access_channels(websocketpp::log::alevel::all);
|
||||
s.clear_error_channels(websocketpp::log::elevel::all);
|
||||
|
||||
|
||||
con = s.get_connection();
|
||||
con->start();
|
||||
|
||||
|
||||
std::stringstream channel;
|
||||
|
||||
|
||||
channel << input;
|
||||
channel >> *con;
|
||||
|
||||
|
||||
return output.str();
|
||||
}
|
||||
|
||||
@@ -91,28 +91,28 @@ bool validate_func_subprotocol(server* s, std::string* out, std::string accept,
|
||||
websocketpp::connection_hdl hdl)
|
||||
{
|
||||
server::connection_ptr con = s->get_con_from_hdl(hdl);
|
||||
|
||||
|
||||
std::stringstream o;
|
||||
|
||||
|
||||
const std::vector<std::string> & protocols = con->get_requested_subprotocols();
|
||||
std::vector<std::string>::const_iterator it;
|
||||
|
||||
|
||||
for (it = protocols.begin(); it != protocols.end(); ++it) {
|
||||
o << *it << ",";
|
||||
}
|
||||
|
||||
*out = o.str();
|
||||
|
||||
|
||||
if (accept != "") {
|
||||
con->select_subprotocol(accept);
|
||||
}
|
||||
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void open_func_subprotocol(server* s, std::string* out, websocketpp::connection_hdl hdl) {
|
||||
server::connection_ptr con = s->get_con_from_hdl(hdl);
|
||||
|
||||
|
||||
*out = con->get_subprotocol();
|
||||
}
|
||||
|
||||
@@ -120,21 +120,21 @@ void open_func_subprotocol(server* s, std::string* out, websocketpp::connection_
|
||||
BOOST_AUTO_TEST_CASE( basic_websocket_request ) {
|
||||
std::string input = "GET / HTTP/1.1\r\nHost: www.example.com\r\nConnection: upgrade\r\nUpgrade: websocket\r\nSec-WebSocket-Version: 13\r\nSec-WebSocket-Key: dGhlIHNhbXBsZSBub25jZQ==\r\nOrigin: http://www.example.com\r\n\r\n";
|
||||
std::string output = "HTTP/1.1 101 Switching Protocols\r\nConnection: upgrade\r\nSec-WebSocket-Accept: s3pPLMBiTxaQ9kYGzzhZRbK+xOo=\r\nServer: test\r\nUpgrade: websocket\r\n\r\n";
|
||||
|
||||
|
||||
server s;
|
||||
s.set_user_agent("test");
|
||||
|
||||
|
||||
BOOST_CHECK_EQUAL(run_server_test(s,input), output);
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE( invalid_websocket_version ) {
|
||||
std::string input = "GET / HTTP/1.1\r\nHost: www.example.com\r\nConnection: upgrade\r\nUpgrade: websocket\r\nSec-WebSocket-Version: a\r\nSec-WebSocket-Key: dGhlIHNhbXBsZSBub25jZQ==\r\nOrigin: http://www.example.com\r\n\r\n";
|
||||
std::string output = "HTTP/1.1 400 Bad Request\r\nServer: test\r\n\r\n";
|
||||
|
||||
|
||||
server s;
|
||||
s.set_user_agent("test");
|
||||
//s.set_message_handler(bind(&echo_func,&s,::_1,::_2));
|
||||
|
||||
|
||||
BOOST_CHECK_EQUAL(run_server_test(s,input), output);
|
||||
}
|
||||
|
||||
@@ -142,10 +142,10 @@ BOOST_AUTO_TEST_CASE( unimplemented_websocket_version ) {
|
||||
std::string input = "GET / HTTP/1.1\r\nHost: www.example.com\r\nConnection: upgrade\r\nUpgrade: websocket\r\nSec-WebSocket-Version: 14\r\nSec-WebSocket-Key: dGhlIHNhbXBsZSBub25jZQ==\r\nOrigin: http://www.example.com\r\n\r\n";
|
||||
|
||||
std::string output = "HTTP/1.1 400 Bad Request\r\nSec-WebSocket-Version: 0,7,8,13\r\nServer: test\r\n\r\n";
|
||||
|
||||
|
||||
server s;
|
||||
s.set_user_agent("test");
|
||||
|
||||
|
||||
BOOST_CHECK_EQUAL(run_server_test(s,input), output);
|
||||
}
|
||||
|
||||
@@ -153,13 +153,13 @@ BOOST_AUTO_TEST_CASE( list_subprotocol_empty ) {
|
||||
std::string input = "GET / HTTP/1.1\r\nHost: www.example.com\r\nConnection: upgrade\r\nUpgrade: websocket\r\nSec-WebSocket-Version: 13\r\nSec-WebSocket-Key: dGhlIHNhbXBsZSBub25jZQ==\r\nOrigin: http://www.example.com\r\nSec-WebSocket-Protocol: foo\r\n\r\n";
|
||||
|
||||
std::string output = "HTTP/1.1 101 Switching Protocols\r\nConnection: upgrade\r\nSec-WebSocket-Accept: s3pPLMBiTxaQ9kYGzzhZRbK+xOo=\r\nServer: test\r\nUpgrade: websocket\r\n\r\n";
|
||||
|
||||
|
||||
std::string subprotocol;
|
||||
|
||||
|
||||
server s;
|
||||
s.set_user_agent("test");
|
||||
s.set_open_handler(bind(&open_func_subprotocol,&s,&subprotocol,::_1));
|
||||
|
||||
|
||||
BOOST_CHECK_EQUAL(run_server_test(s,input), output);
|
||||
BOOST_CHECK_EQUAL(subprotocol, "");
|
||||
}
|
||||
@@ -168,15 +168,15 @@ BOOST_AUTO_TEST_CASE( list_subprotocol_one ) {
|
||||
std::string input = "GET / HTTP/1.1\r\nHost: www.example.com\r\nConnection: upgrade\r\nUpgrade: websocket\r\nSec-WebSocket-Version: 13\r\nSec-WebSocket-Key: dGhlIHNhbXBsZSBub25jZQ==\r\nOrigin: http://www.example.com\r\nSec-WebSocket-Protocol: foo\r\n\r\n";
|
||||
|
||||
std::string output = "HTTP/1.1 101 Switching Protocols\r\nConnection: upgrade\r\nSec-WebSocket-Accept: s3pPLMBiTxaQ9kYGzzhZRbK+xOo=\r\nServer: test\r\nUpgrade: websocket\r\n\r\n";
|
||||
|
||||
|
||||
std::string validate;
|
||||
std::string open;
|
||||
|
||||
|
||||
server s;
|
||||
s.set_user_agent("test");
|
||||
s.set_validate_handler(bind(&validate_func_subprotocol,&s,&validate,"",::_1));
|
||||
s.set_open_handler(bind(&open_func_subprotocol,&s,&open,::_1));
|
||||
|
||||
|
||||
BOOST_CHECK_EQUAL(run_server_test(s,input), output);
|
||||
BOOST_CHECK_EQUAL(validate, "foo,");
|
||||
BOOST_CHECK_EQUAL(open, "");
|
||||
@@ -186,15 +186,15 @@ BOOST_AUTO_TEST_CASE( accept_subprotocol_one ) {
|
||||
std::string input = "GET / HTTP/1.1\r\nHost: www.example.com\r\nConnection: upgrade\r\nUpgrade: websocket\r\nSec-WebSocket-Version: 13\r\nSec-WebSocket-Key: dGhlIHNhbXBsZSBub25jZQ==\r\nOrigin: http://www.example.com\r\nSec-WebSocket-Protocol: foo\r\n\r\n";
|
||||
|
||||
std::string output = "HTTP/1.1 101 Switching Protocols\r\nConnection: upgrade\r\nSec-WebSocket-Accept: s3pPLMBiTxaQ9kYGzzhZRbK+xOo=\r\nSec-WebSocket-Protocol: foo\r\nServer: test\r\nUpgrade: websocket\r\n\r\n";
|
||||
|
||||
|
||||
std::string validate;
|
||||
std::string open;
|
||||
|
||||
|
||||
server s;
|
||||
s.set_user_agent("test");
|
||||
s.set_validate_handler(bind(&validate_func_subprotocol,&s,&validate,"foo",::_1));
|
||||
s.set_open_handler(bind(&open_func_subprotocol,&s,&open,::_1));
|
||||
|
||||
|
||||
BOOST_CHECK_EQUAL(run_server_test(s,input), output);
|
||||
BOOST_CHECK_EQUAL(validate, "foo,");
|
||||
BOOST_CHECK_EQUAL(open, "foo");
|
||||
@@ -204,17 +204,17 @@ BOOST_AUTO_TEST_CASE( accept_subprotocol_invalid ) {
|
||||
std::string input = "GET / HTTP/1.1\r\nHost: www.example.com\r\nConnection: upgrade\r\nUpgrade: websocket\r\nSec-WebSocket-Version: 13\r\nSec-WebSocket-Key: dGhlIHNhbXBsZSBub25jZQ==\r\nOrigin: http://www.example.com\r\nSec-WebSocket-Protocol: foo\r\n\r\n";
|
||||
|
||||
std::string output = "HTTP/1.1 101 Switching Protocols\r\nConnection: upgrade\r\nSec-WebSocket-Accept: s3pPLMBiTxaQ9kYGzzhZRbK+xOo=\r\nSec-WebSocket-Protocol: foo\r\nServer: test\r\nUpgrade: websocket\r\n\r\n";
|
||||
|
||||
|
||||
std::string validate;
|
||||
std::string open;
|
||||
|
||||
|
||||
server s;
|
||||
s.set_user_agent("test");
|
||||
s.set_validate_handler(bind(&validate_func_subprotocol,&s,&validate,"foo2",::_1));
|
||||
s.set_open_handler(bind(&open_func_subprotocol,&s,&open,::_1));
|
||||
|
||||
|
||||
std::string o;
|
||||
|
||||
|
||||
BOOST_CHECK_THROW(o = run_server_test(s,input), websocketpp::lib::error_code);
|
||||
}
|
||||
|
||||
@@ -222,15 +222,15 @@ BOOST_AUTO_TEST_CASE( accept_subprotocol_two ) {
|
||||
std::string input = "GET / HTTP/1.1\r\nHost: www.example.com\r\nConnection: upgrade\r\nUpgrade: websocket\r\nSec-WebSocket-Version: 13\r\nSec-WebSocket-Key: dGhlIHNhbXBsZSBub25jZQ==\r\nOrigin: http://www.example.com\r\nSec-WebSocket-Protocol: foo, bar\r\n\r\n";
|
||||
|
||||
std::string output = "HTTP/1.1 101 Switching Protocols\r\nConnection: upgrade\r\nSec-WebSocket-Accept: s3pPLMBiTxaQ9kYGzzhZRbK+xOo=\r\nSec-WebSocket-Protocol: bar\r\nServer: test\r\nUpgrade: websocket\r\n\r\n";
|
||||
|
||||
|
||||
std::string validate;
|
||||
std::string open;
|
||||
|
||||
|
||||
server s;
|
||||
s.set_user_agent("test");
|
||||
s.set_validate_handler(bind(&validate_func_subprotocol,&s,&validate,"bar",::_1));
|
||||
s.set_open_handler(bind(&open_func_subprotocol,&s,&open,::_1));
|
||||
|
||||
|
||||
BOOST_CHECK_EQUAL(run_server_test(s,input), output);
|
||||
BOOST_CHECK_EQUAL(validate, "foo,bar,");
|
||||
BOOST_CHECK_EQUAL(open, "bar");
|
||||
@@ -239,9 +239,9 @@ BOOST_AUTO_TEST_CASE( accept_subprotocol_two ) {
|
||||
/*BOOST_AUTO_TEST_CASE( user_reject_origin ) {
|
||||
std::string input = "GET / HTTP/1.1\r\nHost: www.example.com\r\nConnection: upgrade\r\nUpgrade: websocket\r\nSec-WebSocket-Version: 13\r\nSec-WebSocket-Key: dGhlIHNhbXBsZSBub25jZQ==\r\nOrigin: http://www.example2.com\r\n\r\n";
|
||||
std::string output = "HTTP/1.1 403 Forbidden\r\nServer: test\r\n\r\n";
|
||||
|
||||
|
||||
server s;
|
||||
s.set_user_agent("test");
|
||||
|
||||
|
||||
BOOST_CHECK(run_server_test(s,input) == output);
|
||||
}*/
|
||||
@@ -11,10 +11,10 @@
|
||||
* * 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
|
||||
*
|
||||
* 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;
|
||||
@@ -22,7 +22,7 @@
|
||||
* 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.
|
||||
*
|
||||
*
|
||||
*/
|
||||
//#define BOOST_TEST_DYN_LINK
|
||||
#define BOOST_TEST_MODULE transport_asio_base
|
||||
@@ -34,16 +34,16 @@
|
||||
|
||||
BOOST_AUTO_TEST_CASE( blank_error ) {
|
||||
websocketpp::lib::error_code ec;
|
||||
|
||||
|
||||
BOOST_CHECK( !ec );
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE( asio_error ) {
|
||||
using websocketpp::transport::asio::error::make_error_code;
|
||||
using websocketpp::transport::asio::error::general;
|
||||
|
||||
|
||||
websocketpp::lib::error_code ec = make_error_code(general);
|
||||
|
||||
|
||||
BOOST_CHECK( ec == general );
|
||||
BOOST_CHECK( ec.value() == 1 );
|
||||
}
|
||||
}
|
||||
@@ -11,10 +11,10 @@
|
||||
* * 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
|
||||
*
|
||||
* 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;
|
||||
@@ -22,7 +22,7 @@
|
||||
* 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.
|
||||
*
|
||||
*
|
||||
*/
|
||||
//#define BOOST_TEST_DYN_LINK
|
||||
#define BOOST_TEST_MODULE transport_asio_timers
|
||||
@@ -52,12 +52,12 @@
|
||||
// Accept a connection, read data, and discard until EOF
|
||||
void run_dummy_server(int port) {
|
||||
using boost::asio::ip::tcp;
|
||||
|
||||
try {
|
||||
|
||||
try {
|
||||
boost::asio::io_service io_service;
|
||||
tcp::acceptor acceptor(io_service, tcp::endpoint(tcp::v6(), port));
|
||||
tcp::socket socket(io_service);
|
||||
|
||||
|
||||
acceptor.accept(socket);
|
||||
for (;;) {
|
||||
char data[512];
|
||||
@@ -94,7 +94,9 @@ struct config {
|
||||
typedef websocketpp::http::parser::request request_type;
|
||||
typedef websocketpp::http::parser::response response_type;
|
||||
typedef websocketpp::transport::asio::tls_socket::endpoint socket_type;
|
||||
|
||||
|
||||
static const bool enable_multithreading = true;
|
||||
|
||||
static const long timeout_socket_pre_init = 1000;
|
||||
static const long timeout_proxy = 1000;
|
||||
static const long timeout_socket_post_init = 1000;
|
||||
@@ -112,20 +114,20 @@ context_ptr on_tls_init(websocketpp::connection_hdl hdl) {
|
||||
// Mock connection
|
||||
struct mock_con: public websocketpp::transport::asio::connection<config> {
|
||||
typedef websocketpp::transport::asio::connection<config> base;
|
||||
|
||||
|
||||
mock_con(bool a, config::alog_type& b, config::elog_type& c) : base(a,b,c) {}
|
||||
|
||||
|
||||
void start() {
|
||||
base::init(websocketpp::lib::bind(&mock_con::handle_start,this,
|
||||
websocketpp::lib::placeholders::_1));
|
||||
}
|
||||
|
||||
|
||||
void handle_start(const websocketpp::lib::error_code& ec) {
|
||||
using websocketpp::transport::asio::socket::make_error_code;
|
||||
using websocketpp::transport::asio::socket::error::tls_handshake_timeout;
|
||||
|
||||
|
||||
BOOST_CHECK_EQUAL( ec, make_error_code(tls_handshake_timeout) );
|
||||
|
||||
|
||||
base::cancel_socket();
|
||||
}
|
||||
};
|
||||
@@ -135,20 +137,20 @@ typedef websocketpp::lib::shared_ptr<mock_con> connection_ptr;
|
||||
|
||||
struct mock_endpoint : public websocketpp::transport::asio::endpoint<config> {
|
||||
typedef websocketpp::transport::asio::endpoint<config> base;
|
||||
|
||||
|
||||
mock_endpoint() {
|
||||
alog.set_channels(websocketpp::log::alevel::all);
|
||||
base::init_logging(&alog,&elog);
|
||||
init_asio();
|
||||
}
|
||||
|
||||
|
||||
void connect(std::string u) {
|
||||
m_con.reset(new mock_con(false,alog,elog));
|
||||
websocketpp::uri_ptr uri(new websocketpp::uri(u));
|
||||
|
||||
|
||||
BOOST_CHECK( uri->get_valid() );
|
||||
BOOST_CHECK_EQUAL( base::init(m_con), websocketpp::lib::error_code() );
|
||||
|
||||
|
||||
base::async_connect(
|
||||
m_con,
|
||||
uri,
|
||||
@@ -156,19 +158,17 @@ struct mock_endpoint : public websocketpp::transport::asio::endpoint<config> {
|
||||
&mock_endpoint::handle_connect,
|
||||
this,
|
||||
m_con,
|
||||
websocketpp::lib::placeholders::_1,
|
||||
websocketpp::lib::placeholders::_2
|
||||
websocketpp::lib::placeholders::_1
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
void handle_connect(connection_ptr con, websocketpp::connection_hdl,
|
||||
const websocketpp::lib::error_code & ec)
|
||||
|
||||
void handle_connect(connection_ptr con, websocketpp::lib::error_code const & ec)
|
||||
{
|
||||
BOOST_CHECK( !ec );
|
||||
con->start();
|
||||
}
|
||||
|
||||
|
||||
connection_ptr m_con;
|
||||
config::alog_type alog;
|
||||
config::elog_type elog;
|
||||
@@ -179,7 +179,7 @@ BOOST_AUTO_TEST_CASE( tls_handshake_timeout ) {
|
||||
websocketpp::lib::thread timer(websocketpp::lib::bind(&run_test_timer,5000));
|
||||
dummy_server.detach();
|
||||
timer.detach();
|
||||
|
||||
|
||||
mock_endpoint endpoint;
|
||||
endpoint.set_tls_init_handler(&on_tls_init);
|
||||
endpoint.connect("wss://localhost:9005");
|
||||
|
||||
@@ -11,10 +11,10 @@
|
||||
* * 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
|
||||
*
|
||||
* 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;
|
||||
@@ -22,7 +22,7 @@
|
||||
* 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.
|
||||
*
|
||||
*
|
||||
*/
|
||||
//#define BOOST_TEST_DYN_LINK
|
||||
#define BOOST_TEST_MODULE hybi_util
|
||||
@@ -36,15 +36,15 @@
|
||||
BOOST_AUTO_TEST_CASE( circshift_0 ) {
|
||||
if (sizeof(size_t) == 8) {
|
||||
size_t test = 0x0123456789abcdef;
|
||||
|
||||
|
||||
test = websocketpp::processor::hybi_util::circshift_prepared_key(test,0);
|
||||
|
||||
|
||||
BOOST_CHECK( test == 0x0123456789abcdef);
|
||||
} else {
|
||||
size_t test = 0x01234567;
|
||||
|
||||
|
||||
test = websocketpp::processor::hybi_util::circshift_prepared_key(test,0);
|
||||
|
||||
|
||||
BOOST_CHECK( test == 0x01234567);
|
||||
}
|
||||
}
|
||||
@@ -52,15 +52,15 @@ BOOST_AUTO_TEST_CASE( circshift_0 ) {
|
||||
BOOST_AUTO_TEST_CASE( circshift_1 ) {
|
||||
if (sizeof(size_t) == 8) {
|
||||
size_t test = 0x0123456789abcdef;
|
||||
|
||||
|
||||
test = websocketpp::processor::hybi_util::circshift_prepared_key(test,1);
|
||||
|
||||
|
||||
BOOST_CHECK( test == 0xef0123456789abcd);
|
||||
} else {
|
||||
size_t test = 0x01234567;
|
||||
|
||||
|
||||
test = websocketpp::processor::hybi_util::circshift_prepared_key(test,1);
|
||||
|
||||
|
||||
BOOST_CHECK( test == 0x67012345);
|
||||
}
|
||||
}
|
||||
@@ -68,15 +68,15 @@ BOOST_AUTO_TEST_CASE( circshift_1 ) {
|
||||
BOOST_AUTO_TEST_CASE( circshift_2 ) {
|
||||
if (sizeof(size_t) == 8) {
|
||||
size_t test = 0x0123456789abcdef;
|
||||
|
||||
|
||||
test = websocketpp::processor::hybi_util::circshift_prepared_key(test,2);
|
||||
|
||||
|
||||
BOOST_CHECK( test == 0xcdef0123456789ab);
|
||||
} else {
|
||||
size_t test = 0x01234567;
|
||||
|
||||
|
||||
test = websocketpp::processor::hybi_util::circshift_prepared_key(test,2);
|
||||
|
||||
|
||||
BOOST_CHECK( test == 0x45670123);
|
||||
}
|
||||
}
|
||||
@@ -84,15 +84,15 @@ BOOST_AUTO_TEST_CASE( circshift_2 ) {
|
||||
BOOST_AUTO_TEST_CASE( circshift_3 ) {
|
||||
if (sizeof(size_t) == 8) {
|
||||
size_t test = 0x0123456789abcdef;
|
||||
|
||||
|
||||
test = websocketpp::processor::hybi_util::circshift_prepared_key(test,3);
|
||||
|
||||
|
||||
BOOST_CHECK( test == 0xabcdef0123456789);
|
||||
} else {
|
||||
size_t test = 0x01234567;
|
||||
|
||||
|
||||
test = websocketpp::processor::hybi_util::circshift_prepared_key(test,3);
|
||||
|
||||
|
||||
BOOST_CHECK( test == 0x23456701);
|
||||
}
|
||||
}
|
||||
+231
-54
@@ -11,10 +11,10 @@
|
||||
* * 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
|
||||
*
|
||||
* 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;
|
||||
@@ -22,7 +22,7 @@
|
||||
* 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.
|
||||
*
|
||||
*
|
||||
*/
|
||||
//#define BOOST_TEST_DYN_LINK
|
||||
#define BOOST_TEST_MODULE transport_integration
|
||||
@@ -30,45 +30,90 @@
|
||||
|
||||
#include <websocketpp/common/thread.hpp>
|
||||
|
||||
#include <websocketpp/config/asio_no_tls.hpp>
|
||||
#include <websocketpp/config/asio_no_tls_client.hpp>
|
||||
#include <websocketpp/config/core.hpp>
|
||||
#include <websocketpp/config/core_client.hpp>
|
||||
#include <websocketpp/config/asio.hpp>
|
||||
#include <websocketpp/config/asio_client.hpp>
|
||||
#include <websocketpp/config/debug_asio.hpp>
|
||||
#include <websocketpp/server.hpp>
|
||||
#include <websocketpp/client.hpp>
|
||||
|
||||
struct config : public websocketpp::config::asio_client {
|
||||
typedef config type;
|
||||
typedef websocketpp::config::asio base;
|
||||
|
||||
|
||||
typedef base::concurrency_type concurrency_type;
|
||||
|
||||
|
||||
typedef base::request_type request_type;
|
||||
typedef base::response_type response_type;
|
||||
|
||||
typedef base::message_type message_type;
|
||||
typedef base::con_msg_manager_type con_msg_manager_type;
|
||||
typedef base::endpoint_msg_manager_type endpoint_msg_manager_type;
|
||||
|
||||
|
||||
typedef base::alog_type alog_type;
|
||||
typedef base::elog_type elog_type;
|
||||
|
||||
|
||||
typedef base::rng_type rng_type;
|
||||
|
||||
|
||||
struct transport_config : public base::transport_config {
|
||||
typedef type::concurrency_type concurrency_type;
|
||||
typedef type::alog_type alog_type;
|
||||
typedef type::elog_type elog_type;
|
||||
typedef type::request_type request_type;
|
||||
typedef type::response_type response_type;
|
||||
typedef websocketpp::transport::asio::basic_socket::endpoint
|
||||
typedef websocketpp::transport::asio::basic_socket::endpoint
|
||||
socket_type;
|
||||
};
|
||||
|
||||
typedef websocketpp::transport::asio::endpoint<transport_config>
|
||||
typedef websocketpp::transport::asio::endpoint<transport_config>
|
||||
transport_type;
|
||||
|
||||
|
||||
//static const websocketpp::log::level elog_level = websocketpp::log::elevel::all;
|
||||
//static const websocketpp::log::level alog_level = websocketpp::log::alevel::all;
|
||||
|
||||
|
||||
/// Length of time before an opening handshake is aborted
|
||||
static const long timeout_open_handshake = 500;
|
||||
/// Length of time before a closing handshake is aborted
|
||||
static const long timeout_close_handshake = 500;
|
||||
/// Length of time to wait for a pong after a ping
|
||||
static const long timeout_pong = 500;
|
||||
};
|
||||
|
||||
struct config_tls : public websocketpp::config::asio_tls_client {
|
||||
typedef config type;
|
||||
typedef websocketpp::config::asio base;
|
||||
|
||||
typedef base::concurrency_type concurrency_type;
|
||||
|
||||
typedef base::request_type request_type;
|
||||
typedef base::response_type response_type;
|
||||
|
||||
typedef base::message_type message_type;
|
||||
typedef base::con_msg_manager_type con_msg_manager_type;
|
||||
typedef base::endpoint_msg_manager_type endpoint_msg_manager_type;
|
||||
|
||||
typedef base::alog_type alog_type;
|
||||
typedef base::elog_type elog_type;
|
||||
|
||||
typedef base::rng_type rng_type;
|
||||
|
||||
struct transport_config : public base::transport_config {
|
||||
typedef type::concurrency_type concurrency_type;
|
||||
typedef type::alog_type alog_type;
|
||||
typedef type::elog_type elog_type;
|
||||
typedef type::request_type request_type;
|
||||
typedef type::response_type response_type;
|
||||
typedef websocketpp::transport::asio::basic_socket::endpoint
|
||||
socket_type;
|
||||
};
|
||||
|
||||
typedef websocketpp::transport::asio::endpoint<transport_config>
|
||||
transport_type;
|
||||
|
||||
//static const websocketpp::log::level elog_level = websocketpp::log::elevel::all;
|
||||
//static const websocketpp::log::level alog_level = websocketpp::log::alevel::all;
|
||||
|
||||
/// Length of time before an opening handshake is aborted
|
||||
static const long timeout_open_handshake = 500;
|
||||
/// Length of time before a closing handshake is aborted
|
||||
@@ -80,6 +125,12 @@ struct config : public websocketpp::config::asio_client {
|
||||
typedef websocketpp::server<config> server;
|
||||
typedef websocketpp::client<config> client;
|
||||
|
||||
typedef websocketpp::server<config_tls> server_tls;
|
||||
typedef websocketpp::client<config_tls> client_tls;
|
||||
|
||||
typedef websocketpp::server<websocketpp::config::core> iostream_server;
|
||||
typedef websocketpp::client<websocketpp::config::core_client> iostream_client;
|
||||
|
||||
using websocketpp::lib::placeholders::_1;
|
||||
using websocketpp::lib::placeholders::_2;
|
||||
using websocketpp::lib::bind;
|
||||
@@ -87,7 +138,10 @@ using websocketpp::lib::bind;
|
||||
template <typename T>
|
||||
void close_after_timeout(T & e, websocketpp::connection_hdl hdl, long timeout) {
|
||||
sleep(timeout);
|
||||
e.close(hdl,websocketpp::close::status::normal,"");
|
||||
|
||||
websocketpp::lib::error_code ec;
|
||||
e.close(hdl,websocketpp::close::status::normal,"",ec);
|
||||
BOOST_CHECK(!ec);
|
||||
}
|
||||
|
||||
void run_server(server * s, int port, bool log = false) {
|
||||
@@ -100,6 +154,7 @@ void run_server(server * s, int port, bool log = false) {
|
||||
}
|
||||
|
||||
s->init_asio();
|
||||
s->set_reuse_addr(true);
|
||||
|
||||
s->listen(port);
|
||||
s->start_accept();
|
||||
@@ -114,9 +169,11 @@ void run_client(client & c, std::string uri, bool log = false) {
|
||||
c.clear_access_channels(websocketpp::log::alevel::all);
|
||||
c.clear_error_channels(websocketpp::log::elevel::all);
|
||||
}
|
||||
c.init_asio();
|
||||
|
||||
websocketpp::lib::error_code ec;
|
||||
c.init_asio(ec);
|
||||
c.set_reuse_addr(true);
|
||||
BOOST_CHECK(!ec);
|
||||
|
||||
client::connection_ptr con = c.get_connection(uri,ec);
|
||||
BOOST_CHECK( !ec );
|
||||
c.connect(con);
|
||||
@@ -124,7 +181,15 @@ void run_client(client & c, std::string uri, bool log = false) {
|
||||
c.run();
|
||||
}
|
||||
|
||||
void run_time_limited_client(client & c, std::string uri, long timeout,
|
||||
void run_client_and_mark(client * c, bool * flag, websocketpp::lib::mutex * mutex) {
|
||||
c->run();
|
||||
BOOST_CHECK( true );
|
||||
websocketpp::lib::lock_guard<websocketpp::lib::mutex> lock(*mutex);
|
||||
*flag = true;
|
||||
BOOST_CHECK( true );
|
||||
}
|
||||
|
||||
void run_time_limited_client(client & c, std::string uri, long timeout,
|
||||
bool log)
|
||||
{
|
||||
if (log) {
|
||||
@@ -135,12 +200,12 @@ void run_time_limited_client(client & c, std::string uri, long timeout,
|
||||
c.clear_error_channels(websocketpp::log::elevel::all);
|
||||
}
|
||||
c.init_asio();
|
||||
|
||||
|
||||
websocketpp::lib::error_code ec;
|
||||
client::connection_ptr con = c.get_connection(uri,ec);
|
||||
BOOST_CHECK( !ec );
|
||||
c.connect(con);
|
||||
|
||||
|
||||
websocketpp::lib::thread tthread(websocketpp::lib::bind(
|
||||
&close_after_timeout<client>,
|
||||
websocketpp::lib::ref(c),
|
||||
@@ -148,18 +213,18 @@ void run_time_limited_client(client & c, std::string uri, long timeout,
|
||||
timeout
|
||||
));
|
||||
tthread.detach();
|
||||
|
||||
|
||||
c.run();
|
||||
}
|
||||
|
||||
void run_dummy_server(int port) {
|
||||
using boost::asio::ip::tcp;
|
||||
|
||||
try {
|
||||
|
||||
try {
|
||||
boost::asio::io_service io_service;
|
||||
tcp::acceptor acceptor(io_service, tcp::endpoint(tcp::v6(), port));
|
||||
tcp::socket socket(io_service);
|
||||
|
||||
|
||||
acceptor.accept(socket);
|
||||
for (;;) {
|
||||
char data[512];
|
||||
@@ -181,14 +246,14 @@ void run_dummy_server(int port) {
|
||||
|
||||
void run_dummy_client(std::string port) {
|
||||
using boost::asio::ip::tcp;
|
||||
|
||||
try {
|
||||
|
||||
try {
|
||||
boost::asio::io_service io_service;
|
||||
tcp::resolver resolver(io_service);
|
||||
tcp::resolver::query query("localhost", port);
|
||||
tcp::resolver::iterator iterator = resolver.resolve(query);
|
||||
tcp::socket socket(io_service);
|
||||
|
||||
|
||||
boost::asio::connect(socket, iterator);
|
||||
for (;;) {
|
||||
char data[512];
|
||||
@@ -213,7 +278,7 @@ bool on_ping(websocketpp::connection_hdl, std::string payload) {
|
||||
}
|
||||
|
||||
void cancel_on_open(server * s, websocketpp::connection_hdl hdl) {
|
||||
s->cancel();
|
||||
s->stop_listening();
|
||||
}
|
||||
|
||||
void stop_on_close(server * s, websocketpp::connection_hdl hdl) {
|
||||
@@ -237,7 +302,7 @@ void fail_on_pong_timeout(websocketpp::connection_hdl hdl, std::string payload)
|
||||
BOOST_FAIL( "expected no pong timeout" );
|
||||
}
|
||||
|
||||
void req_pong(std::string expected_payload, websocketpp::connection_hdl hdl,
|
||||
void req_pong(std::string expected_payload, websocketpp::connection_hdl hdl,
|
||||
std::string payload)
|
||||
{
|
||||
BOOST_CHECK_EQUAL( expected_payload, payload );
|
||||
@@ -252,7 +317,7 @@ void delay(websocketpp::connection_hdl hdl, long duration) {
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
void check_ec(T * c, websocketpp::lib::error_code ec,
|
||||
void check_ec(T * c, websocketpp::lib::error_code ec,
|
||||
websocketpp::connection_hdl hdl)
|
||||
{
|
||||
typename T::connection_ptr con = c->get_con_from_hdl(hdl);
|
||||
@@ -262,7 +327,7 @@ void check_ec(T * c, websocketpp::lib::error_code ec,
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
void check_ec_and_stop(T * e, websocketpp::lib::error_code ec,
|
||||
void check_ec_and_stop(T * e, websocketpp::lib::error_code ec,
|
||||
websocketpp::connection_hdl hdl)
|
||||
{
|
||||
typename T::connection_ptr con = e->get_con_from_hdl(hdl);
|
||||
@@ -273,7 +338,7 @@ void check_ec_and_stop(T * e, websocketpp::lib::error_code ec,
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
void req_pong_timeout(T * c, std::string expected_payload,
|
||||
void req_pong_timeout(T * c, std::string expected_payload,
|
||||
websocketpp::connection_hdl hdl, std::string payload)
|
||||
{
|
||||
typename T::connection_ptr con = c->get_con_from_hdl(hdl);
|
||||
@@ -297,19 +362,19 @@ BOOST_AUTO_TEST_CASE( pong_no_timeout ) {
|
||||
client c;
|
||||
|
||||
s.set_close_handler(bind(&stop_on_close,&s,::_1));
|
||||
|
||||
|
||||
// send a ping when the connection is open
|
||||
c.set_open_handler(bind(&ping_on_open<client>,&c,"foo",::_1));
|
||||
// require that a pong with matching payload is received
|
||||
c.set_pong_handler(bind(&req_pong,"foo",::_1,::_2));
|
||||
// require that a pong timeout is NOT received
|
||||
c.set_pong_timeout_handler(bind(&fail_on_pong_timeout,::_1,::_2));
|
||||
|
||||
|
||||
websocketpp::lib::thread sthread(websocketpp::lib::bind(&run_server,&s,9005,false));
|
||||
|
||||
|
||||
// Run a client that closes the connection after 1 seconds
|
||||
run_time_limited_client(c, "http://localhost:9005", 1, false);
|
||||
|
||||
|
||||
sthread.join();
|
||||
}
|
||||
|
||||
@@ -319,28 +384,28 @@ BOOST_AUTO_TEST_CASE( pong_timeout ) {
|
||||
|
||||
s.set_ping_handler(on_ping);
|
||||
s.set_close_handler(bind(&stop_on_close,&s,::_1));
|
||||
|
||||
|
||||
c.set_fail_handler(bind(&check_ec<client>,&c,
|
||||
websocketpp::lib::error_code(),::_1));
|
||||
|
||||
|
||||
c.set_pong_handler(bind(&fail_on_pong,::_1,::_2));
|
||||
c.set_open_handler(bind(&ping_on_open<client>,&c,"foo",::_1));
|
||||
c.set_pong_timeout_handler(bind(&req_pong_timeout<client>,&c,"foo",::_1,::_2));
|
||||
c.set_close_handler(bind(&check_ec<client>,&c,
|
||||
websocketpp::lib::error_code(),::_1));
|
||||
|
||||
|
||||
websocketpp::lib::thread sthread(websocketpp::lib::bind(&run_server,&s,9005,false));
|
||||
websocketpp::lib::thread tthread(websocketpp::lib::bind(&run_test_timer,6));
|
||||
tthread.detach();
|
||||
|
||||
|
||||
run_client(c, "http://localhost:9005",false);
|
||||
|
||||
|
||||
sthread.join();
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE( client_open_handshake_timeout ) {
|
||||
client c;
|
||||
|
||||
|
||||
// set open handler to fail test
|
||||
c.set_open_handler(bind(&fail_on_open,::_1));
|
||||
// set fail hander to test for the right fail error code
|
||||
@@ -351,13 +416,13 @@ BOOST_AUTO_TEST_CASE( client_open_handshake_timeout ) {
|
||||
websocketpp::lib::thread tthread(websocketpp::lib::bind(&run_test_timer,6));
|
||||
sthread.detach();
|
||||
tthread.detach();
|
||||
|
||||
|
||||
run_client(c, "http://localhost:9005");
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE( server_open_handshake_timeout ) {
|
||||
server s;
|
||||
|
||||
|
||||
// set open handler to fail test
|
||||
s.set_open_handler(bind(&fail_on_open,::_1));
|
||||
// set fail hander to test for the right fail error code
|
||||
@@ -367,9 +432,9 @@ BOOST_AUTO_TEST_CASE( server_open_handshake_timeout ) {
|
||||
websocketpp::lib::thread sthread(websocketpp::lib::bind(&run_server,&s,9005,false));
|
||||
websocketpp::lib::thread tthread(websocketpp::lib::bind(&run_test_timer,6));
|
||||
tthread.detach();
|
||||
|
||||
|
||||
run_dummy_client("9005");
|
||||
|
||||
|
||||
sthread.join();
|
||||
}
|
||||
|
||||
@@ -386,13 +451,13 @@ BOOST_AUTO_TEST_CASE( client_self_initiated_close_handshake_timeout ) {
|
||||
c.set_open_handler(bind(&close<client>,&c,::_1));
|
||||
c.set_close_handler(bind(&check_ec<client>,&c,
|
||||
websocketpp::error::close_handshake_timeout,::_1));
|
||||
|
||||
|
||||
websocketpp::lib::thread sthread(websocketpp::lib::bind(&run_server,&s,9005,false));
|
||||
websocketpp::lib::thread tthread(websocketpp::lib::bind(&run_test_timer,6));
|
||||
tthread.detach();
|
||||
|
||||
run_client(c, "http://localhost:9005",false);
|
||||
|
||||
|
||||
run_client(c, "http://localhost:9005", false);
|
||||
|
||||
sthread.join();
|
||||
}
|
||||
|
||||
@@ -401,7 +466,7 @@ BOOST_AUTO_TEST_CASE( client_peer_initiated_close_handshake_timeout ) {
|
||||
// client should ack normally and then wait
|
||||
// server leaves TCP connection open
|
||||
// client handshake timer should be triggered
|
||||
|
||||
|
||||
// TODO: how to make a mock server that leaves the TCP connection open?
|
||||
}
|
||||
|
||||
@@ -418,7 +483,7 @@ BOOST_AUTO_TEST_CASE( server_self_initiated_close_handshake_timeout ) {
|
||||
websocketpp::error::close_handshake_timeout,::_1));
|
||||
|
||||
c.set_open_handler(bind(&delay,::_1,1));
|
||||
|
||||
|
||||
websocketpp::lib::thread sthread(websocketpp::lib::bind(&run_server,&s,9005,false));
|
||||
websocketpp::lib::thread tthread(websocketpp::lib::bind(&run_test_timer,6));
|
||||
tthread.detach();
|
||||
@@ -427,3 +492,115 @@ BOOST_AUTO_TEST_CASE( server_self_initiated_close_handshake_timeout ) {
|
||||
|
||||
sthread.join();
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE( client_runs_out_of_work ) {
|
||||
client c;
|
||||
|
||||
websocketpp::lib::thread tthread(websocketpp::lib::bind(&run_test_timer,3));
|
||||
tthread.detach();
|
||||
|
||||
websocketpp::lib::error_code ec;
|
||||
c.init_asio(ec);
|
||||
BOOST_CHECK(!ec);
|
||||
|
||||
c.run();
|
||||
|
||||
// This test checks that an io_service with no work ends immediately.
|
||||
BOOST_CHECK(true);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
BOOST_AUTO_TEST_CASE( client_is_perpetual ) {
|
||||
client c;
|
||||
bool flag = false;
|
||||
websocketpp::lib::mutex mutex;
|
||||
|
||||
websocketpp::lib::error_code ec;
|
||||
c.init_asio(ec);
|
||||
BOOST_CHECK(!ec);
|
||||
|
||||
c.start_perpetual();
|
||||
|
||||
websocketpp::lib::thread cthread(websocketpp::lib::bind(&run_client_and_mark,&c,&flag,&mutex));
|
||||
|
||||
sleep(1);
|
||||
|
||||
{
|
||||
// Checks that the thread hasn't exited yet
|
||||
websocketpp::lib::lock_guard<websocketpp::lib::mutex> lock(mutex);
|
||||
BOOST_CHECK( !flag );
|
||||
}
|
||||
|
||||
c.stop_perpetual();
|
||||
|
||||
sleep(1);
|
||||
|
||||
{
|
||||
// Checks that the thread has exited
|
||||
websocketpp::lib::lock_guard<websocketpp::lib::mutex> lock(mutex);
|
||||
BOOST_CHECK( flag );
|
||||
}
|
||||
|
||||
cthread.join();
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE( client_failed_connection ) {
|
||||
client c;
|
||||
|
||||
run_time_limited_client(c,"http://localhost:9005", 5, false);
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE( stop_listening ) {
|
||||
server s;
|
||||
client c;
|
||||
|
||||
// the first connection stops the server from listening
|
||||
s.set_open_handler(bind(&cancel_on_open,&s,::_1));
|
||||
|
||||
// client immediately closes after opening a connection
|
||||
c.set_open_handler(bind(&close<client>,&c,::_1));
|
||||
|
||||
websocketpp::lib::thread sthread(websocketpp::lib::bind(&run_server,&s,9005,false));
|
||||
websocketpp::lib::thread tthread(websocketpp::lib::bind(&run_test_timer,2));
|
||||
tthread.detach();
|
||||
|
||||
run_client(c, "http://localhost:9005",false);
|
||||
|
||||
sthread.join();
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE( pause_reading ) {
|
||||
iostream_server s;
|
||||
std::string handshake = "GET / HTTP/1.1\r\nHost: www.example.com\r\nConnection: upgrade\r\nUpgrade: websocket\r\nSec-WebSocket-Version: 13\r\nSec-WebSocket-Key: dGhlIHNhbXBsZSBub25jZQ==\r\n\r\n";
|
||||
char buffer[2] = { char(0x81), char(0x80) };
|
||||
|
||||
// suppress output (it needs a place to go to avoid error but we don't care what it is)
|
||||
std::stringstream null_output;
|
||||
s.register_ostream(&null_output);
|
||||
|
||||
iostream_server::connection_ptr con = s.get_connection();
|
||||
con->start();
|
||||
|
||||
// read handshake, should work
|
||||
BOOST_CHECK_EQUAL( con->read_some(handshake.data(), handshake.length()), handshake.length());
|
||||
|
||||
// pause reading and try again. The first read should work, the second should return 0
|
||||
// the first read was queued already after the handshake so it will go through because
|
||||
// reading wasn't paused when it was queued. The byte it reads wont be enough to
|
||||
// complete the frame so another read will be requested. This one wont actually happen
|
||||
// because the connection is paused now.
|
||||
con->pause_reading();
|
||||
BOOST_CHECK_EQUAL( con->read_some(buffer, 1), 1);
|
||||
BOOST_CHECK_EQUAL( con->read_some(buffer+1, 1), 0);
|
||||
// resume reading and try again. Should work this time because the resume should have
|
||||
// re-queued a read.
|
||||
con->resume_reading();
|
||||
BOOST_CHECK_EQUAL( con->read_some(buffer+1, 1), 1);
|
||||
}
|
||||
|
||||
|
||||
BOOST_AUTO_TEST_CASE( server_connection_cleanup ) {
|
||||
server_tls s;
|
||||
}
|
||||
@@ -11,10 +11,10 @@
|
||||
* * 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
|
||||
*
|
||||
* 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;
|
||||
@@ -22,7 +22,7 @@
|
||||
* 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.
|
||||
*
|
||||
*
|
||||
*/
|
||||
//#define BOOST_TEST_DYN_LINK
|
||||
#define BOOST_TEST_MODULE transport_iostream_base
|
||||
@@ -30,4 +30,4 @@
|
||||
|
||||
#include <iostream>
|
||||
|
||||
BOOST_AUTO_TEST_CASE( placeholder ) {}
|
||||
BOOST_AUTO_TEST_CASE( placeholder ) {}
|
||||
@@ -11,10 +11,10 @@
|
||||
* * 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
|
||||
*
|
||||
* 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;
|
||||
@@ -22,7 +22,7 @@
|
||||
* 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.
|
||||
*
|
||||
*
|
||||
*/
|
||||
//#define BOOST_TEST_DYN_LINK
|
||||
#define BOOST_TEST_MODULE transport_iostream_connection
|
||||
@@ -32,6 +32,8 @@
|
||||
#include <cstring>
|
||||
#include <string>
|
||||
|
||||
#include <websocketpp/common/memory.hpp>
|
||||
|
||||
#include <websocketpp/error.hpp>
|
||||
#include <websocketpp/transport/iostream/connection.hpp>
|
||||
|
||||
@@ -52,38 +54,45 @@ typedef websocketpp::transport::iostream::connection<config> iostream_con;
|
||||
using websocketpp::transport::iostream::error::make_error_code;
|
||||
|
||||
struct stub_con : public iostream_con {
|
||||
typedef stub_con type;
|
||||
typedef websocketpp::lib::shared_ptr<type> ptr;
|
||||
typedef iostream_con::timer_ptr timer_ptr;
|
||||
|
||||
stub_con(bool is_server, config::alog_type &a, config::elog_type & e)
|
||||
stub_con(bool is_server, config::alog_type & a, config::elog_type & e)
|
||||
: iostream_con(is_server,a,e)
|
||||
// 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))
|
||||
{}
|
||||
|
||||
|
||||
/// Get a shared pointer to this component
|
||||
ptr get_shared() {
|
||||
return websocketpp::lib::static_pointer_cast<type>(iostream_con::get_shared());
|
||||
}
|
||||
|
||||
void write(std::string msg) {
|
||||
iostream_con::async_write(
|
||||
msg.data(),
|
||||
msg.size(),
|
||||
websocketpp::lib::bind(
|
||||
&stub_con::handle_op,
|
||||
this,
|
||||
type::get_shared(),
|
||||
websocketpp::lib::placeholders::_1
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
void write(std::vector<websocketpp::transport::buffer> & bufs) {
|
||||
iostream_con::async_write(
|
||||
bufs,
|
||||
websocketpp::lib::bind(
|
||||
&stub_con::handle_op,
|
||||
this,
|
||||
type::get_shared(),
|
||||
websocketpp::lib::placeholders::_1
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
void async_read_at_least(size_t num_bytes, char *buf, size_t len)
|
||||
{
|
||||
iostream_con::async_read_at_least(
|
||||
@@ -92,191 +101,261 @@ struct stub_con : public iostream_con {
|
||||
len,
|
||||
websocketpp::lib::bind(
|
||||
&stub_con::handle_op,
|
||||
this,
|
||||
type::get_shared(),
|
||||
websocketpp::lib::placeholders::_1
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
void handle_op(const websocketpp::lib::error_code& e) {
|
||||
|
||||
void handle_op(websocketpp::lib::error_code const & e) {
|
||||
ec = e;
|
||||
}
|
||||
|
||||
|
||||
websocketpp::lib::error_code ec;
|
||||
};
|
||||
|
||||
// Stubs
|
||||
config::alog_type a;
|
||||
config::elog_type e;
|
||||
config::alog_type alogger;
|
||||
config::elog_type elogger;
|
||||
|
||||
BOOST_AUTO_TEST_CASE( const_methods ) {
|
||||
iostream_con con(true,a,e);
|
||||
|
||||
BOOST_CHECK( con.is_secure() == false );
|
||||
BOOST_CHECK( con.get_remote_endpoint() == "iostream transport" );
|
||||
iostream_con::ptr con(new iostream_con(true,alogger,elogger));
|
||||
|
||||
BOOST_CHECK( con->is_secure() == false );
|
||||
BOOST_CHECK( con->get_remote_endpoint() == "iostream transport" );
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE( write_before_ostream_set ) {
|
||||
stub_con con(true,a,e);
|
||||
|
||||
con.write("foo");
|
||||
BOOST_CHECK( con.ec == make_error_code(websocketpp::transport::iostream::error::output_stream_required) );
|
||||
|
||||
stub_con::ptr con(new stub_con(true,alogger,elogger));
|
||||
|
||||
con->write("foo");
|
||||
BOOST_CHECK( con->ec == make_error_code(websocketpp::transport::iostream::error::output_stream_required) );
|
||||
|
||||
std::vector<websocketpp::transport::buffer> bufs;
|
||||
con.write(bufs);
|
||||
BOOST_CHECK( con.ec == make_error_code(websocketpp::transport::iostream::error::output_stream_required) );
|
||||
con->write(bufs);
|
||||
BOOST_CHECK( con->ec == make_error_code(websocketpp::transport::iostream::error::output_stream_required) );
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE( async_write ) {
|
||||
stub_con con(true,a,e);
|
||||
|
||||
stub_con::ptr con(new stub_con(true,alogger,elogger));
|
||||
|
||||
std::stringstream output;
|
||||
|
||||
con.register_ostream(&output);
|
||||
|
||||
con.write("foo");
|
||||
|
||||
BOOST_CHECK( !con.ec );
|
||||
|
||||
con->register_ostream(&output);
|
||||
|
||||
con->write("foo");
|
||||
|
||||
BOOST_CHECK( !con->ec );
|
||||
BOOST_CHECK( output.str() == "foo" );
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE( async_write_vector_0 ) {
|
||||
std::stringstream output;
|
||||
|
||||
stub_con con(true,a,e);
|
||||
con.register_ostream(&output);
|
||||
|
||||
|
||||
stub_con::ptr con(new stub_con(true,alogger,elogger));
|
||||
con->register_ostream(&output);
|
||||
|
||||
std::vector<websocketpp::transport::buffer> bufs;
|
||||
|
||||
con.write(bufs);
|
||||
|
||||
BOOST_CHECK( !con.ec );
|
||||
|
||||
con->write(bufs);
|
||||
|
||||
BOOST_CHECK( !con->ec );
|
||||
BOOST_CHECK( output.str() == "" );
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE( async_write_vector_1 ) {
|
||||
std::stringstream output;
|
||||
|
||||
stub_con con(true,a,e);
|
||||
con.register_ostream(&output);
|
||||
|
||||
|
||||
stub_con::ptr con(new stub_con(true,alogger,elogger));
|
||||
con->register_ostream(&output);
|
||||
|
||||
std::vector<websocketpp::transport::buffer> bufs;
|
||||
|
||||
|
||||
std::string foo = "foo";
|
||||
|
||||
|
||||
bufs.push_back(websocketpp::transport::buffer(foo.data(),foo.size()));
|
||||
|
||||
con.write(bufs);
|
||||
|
||||
BOOST_CHECK( !con.ec );
|
||||
|
||||
con->write(bufs);
|
||||
|
||||
BOOST_CHECK( !con->ec );
|
||||
BOOST_CHECK( output.str() == "foo" );
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE( async_write_vector_2 ) {
|
||||
std::stringstream output;
|
||||
|
||||
stub_con con(true,a,e);
|
||||
con.register_ostream(&output);
|
||||
|
||||
|
||||
stub_con::ptr con(new stub_con(true,alogger,elogger));
|
||||
con->register_ostream(&output);
|
||||
|
||||
std::vector<websocketpp::transport::buffer> bufs;
|
||||
|
||||
|
||||
std::string foo = "foo";
|
||||
std::string bar = "bar";
|
||||
|
||||
|
||||
bufs.push_back(websocketpp::transport::buffer(foo.data(),foo.size()));
|
||||
bufs.push_back(websocketpp::transport::buffer(bar.data(),bar.size()));
|
||||
|
||||
con.write(bufs);
|
||||
|
||||
BOOST_CHECK( !con.ec );
|
||||
|
||||
con->write(bufs);
|
||||
|
||||
BOOST_CHECK( !con->ec );
|
||||
BOOST_CHECK( output.str() == "foobar" );
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE( async_read_at_least_too_much ) {
|
||||
stub_con con(true,a,e);
|
||||
|
||||
stub_con::ptr con(new stub_con(true,alogger,elogger));
|
||||
|
||||
char buf[10];
|
||||
|
||||
con.async_read_at_least(11,buf,10);
|
||||
BOOST_CHECK( con.ec == make_error_code(websocketpp::transport::iostream::error::invalid_num_bytes) );
|
||||
|
||||
con->async_read_at_least(11,buf,10);
|
||||
BOOST_CHECK( con->ec == make_error_code(websocketpp::transport::iostream::error::invalid_num_bytes) );
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE( async_read_at_least_double_read ) {
|
||||
stub_con con(true,a,e);
|
||||
|
||||
stub_con::ptr con(new stub_con(true,alogger,elogger));
|
||||
|
||||
char buf[10];
|
||||
|
||||
con.async_read_at_least(5,buf,10);
|
||||
con.async_read_at_least(5,buf,10);
|
||||
BOOST_CHECK( con.ec == make_error_code(websocketpp::transport::iostream::error::double_read) );
|
||||
|
||||
con->async_read_at_least(5,buf,10);
|
||||
con->async_read_at_least(5,buf,10);
|
||||
BOOST_CHECK( con->ec == make_error_code(websocketpp::transport::iostream::error::double_read) );
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE( async_read_at_least ) {
|
||||
stub_con con(true,a,e);
|
||||
|
||||
stub_con::ptr con(new stub_con(true,alogger,elogger));
|
||||
|
||||
char buf[10];
|
||||
|
||||
|
||||
memset(buf,'x',10);
|
||||
|
||||
con.async_read_at_least(5,buf,10);
|
||||
BOOST_CHECK( con.ec == make_error_code(websocketpp::error::test) );
|
||||
|
||||
|
||||
con->async_read_at_least(5,buf,10);
|
||||
BOOST_CHECK( con->ec == make_error_code(websocketpp::error::test) );
|
||||
|
||||
std::stringstream channel;
|
||||
channel << "abcd";
|
||||
channel >> con;
|
||||
channel >> *con;
|
||||
BOOST_CHECK( channel.tellg() == -1 );
|
||||
BOOST_CHECK( con.ec == make_error_code(websocketpp::error::test) );
|
||||
|
||||
BOOST_CHECK( con->ec == make_error_code(websocketpp::error::test) );
|
||||
|
||||
std::stringstream channel2;
|
||||
channel2 << "e";
|
||||
channel2 >> con;
|
||||
channel2 >> *con;
|
||||
BOOST_CHECK( channel2.tellg() == -1 );
|
||||
BOOST_CHECK( !con.ec );
|
||||
BOOST_CHECK( !con->ec );
|
||||
BOOST_CHECK( std::string(buf,10) == "abcdexxxxx" );
|
||||
|
||||
|
||||
std::stringstream channel3;
|
||||
channel3 << "f";
|
||||
channel3 >> con;
|
||||
channel3 >> *con;
|
||||
BOOST_CHECK( channel3.tellg() == 0 );
|
||||
BOOST_CHECK( !con.ec );
|
||||
BOOST_CHECK( !con->ec );
|
||||
BOOST_CHECK( std::string(buf,10) == "abcdexxxxx" );
|
||||
con.async_read_at_least(1,buf+5,5);
|
||||
channel3 >> con;
|
||||
con->async_read_at_least(1,buf+5,5);
|
||||
channel3 >> *con;
|
||||
BOOST_CHECK( channel3.tellg() == -1 );
|
||||
BOOST_CHECK( !con.ec );
|
||||
BOOST_CHECK( !con->ec );
|
||||
BOOST_CHECK( std::string(buf,10) == "abcdefxxxx" );
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE( async_read_at_least2 ) {
|
||||
stub_con con(true,a,e);
|
||||
|
||||
stub_con::ptr con(new stub_con(true,alogger,elogger));
|
||||
|
||||
char buf[10];
|
||||
|
||||
|
||||
memset(buf,'x',10);
|
||||
|
||||
con.async_read_at_least(5,buf,5);
|
||||
BOOST_CHECK( con.ec == make_error_code(websocketpp::error::test) );
|
||||
|
||||
|
||||
con->async_read_at_least(5,buf,5);
|
||||
BOOST_CHECK( con->ec == make_error_code(websocketpp::error::test) );
|
||||
|
||||
std::stringstream channel;
|
||||
channel << "abcdefg";
|
||||
channel >> con;
|
||||
channel >> *con;
|
||||
BOOST_CHECK( channel.tellg() == 5 );
|
||||
BOOST_CHECK( !con.ec );
|
||||
BOOST_CHECK( !con->ec );
|
||||
BOOST_CHECK( std::string(buf,10) == "abcdexxxxx" );
|
||||
|
||||
con.async_read_at_least(1,buf+5,5);
|
||||
channel >> con;
|
||||
|
||||
con->async_read_at_least(1,buf+5,5);
|
||||
channel >> *con;
|
||||
BOOST_CHECK( channel.tellg() == -1 );
|
||||
BOOST_CHECK( !con.ec );
|
||||
BOOST_CHECK( !con->ec );
|
||||
BOOST_CHECK( std::string(buf,10) == "abcdefgxxx" );
|
||||
}
|
||||
|
||||
void timer_callback_stub(const websocketpp::lib::error_code & ec) {}
|
||||
|
||||
BOOST_AUTO_TEST_CASE( set_timer ) {
|
||||
stub_con con(true,a,e);
|
||||
|
||||
stub_con::timer_ptr tp = con.set_timer(1000,timer_callback_stub);
|
||||
|
||||
stub_con::ptr con(new stub_con(true,alogger,elogger));
|
||||
|
||||
stub_con::timer_ptr tp = con->set_timer(1000,timer_callback_stub);
|
||||
|
||||
BOOST_CHECK( !tp );
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE( async_read_at_least_read_some ) {
|
||||
stub_con::ptr con(new stub_con(true,alogger,elogger));
|
||||
|
||||
char buf[10];
|
||||
memset(buf,'x',10);
|
||||
|
||||
con->async_read_at_least(5,buf,5);
|
||||
BOOST_CHECK( con->ec == make_error_code(websocketpp::error::test) );
|
||||
|
||||
char input[10] = "abcdefg";
|
||||
BOOST_CHECK_EQUAL(con->read_some(input,5), 5);
|
||||
BOOST_CHECK( !con->ec );
|
||||
BOOST_CHECK_EQUAL( std::string(buf,10), "abcdexxxxx" );
|
||||
|
||||
BOOST_CHECK_EQUAL(con->read_some(input+5,2), 0);
|
||||
BOOST_CHECK( !con->ec );
|
||||
BOOST_CHECK_EQUAL( std::string(buf,10), "abcdexxxxx" );
|
||||
|
||||
con->async_read_at_least(1,buf+5,5);
|
||||
BOOST_CHECK_EQUAL(con->read_some(input+5,2), 2);
|
||||
BOOST_CHECK( !con->ec );
|
||||
BOOST_CHECK_EQUAL( std::string(buf,10), "abcdefgxxx" );
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE( eof_flag ) {
|
||||
stub_con::ptr con(new stub_con(true,alogger,elogger));
|
||||
char buf[10];
|
||||
con->async_read_at_least(5,buf,5);
|
||||
BOOST_CHECK( con->ec == make_error_code(websocketpp::error::test) );
|
||||
con->eof();
|
||||
BOOST_CHECK_EQUAL( con->ec, make_error_code(websocketpp::transport::error::eof) );
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE( fatal_error_flag ) {
|
||||
stub_con::ptr con(new stub_con(true,alogger,elogger));
|
||||
char buf[10];
|
||||
con->async_read_at_least(5,buf,5);
|
||||
BOOST_CHECK( con->ec == make_error_code(websocketpp::error::test) );
|
||||
con->fatal_error();
|
||||
BOOST_CHECK_EQUAL( con->ec, make_error_code(websocketpp::transport::error::pass_through) );
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE( shared_pointer_memory_cleanup ) {
|
||||
stub_con::ptr con(new stub_con(true,alogger,elogger));
|
||||
|
||||
BOOST_CHECK_EQUAL(con.use_count(), 1);
|
||||
|
||||
char buf[10];
|
||||
memset(buf,'x',10);
|
||||
con->async_read_at_least(5,buf,5);
|
||||
BOOST_CHECK( con->ec == make_error_code(websocketpp::error::test) );
|
||||
BOOST_CHECK_EQUAL(con.use_count(), 2);
|
||||
|
||||
char input[10] = "foo";
|
||||
con->read_some(input,3);
|
||||
BOOST_CHECK_EQUAL(con.use_count(), 2);
|
||||
|
||||
con->read_some(input,2);
|
||||
BOOST_CHECK_EQUAL( std::string(buf,10), "foofoxxxxx" );
|
||||
BOOST_CHECK_EQUAL(con.use_count(), 1);
|
||||
|
||||
con->async_read_at_least(5,buf,5);
|
||||
BOOST_CHECK_EQUAL(con.use_count(), 2);
|
||||
|
||||
con->eof();
|
||||
BOOST_CHECK_EQUAL( con->ec, make_error_code(websocketpp::transport::error::eof) );
|
||||
BOOST_CHECK_EQUAL(con.use_count(), 1);
|
||||
}
|
||||
|
||||
@@ -11,10 +11,10 @@
|
||||
* * 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
|
||||
*
|
||||
* 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;
|
||||
@@ -22,7 +22,7 @@
|
||||
* 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.
|
||||
*
|
||||
*
|
||||
*/
|
||||
//#define BOOST_TEST_DYN_LINK
|
||||
#define BOOST_TEST_MODULE transport_iostream_endpoint
|
||||
@@ -36,6 +36,6 @@ BOOST_AUTO_TEST_CASE( placeholder ) {}
|
||||
|
||||
/*BOOST_AUTO_TEST_CASE( blank_error ) {
|
||||
websocketpp::lib::error_code ec;
|
||||
|
||||
|
||||
BOOST_CHECK( !ec );
|
||||
}*/
|
||||
}*/
|
||||
+17
-19
@@ -11,10 +11,10 @@
|
||||
* * 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
|
||||
*
|
||||
* 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;
|
||||
@@ -22,7 +22,7 @@
|
||||
* 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.
|
||||
*
|
||||
*
|
||||
*/
|
||||
//#define BOOST_TEST_DYN_LINK
|
||||
#define BOOST_TEST_MODULE close
|
||||
@@ -39,8 +39,6 @@ using namespace websocketpp;
|
||||
BOOST_AUTO_TEST_CASE( reserved_values ) {
|
||||
BOOST_CHECK( !close::status::reserved(999) );
|
||||
BOOST_CHECK( close::status::reserved(1004) );
|
||||
BOOST_CHECK( close::status::reserved(1012) );
|
||||
BOOST_CHECK( close::status::reserved(1013) );
|
||||
BOOST_CHECK( close::status::reserved(1014) );
|
||||
BOOST_CHECK( close::status::reserved(1016) );
|
||||
BOOST_CHECK( close::status::reserved(2999) );
|
||||
@@ -62,25 +60,25 @@ BOOST_AUTO_TEST_CASE( invalid_values ) {
|
||||
BOOST_AUTO_TEST_CASE( value_extraction ) {
|
||||
lib::error_code ec;
|
||||
std::string payload = "oo";
|
||||
|
||||
|
||||
// Value = 1000
|
||||
payload[0] = 0x03;
|
||||
payload[1] = char(0xe8);
|
||||
BOOST_CHECK( close::extract_code(payload,ec) == close::status::normal );
|
||||
BOOST_CHECK( !ec );
|
||||
|
||||
|
||||
// Value = 1004
|
||||
payload[0] = 0x03;
|
||||
payload[1] = char(0xec);
|
||||
BOOST_CHECK( close::extract_code(payload,ec) == 1004 );
|
||||
BOOST_CHECK( ec == error::reserved_close_code );
|
||||
|
||||
|
||||
// Value = 1005
|
||||
payload[0] = 0x03;
|
||||
payload[1] = char(0xed);
|
||||
BOOST_CHECK( close::extract_code(payload,ec) == close::status::no_status );
|
||||
BOOST_CHECK( ec == error::invalid_close_code );
|
||||
|
||||
|
||||
// Value = 3000
|
||||
payload[0] = 0x0b;
|
||||
payload[1] = char(0xb8);
|
||||
@@ -91,7 +89,7 @@ BOOST_AUTO_TEST_CASE( value_extraction ) {
|
||||
BOOST_AUTO_TEST_CASE( extract_empty ) {
|
||||
lib::error_code ec;
|
||||
std::string payload = "";
|
||||
|
||||
|
||||
BOOST_CHECK( close::extract_code(payload,ec) == close::status::no_status );
|
||||
BOOST_CHECK( !ec );
|
||||
}
|
||||
@@ -99,7 +97,7 @@ BOOST_AUTO_TEST_CASE( extract_empty ) {
|
||||
BOOST_AUTO_TEST_CASE( extract_short ) {
|
||||
lib::error_code ec;
|
||||
std::string payload = "0";
|
||||
|
||||
|
||||
BOOST_CHECK( close::extract_code(payload,ec) == close::status::protocol_error );
|
||||
BOOST_CHECK( ec == error::bad_close_code );
|
||||
}
|
||||
@@ -107,21 +105,21 @@ BOOST_AUTO_TEST_CASE( extract_short ) {
|
||||
BOOST_AUTO_TEST_CASE( extract_reason ) {
|
||||
lib::error_code ec;
|
||||
std::string payload = "00Foo";
|
||||
|
||||
|
||||
BOOST_CHECK( close::extract_reason(payload,ec) == "Foo" );
|
||||
BOOST_CHECK( !ec );
|
||||
|
||||
|
||||
payload = "";
|
||||
BOOST_CHECK( close::extract_reason(payload,ec) == "" );
|
||||
BOOST_CHECK( !ec );
|
||||
|
||||
|
||||
payload = "00";
|
||||
BOOST_CHECK( close::extract_reason(payload,ec) == "" );
|
||||
BOOST_CHECK( !ec );
|
||||
|
||||
|
||||
payload = "000";
|
||||
payload[2] = char(0xFF);
|
||||
|
||||
|
||||
close::extract_reason(payload,ec);
|
||||
BOOST_CHECK( ec == error::invalid_utf8 );
|
||||
}
|
||||
}
|
||||
+52
-52
@@ -11,10 +11,10 @@
|
||||
* * 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
|
||||
*
|
||||
* 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;
|
||||
@@ -22,7 +22,7 @@
|
||||
* 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.
|
||||
*
|
||||
*
|
||||
*/
|
||||
//#define BOOST_TEST_DYN_LINK
|
||||
#define BOOST_TEST_MODULE frame
|
||||
@@ -39,7 +39,7 @@ using namespace websocketpp;
|
||||
BOOST_AUTO_TEST_CASE( basic_bits ) {
|
||||
frame::basic_header h1(0x00,0x00); // all false
|
||||
frame::basic_header h2(0xF0,0x80); // all true
|
||||
|
||||
|
||||
// Read Values
|
||||
BOOST_CHECK( frame::get_fin(h1) == false );
|
||||
BOOST_CHECK( frame::get_rsv1(h1) == false );
|
||||
@@ -52,20 +52,20 @@ BOOST_AUTO_TEST_CASE( basic_bits ) {
|
||||
BOOST_CHECK( frame::get_rsv2(h2) == true );
|
||||
BOOST_CHECK( frame::get_rsv3(h2) == true );
|
||||
BOOST_CHECK( frame::get_masked(h2) == true );
|
||||
|
||||
|
||||
// Set Values
|
||||
frame::set_fin(h1,true);
|
||||
BOOST_CHECK( h1.b0 == 0x80 );
|
||||
|
||||
|
||||
frame::set_rsv1(h1,true);
|
||||
BOOST_CHECK( h1.b0 == 0xC0 );
|
||||
|
||||
|
||||
frame::set_rsv2(h1,true);
|
||||
BOOST_CHECK( h1.b0 == 0xE0 );
|
||||
|
||||
|
||||
frame::set_rsv3(h1,true);
|
||||
BOOST_CHECK( h1.b0 == 0xF0 );
|
||||
|
||||
|
||||
frame::set_masked(h1,true);
|
||||
BOOST_CHECK( h1.b1 == 0x80 );
|
||||
}
|
||||
@@ -105,19 +105,19 @@ BOOST_AUTO_TEST_CASE( basic_size ) {
|
||||
BOOST_CHECK( frame::get_basic_size(h4) == 126 );
|
||||
BOOST_CHECK( frame::get_basic_size(h5) == 127 );
|
||||
BOOST_CHECK( frame::get_basic_size(h6) == 0 );
|
||||
|
||||
|
||||
/*frame::set_basic_size(h1,1);
|
||||
BOOST_CHECK( h1.b1 == 0x01 );
|
||||
|
||||
|
||||
frame::set_basic_size(h1,125);
|
||||
BOOST_CHECK( h1.b1 == 0x7D );
|
||||
|
||||
|
||||
frame::set_basic_size(h1,126);
|
||||
BOOST_CHECK( h1.b1 == 0x7E );
|
||||
|
||||
|
||||
frame::set_basic_size(h1,127);
|
||||
BOOST_CHECK( h1.b1 == 0x7F );
|
||||
|
||||
|
||||
frame::set_basic_size(h1,0);
|
||||
BOOST_CHECK( h1.b1 == 0x00 );*/
|
||||
}
|
||||
@@ -140,7 +140,7 @@ BOOST_AUTO_TEST_CASE( basic_header_length ) {
|
||||
|
||||
BOOST_AUTO_TEST_CASE( basic_opcode ) {
|
||||
frame::basic_header h1(0x00,0x00);
|
||||
|
||||
|
||||
BOOST_CHECK( is_control(frame::opcode::CONTINUATION) == false);
|
||||
BOOST_CHECK( is_control(frame::opcode::TEXT) == false);
|
||||
BOOST_CHECK( is_control(frame::opcode::BINARY) == false);
|
||||
@@ -155,7 +155,7 @@ BOOST_AUTO_TEST_CASE( extended_header_basics ) {
|
||||
frame::extended_header h1;
|
||||
uint8_t h1_solution[12] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
|
||||
|
||||
|
||||
frame::extended_header h2(uint16_t(255));
|
||||
uint8_t h2_solution[12] = {0x00, 0xFF, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
|
||||
@@ -193,7 +193,7 @@ BOOST_AUTO_TEST_CASE( extended_header_extractors ) {
|
||||
BOOST_CHECK( get_payload_size(h2,e2) == 0x0807060504030201LL );
|
||||
BOOST_CHECK( get_masking_key_offset(h2) == 8 );
|
||||
BOOST_CHECK( get_masking_key(h2,e2).i == 0 );
|
||||
|
||||
|
||||
frame::basic_header h3(0x00,0xFE);
|
||||
frame::extended_header e3(uint16_t(255),0x08040201);
|
||||
BOOST_CHECK( get_extended_size(e3) == 255 );
|
||||
@@ -217,25 +217,25 @@ BOOST_AUTO_TEST_CASE( header_preparation ) {
|
||||
frame::basic_header h1(0x81,0xFF); //
|
||||
frame::extended_header e1(uint64_t(0xFFFFFLL),htonl(0xD5FB70EE));
|
||||
std::string p1 = prepare_header(h1, e1);
|
||||
uint8_t s1[14] = {0x81, 0xFF,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x0F, 0xFF, 0xFF,
|
||||
uint8_t s1[14] = {0x81, 0xFF,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x0F, 0xFF, 0xFF,
|
||||
0xD5, 0xFB, 0x70, 0xEE};
|
||||
|
||||
|
||||
BOOST_CHECK( p1.size() == 14);
|
||||
BOOST_CHECK( std::equal(p1.begin(),p1.end(),reinterpret_cast<char*>(s1)) );
|
||||
|
||||
|
||||
frame::basic_header h2(0x81,0x7E); //
|
||||
frame::extended_header e2(uint16_t(255));
|
||||
std::string p2 = prepare_header(h2, e2);
|
||||
uint8_t s2[4] = {0x81, 0x7E, 0x00, 0xFF};
|
||||
|
||||
|
||||
BOOST_CHECK( p2.size() == 4);
|
||||
BOOST_CHECK( std::equal(p2.begin(),p2.end(),reinterpret_cast<char*>(s2)) );
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE( prepare_masking_key ) {
|
||||
frame::masking_key_type key;
|
||||
|
||||
|
||||
key.i = htonl(0x12345678);
|
||||
|
||||
if (sizeof(size_t) == 8) {
|
||||
@@ -266,14 +266,14 @@ BOOST_AUTO_TEST_CASE( prepare_masking_key2 ) {
|
||||
BOOST_AUTO_TEST_CASE( circshift ) {
|
||||
/*if (sizeof(size_t) == 8) {
|
||||
size_t test = 0x0123456789abcdef;
|
||||
|
||||
|
||||
BOOST_CHECK( frame::circshift_prepared_key(test,0) == 0x0123456789abcdef);
|
||||
BOOST_CHECK( frame::circshift_prepared_key(test,1) == 0xef0123456789abcd);
|
||||
BOOST_CHECK( frame::circshift_prepared_key(test,2) == 0xcdef0123456789ab);
|
||||
BOOST_CHECK( frame::circshift_prepared_key(test,3) == 0xabcdef0123456789);
|
||||
} else {
|
||||
size_t test = 0x01234567;
|
||||
|
||||
|
||||
BOOST_CHECK( frame::circshift_prepared_key(test,0) == 0x01234567);
|
||||
BOOST_CHECK( frame::circshift_prepared_key(test,1) == 0x67012345);
|
||||
BOOST_CHECK( frame::circshift_prepared_key(test,2) == 0x45670123);
|
||||
@@ -282,13 +282,13 @@ BOOST_AUTO_TEST_CASE( circshift ) {
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE( block_byte_mask ) {
|
||||
uint8_t input[15] = {0x00, 0x00, 0x00, 0x00,
|
||||
uint8_t input[15] = {0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00};
|
||||
|
||||
|
||||
uint8_t output[15];
|
||||
|
||||
|
||||
uint8_t masked[15] = {0x00, 0x01, 0x02, 0x03,
|
||||
0x00, 0x01, 0x02, 0x03,
|
||||
0x00, 0x01, 0x02, 0x03,
|
||||
@@ -299,18 +299,18 @@ BOOST_AUTO_TEST_CASE( block_byte_mask ) {
|
||||
key.c[1] = 0x01;
|
||||
key.c[2] = 0x02;
|
||||
key.c[3] = 0x03;
|
||||
|
||||
|
||||
byte_mask(input,input+15,output,key);
|
||||
|
||||
|
||||
BOOST_CHECK( std::equal(output,output+15,masked) );
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE( block_byte_mask_inplace ) {
|
||||
uint8_t buffer[15] = {0x00, 0x00, 0x00, 0x00,
|
||||
uint8_t buffer[15] = {0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00};
|
||||
|
||||
|
||||
uint8_t masked[15] = {0x00, 0x01, 0x02, 0x03,
|
||||
0x00, 0x01, 0x02, 0x03,
|
||||
0x00, 0x01, 0x02, 0x03,
|
||||
@@ -321,20 +321,20 @@ BOOST_AUTO_TEST_CASE( block_byte_mask_inplace ) {
|
||||
key.c[1] = 0x01;
|
||||
key.c[2] = 0x02;
|
||||
key.c[3] = 0x03;
|
||||
|
||||
|
||||
byte_mask(buffer,buffer+15,key);
|
||||
|
||||
BOOST_CHECK( std::equal(buffer,buffer+15,masked) );
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE( block_word_mask ) {
|
||||
uint8_t input[15] = {0x00, 0x00, 0x00, 0x00,
|
||||
uint8_t input[15] = {0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00};
|
||||
|
||||
|
||||
uint8_t output[15];
|
||||
|
||||
|
||||
uint8_t masked[15] = {0x00, 0x01, 0x02, 0x03,
|
||||
0x00, 0x01, 0x02, 0x03,
|
||||
0x00, 0x01, 0x02, 0x03,
|
||||
@@ -345,18 +345,18 @@ BOOST_AUTO_TEST_CASE( block_word_mask ) {
|
||||
key.c[1] = 0x01;
|
||||
key.c[2] = 0x02;
|
||||
key.c[3] = 0x03;
|
||||
|
||||
|
||||
word_mask_exact(input,output,15,key);
|
||||
|
||||
BOOST_CHECK( std::equal(output,output+15,masked) );
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE( block_word_mask_inplace ) {
|
||||
uint8_t buffer[15] = {0x00, 0x00, 0x00, 0x00,
|
||||
uint8_t buffer[15] = {0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00};
|
||||
|
||||
|
||||
uint8_t masked[15] = {0x00, 0x01, 0x02, 0x03,
|
||||
0x00, 0x01, 0x02, 0x03,
|
||||
0x00, 0x01, 0x02, 0x03,
|
||||
@@ -367,7 +367,7 @@ BOOST_AUTO_TEST_CASE( block_word_mask_inplace ) {
|
||||
key.c[1] = 0x01;
|
||||
key.c[2] = 0x02;
|
||||
key.c[3] = 0x03;
|
||||
|
||||
|
||||
word_mask_exact(buffer,15,key);
|
||||
|
||||
BOOST_CHECK( std::equal(buffer,buffer+15,masked) );
|
||||
@@ -376,7 +376,7 @@ BOOST_AUTO_TEST_CASE( block_word_mask_inplace ) {
|
||||
BOOST_AUTO_TEST_CASE( continuous_word_mask ) {
|
||||
uint8_t input[16];
|
||||
uint8_t output[16];
|
||||
|
||||
|
||||
uint8_t masked[16] = {0x00, 0x01, 0x02, 0x03,
|
||||
0x00, 0x01, 0x02, 0x03,
|
||||
0x00, 0x01, 0x02, 0x03,
|
||||
@@ -400,7 +400,7 @@ BOOST_AUTO_TEST_CASE( continuous_word_mask ) {
|
||||
pkey = frame::prepare_masking_key(key);
|
||||
std::fill_n(input,16,0x00);
|
||||
std::fill_n(output,16,0x00);
|
||||
|
||||
|
||||
pkey_temp = frame::word_mask_circ(input,output,7,pkey);
|
||||
BOOST_CHECK( std::equal(output,output+7,masked) );
|
||||
BOOST_CHECK( pkey_temp == frame::circshift_prepared_key(pkey,3) );
|
||||
@@ -413,7 +413,7 @@ BOOST_AUTO_TEST_CASE( continuous_word_mask ) {
|
||||
BOOST_AUTO_TEST_CASE( continuous_byte_mask ) {
|
||||
uint8_t input[16];
|
||||
uint8_t output[16];
|
||||
|
||||
|
||||
uint8_t masked[16] = {0x00, 0x01, 0x02, 0x03,
|
||||
0x00, 0x01, 0x02, 0x03,
|
||||
0x00, 0x01, 0x02, 0x03,
|
||||
@@ -437,7 +437,7 @@ BOOST_AUTO_TEST_CASE( continuous_byte_mask ) {
|
||||
pkey = frame::prepare_masking_key(key);
|
||||
std::fill_n(input,16,0x00);
|
||||
std::fill_n(output,16,0x00);
|
||||
|
||||
|
||||
pkey_temp = frame::byte_mask_circ(input,output,7,pkey);
|
||||
BOOST_CHECK( std::equal(output,output+7,masked) );
|
||||
BOOST_CHECK( pkey_temp == frame::circshift_prepared_key(pkey,3) );
|
||||
@@ -449,7 +449,7 @@ BOOST_AUTO_TEST_CASE( continuous_byte_mask ) {
|
||||
|
||||
BOOST_AUTO_TEST_CASE( continuous_word_mask_inplace ) {
|
||||
uint8_t buffer[16];
|
||||
|
||||
|
||||
uint8_t masked[16] = {0x00, 0x01, 0x02, 0x03,
|
||||
0x00, 0x01, 0x02, 0x03,
|
||||
0x00, 0x01, 0x02, 0x03,
|
||||
@@ -471,7 +471,7 @@ BOOST_AUTO_TEST_CASE( continuous_word_mask_inplace ) {
|
||||
// calls not split on word boundaries
|
||||
pkey = frame::prepare_masking_key(key);
|
||||
std::fill_n(buffer,16,0x00);
|
||||
|
||||
|
||||
pkey_temp = frame::word_mask_circ(buffer,7,pkey);
|
||||
BOOST_CHECK( std::equal(buffer,buffer+7,masked) );
|
||||
BOOST_CHECK_EQUAL( pkey_temp, frame::circshift_prepared_key(pkey,3) );
|
||||
@@ -483,7 +483,7 @@ BOOST_AUTO_TEST_CASE( continuous_word_mask_inplace ) {
|
||||
|
||||
BOOST_AUTO_TEST_CASE( continuous_byte_mask_inplace ) {
|
||||
uint8_t buffer[16];
|
||||
|
||||
|
||||
uint8_t masked[16] = {0x00, 0x01, 0x02, 0x03,
|
||||
0x00, 0x01, 0x02, 0x03,
|
||||
0x00, 0x01, 0x02, 0x03,
|
||||
@@ -505,7 +505,7 @@ BOOST_AUTO_TEST_CASE( continuous_byte_mask_inplace ) {
|
||||
// calls not split on word boundaries
|
||||
pkey = frame::prepare_masking_key(key);
|
||||
std::fill_n(buffer,16,0x00);
|
||||
|
||||
|
||||
pkey_temp = frame::byte_mask_circ(buffer,7,pkey);
|
||||
BOOST_CHECK( std::equal(buffer,buffer+7,masked) );
|
||||
BOOST_CHECK_EQUAL( pkey_temp, frame::circshift_prepared_key(pkey,3) );
|
||||
@@ -515,11 +515,11 @@ BOOST_AUTO_TEST_CASE( continuous_byte_mask_inplace ) {
|
||||
BOOST_CHECK_EQUAL( pkey_temp, frame::circshift_prepared_key(pkey,3) );
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE( continuous_word_mask2 ) {
|
||||
BOOST_AUTO_TEST_CASE( continuous_word_mask2 ) {
|
||||
uint8_t buffer[12] = {0xA6, 0x15, 0x97, 0xB9,
|
||||
0x81, 0x50, 0xAC, 0xBA,
|
||||
0x9C, 0x1C, 0x9F, 0xF4};
|
||||
|
||||
|
||||
uint8_t unmasked[12] = {0x48, 0x65, 0x6C, 0x6C,
|
||||
0x6F, 0x20, 0x57, 0x6F,
|
||||
0x72, 0x6C, 0x64, 0x21};
|
||||
|
||||
+31
-34
@@ -11,10 +11,10 @@
|
||||
* * 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
|
||||
*
|
||||
* 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;
|
||||
@@ -22,7 +22,7 @@
|
||||
* 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.
|
||||
*
|
||||
*
|
||||
*/
|
||||
//#define BOOST_TEST_DYN_LINK
|
||||
#define BOOST_TEST_MODULE sha1
|
||||
@@ -37,48 +37,45 @@
|
||||
BOOST_AUTO_TEST_SUITE ( sha1 )
|
||||
|
||||
BOOST_AUTO_TEST_CASE( sha1_test_a ) {
|
||||
websocketpp::sha1 sha;
|
||||
uint32_t digest[5];
|
||||
unsigned char hash[20];
|
||||
unsigned char reference[20] = {0xa9, 0x99, 0x3e, 0x36, 0x47,
|
||||
0x06, 0x81, 0x6a, 0xba, 0x3e,
|
||||
0x25, 0x71, 0x78, 0x50, 0xc2,
|
||||
0x6c, 0x9c, 0xd0, 0xd8, 0x9d};
|
||||
|
||||
sha << "abc";
|
||||
BOOST_CHECK(sha.get_raw_digest(digest));
|
||||
websocketpp::sha1::calc("abc",3,hash);
|
||||
|
||||
BOOST_CHECK_EQUAL( digest[0], 0xa9993e36 );
|
||||
BOOST_CHECK_EQUAL( digest[1], 0x4706816a );
|
||||
BOOST_CHECK_EQUAL( digest[2], 0xba3e2571 );
|
||||
BOOST_CHECK_EQUAL( digest[3], 0x7850c26c );
|
||||
BOOST_CHECK_EQUAL( digest[4], 0x9cd0d89d );
|
||||
BOOST_CHECK_EQUAL_COLLECTIONS(hash, hash+20, reference, reference+20);
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE( sha1_test_b ) {
|
||||
websocketpp::sha1 sha;
|
||||
uint32_t digest[5];
|
||||
unsigned char hash[20];
|
||||
unsigned char reference[20] = {0x84, 0x98, 0x3e, 0x44, 0x1c,
|
||||
0x3b, 0xd2, 0x6e, 0xba, 0xae,
|
||||
0x4a, 0xa1, 0xf9, 0x51, 0x29,
|
||||
0xe5, 0xe5, 0x46, 0x70, 0xf1};
|
||||
|
||||
sha << "abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq";
|
||||
BOOST_CHECK(sha.get_raw_digest(digest));
|
||||
websocketpp::sha1::calc(
|
||||
"abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq",56,hash);
|
||||
|
||||
BOOST_CHECK_EQUAL( digest[0], 0x84983e44 );
|
||||
BOOST_CHECK_EQUAL( digest[1], 0x1c3bd26e );
|
||||
BOOST_CHECK_EQUAL( digest[2], 0xbaae4aa1 );
|
||||
BOOST_CHECK_EQUAL( digest[3], 0xf95129e5 );
|
||||
BOOST_CHECK_EQUAL( digest[4], 0xe54670f1 );
|
||||
BOOST_CHECK_EQUAL_COLLECTIONS(hash, hash+20, reference, reference+20);
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE( sha1_test_c ) {
|
||||
websocketpp::sha1 sha;
|
||||
uint32_t digest[5];
|
||||
|
||||
for (int i = 1; i <= 1000000; i++) {
|
||||
sha.input('a');
|
||||
std::string input;
|
||||
unsigned char hash[20];
|
||||
unsigned char reference[20] = {0x34, 0xaa, 0x97, 0x3c, 0xd4,
|
||||
0xc4, 0xda, 0xa4, 0xf6, 0x1e,
|
||||
0xeb, 0x2b, 0xdb, 0xad, 0x27,
|
||||
0x31, 0x65, 0x34, 0x01, 0x6f};
|
||||
|
||||
for (int i = 0; i < 1000000; i++) {
|
||||
input += 'a';
|
||||
}
|
||||
|
||||
BOOST_CHECK(sha.get_raw_digest(digest));
|
||||
websocketpp::sha1::calc(input.c_str(),input.size(),hash);
|
||||
|
||||
BOOST_CHECK_EQUAL( digest[0], 0x34aa973c );
|
||||
BOOST_CHECK_EQUAL( digest[1], 0xd4c4daa4 );
|
||||
BOOST_CHECK_EQUAL( digest[2], 0xf61eeb2b );
|
||||
BOOST_CHECK_EQUAL( digest[3], 0xdbad2731 );
|
||||
BOOST_CHECK_EQUAL( digest[4], 0x6534016f );
|
||||
BOOST_CHECK_EQUAL_COLLECTIONS(hash, hash+20, reference, reference+20);
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_SUITE_END()
|
||||
+44
-35
@@ -11,10 +11,10 @@
|
||||
* * 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
|
||||
*
|
||||
* 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;
|
||||
@@ -22,7 +22,7 @@
|
||||
* 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.
|
||||
*
|
||||
*
|
||||
*/
|
||||
//#define BOOST_TEST_DYN_LINK
|
||||
#define BOOST_TEST_MODULE uri
|
||||
@@ -36,19 +36,20 @@
|
||||
// Test a regular valid ws URI
|
||||
BOOST_AUTO_TEST_CASE( uri_valid ) {
|
||||
websocketpp::uri uri("ws://localhost:9000/chat");
|
||||
|
||||
|
||||
BOOST_CHECK( uri.get_valid() );
|
||||
BOOST_CHECK( !uri.get_secure() );
|
||||
BOOST_CHECK_EQUAL( uri.get_scheme(), "ws");
|
||||
BOOST_CHECK_EQUAL( uri.get_host(), "localhost");
|
||||
BOOST_CHECK_EQUAL( uri.get_port(), 9000 );
|
||||
BOOST_CHECK_EQUAL( uri.get_resource(), "/chat" );
|
||||
BOOST_CHECK_EQUAL( uri.get_query(), "" );
|
||||
}
|
||||
|
||||
// Test a regular valid ws URI
|
||||
BOOST_AUTO_TEST_CASE( uri_valid_no_port_unsecure ) {
|
||||
websocketpp::uri uri("ws://localhost/chat");
|
||||
|
||||
|
||||
BOOST_CHECK( uri.get_valid() );
|
||||
BOOST_CHECK( !uri.get_secure() );
|
||||
BOOST_CHECK_EQUAL( uri.get_scheme(), "ws");
|
||||
@@ -60,7 +61,7 @@ BOOST_AUTO_TEST_CASE( uri_valid_no_port_unsecure ) {
|
||||
// Valid URI with no port (secure)
|
||||
BOOST_AUTO_TEST_CASE( uri_valid_no_port_secure ) {
|
||||
websocketpp::uri uri("wss://localhost/chat");
|
||||
|
||||
|
||||
BOOST_CHECK( uri.get_valid() );
|
||||
BOOST_CHECK( uri.get_secure() );
|
||||
BOOST_CHECK_EQUAL( uri.get_scheme(), "wss");
|
||||
@@ -72,31 +73,31 @@ BOOST_AUTO_TEST_CASE( uri_valid_no_port_secure ) {
|
||||
// Valid URI with no resource
|
||||
BOOST_AUTO_TEST_CASE( uri_valid_no_resource ) {
|
||||
websocketpp::uri uri("wss://localhost:9000");
|
||||
|
||||
|
||||
BOOST_CHECK( uri.get_valid() );
|
||||
BOOST_CHECK( uri.get_secure() );
|
||||
BOOST_CHECK_EQUAL( uri.get_scheme(), "wss");
|
||||
BOOST_CHECK_EQUAL( uri.get_host(), "localhost");
|
||||
BOOST_CHECK_EQUAL( uri.get_port(), 9000 );
|
||||
BOOST_CHECK_EQUAL( uri.get_resource(), "/" );
|
||||
BOOST_CHECK_EQUAL( uri.get_resource(), "/" );
|
||||
}
|
||||
|
||||
// Valid URI IPv6 Literal
|
||||
BOOST_AUTO_TEST_CASE( uri_valid_ipv6_literal ) {
|
||||
websocketpp::uri uri("wss://[::1]:9000/chat");
|
||||
|
||||
|
||||
BOOST_CHECK( uri.get_valid() );
|
||||
BOOST_CHECK( uri.get_secure() );
|
||||
BOOST_CHECK_EQUAL( uri.get_scheme(), "wss");
|
||||
BOOST_CHECK_EQUAL( uri.get_host(), "::1");
|
||||
BOOST_CHECK_EQUAL( uri.get_port(), 9000 );
|
||||
BOOST_CHECK_EQUAL( uri.get_resource(), "/chat" );
|
||||
BOOST_CHECK_EQUAL( uri.get_resource(), "/chat" );
|
||||
}
|
||||
|
||||
// Valid URI with more complicated host
|
||||
BOOST_AUTO_TEST_CASE( uri_valid_2 ) {
|
||||
websocketpp::uri uri("wss://thor-websocket.zaphoyd.net:88/");
|
||||
|
||||
|
||||
BOOST_CHECK( uri.get_valid() );
|
||||
BOOST_CHECK( uri.get_secure() );
|
||||
BOOST_CHECK_EQUAL( uri.get_scheme(), "wss");
|
||||
@@ -108,14 +109,14 @@ BOOST_AUTO_TEST_CASE( uri_valid_2 ) {
|
||||
|
||||
// Invalid URI (port too long)
|
||||
BOOST_AUTO_TEST_CASE( uri_invalid_long_port ) {
|
||||
websocketpp::uri uri("wss://localhost:900000/chat");
|
||||
|
||||
websocketpp::uri uri("wss://localhost:900000/chat");
|
||||
|
||||
BOOST_CHECK( !uri.get_valid() );
|
||||
}
|
||||
|
||||
// Invalid URI (bogus scheme method)
|
||||
BOOST_AUTO_TEST_CASE( uri_invalid_scheme ) {
|
||||
websocketpp::uri uri("foo://localhost:9000/chat");
|
||||
websocketpp::uri uri("foo://localhost:9000/chat");
|
||||
|
||||
BOOST_CHECK( !uri.get_valid() );
|
||||
}
|
||||
@@ -123,70 +124,70 @@ BOOST_AUTO_TEST_CASE( uri_invalid_scheme ) {
|
||||
// Valid URI (http method)
|
||||
BOOST_AUTO_TEST_CASE( uri_http_scheme ) {
|
||||
websocketpp::uri uri("http://localhost:9000/chat");
|
||||
|
||||
|
||||
BOOST_CHECK( uri.get_valid() );
|
||||
BOOST_CHECK( !uri.get_secure() );
|
||||
BOOST_CHECK_EQUAL( uri.get_scheme(), "http");
|
||||
BOOST_CHECK_EQUAL( uri.get_host(), "localhost");
|
||||
BOOST_CHECK_EQUAL( uri.get_port(), 9000 );
|
||||
BOOST_CHECK_EQUAL( uri.get_resource(), "/chat" );
|
||||
BOOST_CHECK_EQUAL( uri.get_resource(), "/chat" );
|
||||
}
|
||||
|
||||
// Valid URI IPv4 literal
|
||||
BOOST_AUTO_TEST_CASE( uri_valid_ipv4_literal ) {
|
||||
websocketpp::uri uri("wss://127.0.0.1:9000/chat");
|
||||
|
||||
|
||||
BOOST_CHECK( uri.get_valid() );
|
||||
BOOST_CHECK( uri.get_secure() );
|
||||
BOOST_CHECK_EQUAL( uri.get_scheme(), "wss");
|
||||
BOOST_CHECK_EQUAL( uri.get_host(), "127.0.0.1");
|
||||
BOOST_CHECK_EQUAL( uri.get_port(), 9000 );
|
||||
BOOST_CHECK_EQUAL( uri.get_resource(), "/chat" );
|
||||
BOOST_CHECK_EQUAL( uri.get_resource(), "/chat" );
|
||||
}
|
||||
|
||||
// Valid URI complicated resource path
|
||||
BOOST_AUTO_TEST_CASE( uri_valid_3 ) {
|
||||
websocketpp::uri uri("wss://localhost:9000/chat/foo/bar");
|
||||
|
||||
|
||||
BOOST_CHECK( uri.get_valid() );
|
||||
BOOST_CHECK( uri.get_secure() );
|
||||
BOOST_CHECK_EQUAL( uri.get_scheme(), "wss");
|
||||
BOOST_CHECK_EQUAL( uri.get_host(), "localhost");
|
||||
BOOST_CHECK_EQUAL( uri.get_port(), 9000 );
|
||||
BOOST_CHECK_EQUAL( uri.get_resource(), "/chat/foo/bar" );
|
||||
BOOST_CHECK_EQUAL( uri.get_resource(), "/chat/foo/bar" );
|
||||
}
|
||||
|
||||
// Invalid URI broken method separator
|
||||
BOOST_AUTO_TEST_CASE( uri_invalid_method_separator ) {
|
||||
websocketpp::uri uri("wss:/localhost:9000/chat");
|
||||
websocketpp::uri uri("wss:/localhost:9000/chat");
|
||||
|
||||
BOOST_CHECK( !uri.get_valid() );
|
||||
}
|
||||
|
||||
// Invalid URI port > 65535
|
||||
BOOST_AUTO_TEST_CASE( uri_invalid_gt_16_bit_port ) {
|
||||
websocketpp::uri uri("wss:/localhost:70000/chat");
|
||||
websocketpp::uri uri("wss:/localhost:70000/chat");
|
||||
|
||||
BOOST_CHECK( !uri.get_valid() );
|
||||
}
|
||||
|
||||
// Invalid URI includes uri fragment
|
||||
BOOST_AUTO_TEST_CASE( uri_invalid_fragment ) {
|
||||
websocketpp::uri uri("wss:/localhost:70000/chat#foo");
|
||||
websocketpp::uri uri("wss:/localhost:70000/chat#foo");
|
||||
|
||||
BOOST_CHECK( !uri.get_valid() );
|
||||
}
|
||||
|
||||
// Invalid URI with no brackets around IPv6 literal
|
||||
BOOST_AUTO_TEST_CASE( uri_invalid_bad_v6_literal_1 ) {
|
||||
websocketpp::uri uri("wss://::1/chat");
|
||||
websocketpp::uri uri("wss://::1/chat");
|
||||
|
||||
BOOST_CHECK( !uri.get_valid() );
|
||||
}
|
||||
|
||||
// Invalid URI with port and no brackets around IPv6 literal
|
||||
// Invalid URI with port and no brackets around IPv6 literal
|
||||
BOOST_AUTO_TEST_CASE( uri_invalid_bad_v6_literal_2 ) {
|
||||
websocketpp::uri uri("wss://::1:2009/chat");
|
||||
websocketpp::uri uri("wss://::1:2009/chat");
|
||||
|
||||
BOOST_CHECK( !uri.get_valid() );
|
||||
}
|
||||
@@ -194,43 +195,51 @@ BOOST_AUTO_TEST_CASE( uri_invalid_bad_v6_literal_2 ) {
|
||||
// Valid URI complicated resource path with query
|
||||
BOOST_AUTO_TEST_CASE( uri_valid_4 ) {
|
||||
websocketpp::uri uri("wss://localhost:9000/chat/foo/bar?foo=bar");
|
||||
|
||||
|
||||
BOOST_CHECK( uri.get_valid() );
|
||||
BOOST_CHECK( uri.get_secure() );
|
||||
BOOST_CHECK_EQUAL( uri.get_scheme(), "wss" );
|
||||
BOOST_CHECK_EQUAL( uri.get_host(), "localhost");
|
||||
BOOST_CHECK_EQUAL( uri.get_port(), 9000 );
|
||||
BOOST_CHECK_EQUAL( uri.get_resource(), "/chat/foo/bar?foo=bar" );
|
||||
BOOST_CHECK_EQUAL( uri.get_resource(), "/chat/foo/bar?foo=bar" );
|
||||
BOOST_CHECK_EQUAL( uri.get_query(), "foo=bar" );
|
||||
}
|
||||
|
||||
// Valid URI with a mapped v4 ipv6 literal
|
||||
BOOST_AUTO_TEST_CASE( uri_valid_v4_mapped ) {
|
||||
websocketpp::uri uri("wss://[0000:0000:0000:0000:0000:0000:192.168.1.1]:9000/");
|
||||
|
||||
|
||||
BOOST_CHECK( uri.get_valid() );
|
||||
BOOST_CHECK( uri.get_secure() );
|
||||
BOOST_CHECK_EQUAL( uri.get_scheme(), "wss" );
|
||||
BOOST_CHECK_EQUAL( uri.get_host(), "0000:0000:0000:0000:0000:0000:192.168.1.1");
|
||||
BOOST_CHECK_EQUAL( uri.get_port(), 9000 );
|
||||
BOOST_CHECK_EQUAL( uri.get_resource(), "/" );
|
||||
BOOST_CHECK_EQUAL( uri.get_resource(), "/" );
|
||||
}
|
||||
|
||||
// Valid URI with a v6 address with mixed case
|
||||
BOOST_AUTO_TEST_CASE( uri_valid_v6_mixed_case ) {
|
||||
websocketpp::uri uri("wss://[::10aB]:9000/");
|
||||
|
||||
|
||||
BOOST_CHECK( uri.get_valid() == true );
|
||||
BOOST_CHECK( uri.get_secure() == true );
|
||||
BOOST_CHECK_EQUAL( uri.get_scheme(), "wss" );
|
||||
BOOST_CHECK_EQUAL( uri.get_host(), "::10aB");
|
||||
BOOST_CHECK_EQUAL( uri.get_port(), 9000 );
|
||||
BOOST_CHECK_EQUAL( uri.get_resource(), "/" );
|
||||
BOOST_CHECK_EQUAL( uri.get_resource(), "/" );
|
||||
}
|
||||
|
||||
// Valid URI with a v6 address with mixed case
|
||||
BOOST_AUTO_TEST_CASE( uri_invalid_no_scheme ) {
|
||||
websocketpp::uri uri("myserver.com");
|
||||
|
||||
BOOST_CHECK( !uri.get_valid() );
|
||||
}
|
||||
|
||||
// Invalid IPv6 literal
|
||||
/*BOOST_AUTO_TEST_CASE( uri_invalid_v6_nonhex ) {
|
||||
websocketpp::uri uri("wss://[g::1]:9000/");
|
||||
|
||||
|
||||
BOOST_CHECK( uri.get_valid() == false );
|
||||
}*/
|
||||
|
||||
|
||||
+10
-10
@@ -11,10 +11,10 @@
|
||||
* * 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
|
||||
*
|
||||
* 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;
|
||||
@@ -22,7 +22,7 @@
|
||||
* 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.
|
||||
*
|
||||
*
|
||||
*/
|
||||
//#define BOOST_TEST_DYN_LINK
|
||||
#define BOOST_TEST_MODULE utility
|
||||
@@ -38,34 +38,34 @@ BOOST_AUTO_TEST_SUITE ( utility )
|
||||
BOOST_AUTO_TEST_CASE( substr_found ) {
|
||||
std::string haystack = "abc123";
|
||||
std::string needle = "abc";
|
||||
|
||||
|
||||
BOOST_CHECK(websocketpp::utility::ci_find_substr(haystack,needle) ==haystack.begin());
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE( substr_found_ci ) {
|
||||
std::string haystack = "abc123";
|
||||
std::string needle = "aBc";
|
||||
|
||||
|
||||
BOOST_CHECK(websocketpp::utility::ci_find_substr(haystack,needle) ==haystack.begin());
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE( substr_not_found ) {
|
||||
std::string haystack = "abd123";
|
||||
std::string needle = "abcd";
|
||||
|
||||
|
||||
BOOST_CHECK(websocketpp::utility::ci_find_substr(haystack,needle) == haystack.end());
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE( to_lower ) {
|
||||
std::string in = "AbCd";
|
||||
|
||||
|
||||
BOOST_CHECK_EQUAL(websocketpp::utility::to_lower(in), "abcd");
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE( string_replace_all ) {
|
||||
std::string source = "foo \"bar\" baz";
|
||||
std::string dest = "foo \\\"bar\\\" baz";
|
||||
|
||||
|
||||
using websocketpp::utility::string_replace_all;
|
||||
BOOST_CHECK_EQUAL(string_replace_all(source,"\"","\\\""),dest);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,17 @@
|
||||
Broadcast Tutorial
|
||||
==================
|
||||
|
||||
This tutorial will dig into some more nitty gritty details on how to build high
|
||||
scalability, high performance websocket servers for broadcast like workflows.
|
||||
|
||||
Will go into features like:
|
||||
- minimizing work done in handlers
|
||||
- using asio thread pool mode
|
||||
- teaming multiple endpoints
|
||||
- setting accept queue depth
|
||||
- tuning compile time buffer sizes
|
||||
- prepared messages
|
||||
- flow control
|
||||
- basic operating system level tuning, particularly increasing file descriptor limits.
|
||||
- measuring performance with wsperf / autobahn
|
||||
- tuning permessage-deflate compression settings
|
||||
@@ -0,0 +1,13 @@
|
||||
Chat Tutorial
|
||||
=============
|
||||
|
||||
Goals of this tutorial:
|
||||
- Impliment a realtime websocket chat server
|
||||
|
||||
|
||||
Server
|
||||
- Nicknames
|
||||
- Channels
|
||||
- Subprotocol
|
||||
- Origin restrictions
|
||||
- HTTP statistics page
|
||||
@@ -0,0 +1,56 @@
|
||||
/*
|
||||
* 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:
|
||||
* * 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.
|
||||
*/
|
||||
|
||||
// **NOTE:** This file is a snapshot of the WebSocket++ utility client tutorial.
|
||||
// Additional related material can be found in the tutorials/utility_client
|
||||
// directory of the WebSocket++ repository.
|
||||
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
|
||||
int main() {
|
||||
bool done = false;
|
||||
std::string input;
|
||||
|
||||
while (!done) {
|
||||
std::cout << "Enter Command: ";
|
||||
std::getline(std::cin, input);
|
||||
|
||||
if (input == "quit") {
|
||||
done = true;
|
||||
} else if (input == "help") {
|
||||
std::cout
|
||||
<< "\nCommand List:\n"
|
||||
<< "help: Display this help text\n"
|
||||
<< "quit: Exit the program\n"
|
||||
<< std::endl;
|
||||
} else {
|
||||
std::cout << "Unrecognized Command" << std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,61 @@
|
||||
/*
|
||||
* 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:
|
||||
* * 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.
|
||||
*/
|
||||
|
||||
// **NOTE:** This file is a snapshot of the WebSocket++ utility client tutorial.
|
||||
// Additional related material can be found in the tutorials/utility_client
|
||||
// directory of the WebSocket++ repository.
|
||||
|
||||
#include <websocketpp/config/asio_no_tls_client.hpp>
|
||||
#include <websocketpp/client.hpp>
|
||||
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
|
||||
typedef websocketpp::client<websocketpp::config::asio_client> client;
|
||||
|
||||
int main() {
|
||||
bool done = false;
|
||||
std::string input;
|
||||
|
||||
while (!done) {
|
||||
std::cout << "Enter Command: ";
|
||||
std::getline(std::cin, input);
|
||||
|
||||
if (input == "quit") {
|
||||
done = true;
|
||||
} else if (input == "help") {
|
||||
std::cout
|
||||
<< "\nCommand List:\n"
|
||||
<< "help: Display this help text\n"
|
||||
<< "quit: Exit the program\n"
|
||||
<< std::endl;
|
||||
} else {
|
||||
std::cout << "Unrecognized Command" << std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,81 @@
|
||||
/*
|
||||
* 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:
|
||||
* * 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.
|
||||
*/
|
||||
|
||||
// **NOTE:** This file is a snapshot of the WebSocket++ utility client tutorial.
|
||||
// Additional related material can be found in the tutorials/utility_client
|
||||
// directory of the WebSocket++ repository.
|
||||
|
||||
#include <websocketpp/config/asio_no_tls_client.hpp>
|
||||
#include <websocketpp/client.hpp>
|
||||
|
||||
#include <websocketpp/common/thread.hpp>
|
||||
#include <websocketpp/common/memory.hpp>
|
||||
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
|
||||
typedef websocketpp::client<websocketpp::config::asio_client> client;
|
||||
|
||||
class websocket_endpoint {
|
||||
public:
|
||||
websocket_endpoint () {
|
||||
m_endpoint.clear_access_channels(websocketpp::log::alevel::all);
|
||||
m_endpoint.clear_error_channels(websocketpp::log::elevel::all);
|
||||
|
||||
m_endpoint.init_asio();
|
||||
m_endpoint.start_perpetual();
|
||||
|
||||
m_thread.reset(new websocketpp::lib::thread(&client::run, &m_endpoint));
|
||||
}
|
||||
private:
|
||||
client m_endpoint;
|
||||
websocketpp::lib::shared_ptr<websocketpp::lib::thread> m_thread;
|
||||
};
|
||||
|
||||
int main() {
|
||||
bool done = false;
|
||||
std::string input;
|
||||
websocket_endpoint endpoint;
|
||||
|
||||
while (!done) {
|
||||
std::cout << "Enter Command: ";
|
||||
std::getline(std::cin, input);
|
||||
|
||||
if (input == "quit") {
|
||||
done = true;
|
||||
} else if (input == "help") {
|
||||
std::cout
|
||||
<< "\nCommand List:\n"
|
||||
<< "help: Display this help text\n"
|
||||
<< "quit: Exit the program\n"
|
||||
<< std::endl;
|
||||
} else {
|
||||
std::cout << "Unrecognized Command" << std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,202 @@
|
||||
/*
|
||||
* 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:
|
||||
* * 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.
|
||||
*/
|
||||
|
||||
// **NOTE:** This file is a snapshot of the WebSocket++ utility client tutorial.
|
||||
// Additional related material can be found in the tutorials/utility_client
|
||||
// directory of the WebSocket++ repository.
|
||||
|
||||
#include <websocketpp/config/asio_no_tls_client.hpp>
|
||||
#include <websocketpp/client.hpp>
|
||||
|
||||
#include <websocketpp/common/thread.hpp>
|
||||
#include <websocketpp/common/memory.hpp>
|
||||
|
||||
#include <cstdlib>
|
||||
#include <iostream>
|
||||
#include <map>
|
||||
#include <string>
|
||||
#include <sstream>
|
||||
|
||||
typedef websocketpp::client<websocketpp::config::asio_client> client;
|
||||
|
||||
class connection_metadata {
|
||||
public:
|
||||
typedef websocketpp::lib::shared_ptr<connection_metadata> ptr;
|
||||
|
||||
connection_metadata(int id, websocketpp::connection_hdl hdl, std::string uri)
|
||||
: m_id(id)
|
||||
, m_hdl(hdl)
|
||||
, m_status("Connecting")
|
||||
, m_uri(uri)
|
||||
, m_server("N/A")
|
||||
{}
|
||||
|
||||
void on_open(client * c, websocketpp::connection_hdl hdl) {
|
||||
m_status = "Open";
|
||||
|
||||
client::connection_ptr con = c->get_con_from_hdl(hdl);
|
||||
m_server = con->get_response_header("Server");
|
||||
}
|
||||
|
||||
void on_fail(client * c, websocketpp::connection_hdl hdl) {
|
||||
m_status = "Failed";
|
||||
|
||||
client::connection_ptr con = c->get_con_from_hdl(hdl);
|
||||
m_server = con->get_response_header("Server");
|
||||
m_error_reason = con->get_ec().message();
|
||||
}
|
||||
|
||||
friend std::ostream & operator<< (std::ostream & out, connection_metadata const & data);
|
||||
private:
|
||||
int m_id;
|
||||
websocketpp::connection_hdl m_hdl;
|
||||
std::string m_status;
|
||||
std::string m_uri;
|
||||
std::string m_server;
|
||||
std::string m_error_reason;
|
||||
};
|
||||
|
||||
std::ostream & operator<< (std::ostream & out, connection_metadata const & data) {
|
||||
out << "> URI: " << data.m_uri << "\n"
|
||||
<< "> Status: " << data.m_status << "\n"
|
||||
<< "> Remote Server: " << (data.m_server.empty() ? "None Specified" : data.m_server) << "\n"
|
||||
<< "> Error/close reason: " << (data.m_error_reason.empty() ? "N/A" : data.m_error_reason);
|
||||
|
||||
return out;
|
||||
}
|
||||
|
||||
class websocket_endpoint {
|
||||
public:
|
||||
websocket_endpoint () : m_next_id(0) {
|
||||
m_endpoint.clear_access_channels(websocketpp::log::alevel::all);
|
||||
m_endpoint.clear_error_channels(websocketpp::log::elevel::all);
|
||||
|
||||
m_endpoint.init_asio();
|
||||
m_endpoint.start_perpetual();
|
||||
|
||||
m_thread.reset(new websocketpp::lib::thread(&client::run, &m_endpoint));
|
||||
}
|
||||
|
||||
int connect(std::string const & uri) {
|
||||
websocketpp::lib::error_code ec;
|
||||
|
||||
client::connection_ptr con = m_endpoint.get_connection(uri, ec);
|
||||
|
||||
if (ec) {
|
||||
std::cout << "> Connect initialization error: " << ec.message() << std::endl;
|
||||
return -1;
|
||||
}
|
||||
|
||||
int new_id = m_next_id++;
|
||||
connection_metadata::ptr metadata_ptr(new connection_metadata(new_id, con->get_handle(), uri));
|
||||
m_connection_list[new_id] = metadata_ptr;
|
||||
|
||||
con->set_open_handler(websocketpp::lib::bind(
|
||||
&connection_metadata::on_open,
|
||||
metadata_ptr,
|
||||
&m_endpoint,
|
||||
websocketpp::lib::placeholders::_1
|
||||
));
|
||||
con->set_fail_handler(websocketpp::lib::bind(
|
||||
&connection_metadata::on_fail,
|
||||
metadata_ptr,
|
||||
&m_endpoint,
|
||||
websocketpp::lib::placeholders::_1
|
||||
));
|
||||
|
||||
m_endpoint.connect(con);
|
||||
|
||||
return new_id;
|
||||
}
|
||||
|
||||
connection_metadata::ptr get_metadata(int id) const {
|
||||
con_list::const_iterator metadata_it = m_connection_list.find(id);
|
||||
if (metadata_it == m_connection_list.end()) {
|
||||
return connection_metadata::ptr();
|
||||
} else {
|
||||
return metadata_it->second;
|
||||
}
|
||||
}
|
||||
private:
|
||||
typedef std::map<int,connection_metadata::ptr> con_list;
|
||||
|
||||
client m_endpoint;
|
||||
websocketpp::lib::shared_ptr<websocketpp::lib::thread> m_thread;
|
||||
|
||||
con_list m_connection_list;
|
||||
int m_next_id;
|
||||
};
|
||||
|
||||
int main() {
|
||||
bool done = false;
|
||||
std::string input;
|
||||
websocket_endpoint endpoint;
|
||||
|
||||
while (!done) {
|
||||
std::cout << "Enter Command: ";
|
||||
std::getline(std::cin, input);
|
||||
|
||||
if (input == "quit") {
|
||||
done = true;
|
||||
} else if (input == "help") {
|
||||
std::cout
|
||||
<< "\nCommand List:\n"
|
||||
<< "connect <ws uri>\n"
|
||||
<< "show <connection id>\n"
|
||||
<< "help: Display this help text\n"
|
||||
<< "quit: Exit the program\n"
|
||||
<< std::endl;
|
||||
} else if (input.substr(0,7) == "connect") {
|
||||
int id = endpoint.connect(input.substr(8));
|
||||
if (id != -1) {
|
||||
std::cout << "> Created connection with id " << id << std::endl;
|
||||
}
|
||||
} else if (input.substr(0,4) == "show") {
|
||||
int id = atoi(input.substr(5).c_str());
|
||||
|
||||
connection_metadata::ptr metadata = endpoint.get_metadata(id);
|
||||
if (metadata) {
|
||||
std::cout << *metadata << std::endl;
|
||||
} else {
|
||||
std::cout << "> Unknown connection id " << id << std::endl;
|
||||
}
|
||||
} else {
|
||||
std::cout << "> Unrecognized Command" << std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
clang++ -std=c++11 -stdlib=libc++ -I/Users/zaphoyd/software/websocketpp/ -I/Users/zaphoyd/software/boost_1_55_0/ -D_WEBSOCKETPP_CPP11_STL_ step4.cpp /Users/zaphoyd/software/boost_1_55_0/stage/lib/libboost_system.a
|
||||
|
||||
clang++ -I/Users/zaphoyd/software/websocketpp/ -I/Users/zaphoyd/software/boost_1_55_0/ step4.cpp /Users/zaphoyd/software/boost_1_55_0/stage/lib/libboost_system.a /Users/zaphoyd/software/boost_1_55_0/stage/lib/libboost_thread.a /Users/zaphoyd/software/boost_1_55_0/stage/lib/libboost_random.a
|
||||
|
||||
clang++ -std=c++11 -stdlib=libc++ -I/Users/zaphoyd/Documents/websocketpp/ -I/Users/zaphoyd/Documents/boost_1_53_0_libcpp/ -D_WEBSOCKETPP_CPP11_STL_ step4.cpp /Users/zaphoyd/Documents/boost_1_53_0_libcpp/stage/lib/libboost_system.a
|
||||
|
||||
*/
|
||||
@@ -0,0 +1,280 @@
|
||||
/*
|
||||
* 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:
|
||||
* * 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.
|
||||
*/
|
||||
|
||||
// **NOTE:** This file is a snapshot of the WebSocket++ utility client tutorial.
|
||||
// Additional related material can be found in the tutorials/utility_client
|
||||
// directory of the WebSocket++ repository.
|
||||
|
||||
#include <websocketpp/config/asio_no_tls_client.hpp>
|
||||
#include <websocketpp/client.hpp>
|
||||
|
||||
#include <websocketpp/common/thread.hpp>
|
||||
#include <websocketpp/common/memory.hpp>
|
||||
|
||||
#include <cstdlib>
|
||||
#include <iostream>
|
||||
#include <map>
|
||||
#include <string>
|
||||
#include <sstream>
|
||||
|
||||
typedef websocketpp::client<websocketpp::config::asio_client> client;
|
||||
|
||||
class connection_metadata {
|
||||
public:
|
||||
typedef websocketpp::lib::shared_ptr<connection_metadata> ptr;
|
||||
|
||||
connection_metadata(int id, websocketpp::connection_hdl hdl, std::string uri)
|
||||
: m_id(id)
|
||||
, m_hdl(hdl)
|
||||
, m_status("Connecting")
|
||||
, m_uri(uri)
|
||||
, m_server("N/A")
|
||||
{}
|
||||
|
||||
void on_open(client * c, websocketpp::connection_hdl hdl) {
|
||||
m_status = "Open";
|
||||
|
||||
client::connection_ptr con = c->get_con_from_hdl(hdl);
|
||||
m_server = con->get_response_header("Server");
|
||||
}
|
||||
|
||||
void on_fail(client * c, websocketpp::connection_hdl hdl) {
|
||||
m_status = "Failed";
|
||||
|
||||
client::connection_ptr con = c->get_con_from_hdl(hdl);
|
||||
m_server = con->get_response_header("Server");
|
||||
m_error_reason = con->get_ec().message();
|
||||
}
|
||||
|
||||
void on_close(client * c, websocketpp::connection_hdl hdl) {
|
||||
m_status = "Closed";
|
||||
client::connection_ptr con = c->get_con_from_hdl(hdl);
|
||||
std::stringstream s;
|
||||
s << "close code: " << con->get_remote_close_code() << " ("
|
||||
<< websocketpp::close::status::get_string(con->get_remote_close_code())
|
||||
<< "), close reason: " << con->get_remote_close_reason();
|
||||
m_error_reason = s.str();
|
||||
}
|
||||
|
||||
websocketpp::connection_hdl get_hdl() const {
|
||||
return m_hdl;
|
||||
}
|
||||
|
||||
int get_id() const {
|
||||
return m_id;
|
||||
}
|
||||
|
||||
std::string get_status() const {
|
||||
return m_status;
|
||||
}
|
||||
|
||||
friend std::ostream & operator<< (std::ostream & out, connection_metadata const & data);
|
||||
private:
|
||||
int m_id;
|
||||
websocketpp::connection_hdl m_hdl;
|
||||
std::string m_status;
|
||||
std::string m_uri;
|
||||
std::string m_server;
|
||||
std::string m_error_reason;
|
||||
};
|
||||
|
||||
std::ostream & operator<< (std::ostream & out, connection_metadata const & data) {
|
||||
out << "> URI: " << data.m_uri << "\n"
|
||||
<< "> Status: " << data.m_status << "\n"
|
||||
<< "> Remote Server: " << (data.m_server.empty() ? "None Specified" : data.m_server) << "\n"
|
||||
<< "> Error/close reason: " << (data.m_error_reason.empty() ? "N/A" : data.m_error_reason);
|
||||
|
||||
return out;
|
||||
}
|
||||
|
||||
class websocket_endpoint {
|
||||
public:
|
||||
websocket_endpoint () : m_next_id(0) {
|
||||
m_endpoint.clear_access_channels(websocketpp::log::alevel::all);
|
||||
m_endpoint.clear_error_channels(websocketpp::log::elevel::all);
|
||||
|
||||
m_endpoint.init_asio();
|
||||
m_endpoint.start_perpetual();
|
||||
|
||||
m_thread.reset(new websocketpp::lib::thread(&client::run, &m_endpoint));
|
||||
}
|
||||
|
||||
~websocket_endpoint() {
|
||||
m_endpoint.stop_perpetual();
|
||||
|
||||
for (con_list::const_iterator it = m_connection_list.begin(); it != m_connection_list.end(); ++it) {
|
||||
if (it->second->get_status() != "Open") {
|
||||
// Only close open connections
|
||||
continue;
|
||||
}
|
||||
|
||||
std::cout << "> Closing connection " << it->second->get_id() << std::endl;
|
||||
|
||||
websocketpp::lib::error_code ec;
|
||||
m_endpoint.close(it->second->get_hdl(), websocketpp::close::status::going_away, "", ec);
|
||||
if (ec) {
|
||||
std::cout << "> Error closing connection " << it->second->get_id() << ": "
|
||||
<< ec.message() << std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
m_thread->join();
|
||||
}
|
||||
|
||||
int connect(std::string const & uri) {
|
||||
websocketpp::lib::error_code ec;
|
||||
|
||||
client::connection_ptr con = m_endpoint.get_connection(uri, ec);
|
||||
|
||||
if (ec) {
|
||||
std::cout << "> Connect initialization error: " << ec.message() << std::endl;
|
||||
return -1;
|
||||
}
|
||||
|
||||
int new_id = m_next_id++;
|
||||
connection_metadata::ptr metadata_ptr(new connection_metadata(new_id, con->get_handle(), uri));
|
||||
m_connection_list[new_id] = metadata_ptr;
|
||||
|
||||
con->set_open_handler(websocketpp::lib::bind(
|
||||
&connection_metadata::on_open,
|
||||
metadata_ptr,
|
||||
&m_endpoint,
|
||||
websocketpp::lib::placeholders::_1
|
||||
));
|
||||
con->set_fail_handler(websocketpp::lib::bind(
|
||||
&connection_metadata::on_fail,
|
||||
metadata_ptr,
|
||||
&m_endpoint,
|
||||
websocketpp::lib::placeholders::_1
|
||||
));
|
||||
con->set_close_handler(websocketpp::lib::bind(
|
||||
&connection_metadata::on_close,
|
||||
metadata_ptr,
|
||||
&m_endpoint,
|
||||
websocketpp::lib::placeholders::_1
|
||||
));
|
||||
|
||||
m_endpoint.connect(con);
|
||||
|
||||
return new_id;
|
||||
}
|
||||
|
||||
void close(int id, websocketpp::close::status::value code, std::string reason) {
|
||||
websocketpp::lib::error_code ec;
|
||||
|
||||
con_list::iterator metadata_it = m_connection_list.find(id);
|
||||
if (metadata_it == m_connection_list.end()) {
|
||||
std::cout << "> No connection found with id " << id << std::endl;
|
||||
return;
|
||||
}
|
||||
|
||||
m_endpoint.close(metadata_it->second->get_hdl(), code, reason, ec);
|
||||
if (ec) {
|
||||
std::cout << "> Error initiating close: " << ec.message() << std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
connection_metadata::ptr get_metadata(int id) const {
|
||||
con_list::const_iterator metadata_it = m_connection_list.find(id);
|
||||
if (metadata_it == m_connection_list.end()) {
|
||||
return connection_metadata::ptr();
|
||||
} else {
|
||||
return metadata_it->second;
|
||||
}
|
||||
}
|
||||
private:
|
||||
typedef std::map<int,connection_metadata::ptr> con_list;
|
||||
|
||||
client m_endpoint;
|
||||
websocketpp::lib::shared_ptr<websocketpp::lib::thread> m_thread;
|
||||
|
||||
con_list m_connection_list;
|
||||
int m_next_id;
|
||||
};
|
||||
|
||||
int main() {
|
||||
bool done = false;
|
||||
std::string input;
|
||||
websocket_endpoint endpoint;
|
||||
|
||||
while (!done) {
|
||||
std::cout << "Enter Command: ";
|
||||
std::getline(std::cin, input);
|
||||
|
||||
if (input == "quit") {
|
||||
done = true;
|
||||
} else if (input == "help") {
|
||||
std::cout
|
||||
<< "\nCommand List:\n"
|
||||
<< "connect <ws uri>\n"
|
||||
<< "close <connection id> [<close code:default=1000>] [<close reason>]\n"
|
||||
<< "show <connection id>\n"
|
||||
<< "help: Display this help text\n"
|
||||
<< "quit: Exit the program\n"
|
||||
<< std::endl;
|
||||
} else if (input.substr(0,7) == "connect") {
|
||||
int id = endpoint.connect(input.substr(8));
|
||||
if (id != -1) {
|
||||
std::cout << "> Created connection with id " << id << std::endl;
|
||||
}
|
||||
} else if (input.substr(0,5) == "close") {
|
||||
std::stringstream ss(input);
|
||||
|
||||
std::string cmd;
|
||||
int id;
|
||||
int close_code = websocketpp::close::status::normal;
|
||||
std::string reason = "";
|
||||
|
||||
ss >> cmd >> id >> close_code;
|
||||
std::getline(ss,reason);
|
||||
|
||||
endpoint.close(id, close_code, reason);
|
||||
} else if (input.substr(0,4) == "show") {
|
||||
int id = atoi(input.substr(5).c_str());
|
||||
|
||||
connection_metadata::ptr metadata = endpoint.get_metadata(id);
|
||||
if (metadata) {
|
||||
std::cout << *metadata << std::endl;
|
||||
} else {
|
||||
std::cout << "> Unknown connection id " << id << std::endl;
|
||||
}
|
||||
} else {
|
||||
std::cout << "> Unrecognized Command" << std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
clang++ -std=c++11 -stdlib=libc++ -I/Users/zaphoyd/software/websocketpp/ -I/Users/zaphoyd/software/boost_1_55_0/ -D_WEBSOCKETPP_CPP11_STL_ step4.cpp /Users/zaphoyd/software/boost_1_55_0/stage/lib/libboost_system.a
|
||||
|
||||
clang++ -I/Users/zaphoyd/software/websocketpp/ -I/Users/zaphoyd/software/boost_1_55_0/ step4.cpp /Users/zaphoyd/software/boost_1_55_0/stage/lib/libboost_system.a /Users/zaphoyd/software/boost_1_55_0/stage/lib/libboost_thread.a /Users/zaphoyd/software/boost_1_55_0/stage/lib/libboost_random.a
|
||||
|
||||
clang++ -std=c++11 -stdlib=libc++ -I/Users/zaphoyd/Documents/websocketpp/ -I/Users/zaphoyd/Documents/boost_1_53_0_libcpp/ -D_WEBSOCKETPP_CPP11_STL_ step4.cpp /Users/zaphoyd/Documents/boost_1_53_0_libcpp/stage/lib/libboost_system.a
|
||||
|
||||
*/
|
||||
@@ -0,0 +1,719 @@
|
||||
Utility Client Example Application
|
||||
==================================
|
||||
|
||||
Chapter 1: Initial Setup & Basics
|
||||
---------------------------------
|
||||
|
||||
Setting up the basic types, opening and closing connections, sending and receiving messages.
|
||||
|
||||
### Step 1
|
||||
|
||||
A basic program loop that prompts the user for a command and then processes it. In this tutorial we will modify this program to perform tasks and retrieve data from a remote server over a WebSocket connection.
|
||||
|
||||
#### Build
|
||||
`clang++ step1.cpp`
|
||||
|
||||
#### Code so far
|
||||
|
||||
*note* A code snapshot for each step is present next to this tutorial file in the git repository.
|
||||
|
||||
```cpp
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
|
||||
int main() {
|
||||
bool done = false;
|
||||
std::string input;
|
||||
|
||||
while (!done) {
|
||||
std::cout << "Enter Command: ";
|
||||
std::getline(std::cin, input);
|
||||
|
||||
if (input == "quit") {
|
||||
done = true;
|
||||
} else if (input == "help") {
|
||||
std::cout
|
||||
<< "\nCommand List:\n"
|
||||
<< "help: Display this help text\n"
|
||||
<< "quit: Exit the program\n"
|
||||
<< std::endl;
|
||||
} else {
|
||||
std::cout << "Unrecognized Command" << std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
```
|
||||
|
||||
### Step 2
|
||||
|
||||
_Add WebSocket++ includes and set up an endpoint type._
|
||||
|
||||
WebSocket++ includes two major object types. The endpoint and the connection. The
|
||||
endpoint creates and launches new connections and maintains default settings for
|
||||
those connections. Endpoints also manage any shared network resources.
|
||||
|
||||
The connection stores information specific to each WebSocket session.
|
||||
|
||||
> **Note:** Once a connection is launched, there is no link between the endpoint and the connection. All default settings are copied into the new connection by the endpoint. Changing default settings on an endpoint will only affect future connections.
|
||||
Connections do not maintain a link back to their associated endpoint. Endpoints do not maintain a list of outstanding connections. If your application needs to iterate over all connections it will need to maintain a list of them itself.
|
||||
|
||||
WebSocket++ endpoints are built by combining an endpoint role with an endpoint config. There are two different types of endpoint roles, one each for the client and server roles in a WebSocket session. This is a client tutorial so we will use the client role `websocketpp::client` which is provided by the `<websocketpp/client.hpp>` header.
|
||||
|
||||
> ###### Terminology: Endpoint Config
|
||||
> WebSocket++ endpoints have a group of settings that may be configured at compile time via the `config` template parameter. A config is a struct that contains types and static constants that are used to produce an endpoint with specific properties. Depending on which config is being used the endpoint will have different methods available and may have additional third party dependencies.
|
||||
|
||||
The endpoint role takes a template parameter called `config` that is used to configure the behavior of endpoint at compile time. For this example we are going to use a default config provided by the library called `asio_client`, provided by `<websocketpp/config/asio_no_tls_client.hpp>`. This is a client config that uses boost::asio to provide network transport and does not support TLS based security. Later on we will discuss how to introduce TLS based security into a WebSocket++ application, more about the other stock configs, and how to build your own custom configs.
|
||||
|
||||
Combine a config with an endpoint role to produce a fully configured endpoint. This type will be used frequently so I would recommend a typedef here.
|
||||
|
||||
`typedef websocketpp::client<websocketpp::config::asio_client> client`
|
||||
|
||||
#### Build
|
||||
Adding WebSocket++ has added a few dependencies to our program that must be addressed in the build system. Firstly, the WebSocket++ and Boost library headers must be in the include search path of your build system. How exactly this is done depends on where you have the WebSocket++ headers installed and what build system you are using.
|
||||
|
||||
In addition to the new headers, boost::asio depends on the `boost_system` shared library. This will need to be added (either as a static or dynamic) to the linker. Refer to your build environment documentation for instructions on linking to shared libraries.
|
||||
|
||||
`clang++ step2.cpp -lboost_system`
|
||||
|
||||
#### Code so far
|
||||
```cpp
|
||||
#include <websocketpp/config/asio_no_tls_client.hpp>
|
||||
#include <websocketpp/client.hpp>
|
||||
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
|
||||
typedef websocketpp::client<websocketpp::config::asio_client> client;
|
||||
|
||||
int main() {
|
||||
bool done = false;
|
||||
std::string input;
|
||||
|
||||
while (!done) {
|
||||
std::cout << "Enter Command: ";
|
||||
std::getline(std::cin, input);
|
||||
|
||||
if (input == "quit") {
|
||||
done = true;
|
||||
} else if (input == "help") {
|
||||
std::cout
|
||||
<< "\nCommand List:\n"
|
||||
<< "help: Display this help text\n"
|
||||
<< "quit: Exit the program\n"
|
||||
<< std::endl;
|
||||
} else {
|
||||
std::cout << "Unrecognized Command" << std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
```
|
||||
|
||||
### Step 3
|
||||
|
||||
_Create endpoint wrapper object that handles initialization and setting up the background thread._
|
||||
|
||||
In order to process user input while network processing occurs in the background we are going to use a separate thread for the WebSocket++ processing loop. This leaves the main thread free to process foreground user input. In order to enable simple RAII style resource management for our thread and endpoint we will use a wrapper object that configures them both in its constructor.
|
||||
|
||||
> ###### Terminology: websocketpp::lib namespace
|
||||
> WebSocket++ is designed to be used with a C++11 standard library. As this is not universally available in popular build systems the Boost libraries may be used as polyfills for the C++11 standard library in C++98 build environments. The `websocketpp::lib` namespace is used by the library and its associated examples to abstract away the distinctions between the two. `websocketpp::lib::shared_ptr` will evaluate to `std::shared_ptr` in a C++11 environment and `boost::shared_ptr` otherwise.
|
||||
>
|
||||
> This tutorial uses the `websocketpp::lib` wrappers because it doesn't know what the build environment of the reader is. For your applications, unless you are interested in similar portability, are free to use the boost or std versions of these types directly.
|
||||
>
|
||||
>[TODO: link to more information about websocketpp::lib namespace and C++11 setup]
|
||||
|
||||
Within the `websocket_endpoint` constructor several things happen:
|
||||
|
||||
First, we set the endpoint logging behavior to silent by clearing all of the access and error logging channels. [TODO: link to more information about logging]
|
||||
```cpp
|
||||
m_endpoint.clear_access_channels(websocketpp::log::alevel::all);
|
||||
m_endpoint.clear_error_channels(websocketpp::log::elevel::all);
|
||||
```
|
||||
|
||||
Next, we initialize the transport system underlying the endpoint and set it to perpetual mode. In perpetual mode the endpoint's processing loop will not exit automatically when it has no connections. This is important because we want this endpoint to remain active while our application is running and process requests for new WebSocket connections on demand as we need them. Both of these methods are specific to the asio transport. They will not be necessary or present in endpoints that use a non-asio config.
|
||||
```cpp
|
||||
m_endpoint.init_asio();
|
||||
m_endpoint.start_perpetual();
|
||||
```
|
||||
|
||||
Finally, we launch a thread to run the `run` method of our client endpoint. While the endpoint is running it will process connection tasks (read and deliver incoming messages, frame and send outgoing messages, etc). Because it is running in perpetual mode, when there are no connections active it will wait for a new connection.
|
||||
```cpp
|
||||
m_thread.reset(new websocketpp::lib::thread(&client::run, &m_endpoint));
|
||||
```
|
||||
|
||||
#### Build
|
||||
|
||||
Now that our client endpoint template is actually instantiated a few more linker dependencies will show up. In particular, WebSocket clients require a cryptographically secure random number generator. WebSocket++ is able to use either `boost_random` or the C++11 standard library <random> for this purpose. Because this example also uses threads, if we do not have C++11 std::thread available we will need to include `boost_thread`.
|
||||
|
||||
##### Clang (C++98 & boost)
|
||||
`clang++ step3.cpp -lboost_system -lboost_random -lboost_thread`
|
||||
|
||||
##### Clang (C++11)
|
||||
`clang++ -std=c++0x -stdlib=libc++ step3.cpp -lboost_system -D_WEBSOCKETPP_CPP11_STL_`
|
||||
|
||||
##### G++ (C++98 & Boost)
|
||||
`g++ step3.cpp -lboost_system -lboost_random -lboost_thread`
|
||||
|
||||
##### G++ v4.6+ (C++11)
|
||||
`g++ -std=c++0x step3.cpp -lboost_system -D_WEBSOCKETPP_CPP11_STL_`
|
||||
|
||||
#### Code so far
|
||||
|
||||
```cpp
|
||||
#include <websocketpp/config/asio_no_tls_client.hpp>
|
||||
#include <websocketpp/client.hpp>
|
||||
|
||||
#include <websocketpp/common/thread.hpp>
|
||||
#include <websocketpp/common/memory.hpp>
|
||||
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
|
||||
typedef websocketpp::client<websocketpp::config::asio_client> client;
|
||||
|
||||
class websocket_endpoint {
|
||||
public:
|
||||
websocket_endpoint () {
|
||||
m_endpoint.clear_access_channels(websocketpp::log::alevel::all);
|
||||
m_endpoint.clear_error_channels(websocketpp::log::elevel::all);
|
||||
|
||||
m_endpoint.init_asio();
|
||||
m_endpoint.start_perpetual();
|
||||
|
||||
m_thread.reset(new websocketpp::lib::thread(&client::run, &m_endpoint));
|
||||
}
|
||||
private:
|
||||
client m_endpoint;
|
||||
websocketpp::lib::shared_ptr<websocketpp::lib::thread> m_thread;
|
||||
};
|
||||
|
||||
int main() {
|
||||
bool done = false;
|
||||
std::string input;
|
||||
websocket_endpoint endpoint;
|
||||
|
||||
while (!done) {
|
||||
std::cout << "Enter Command: ";
|
||||
std::getline(std::cin, input);
|
||||
|
||||
if (input == "quit") {
|
||||
done = true;
|
||||
} else if (input == "help") {
|
||||
std::cout
|
||||
<< "\nCommand List:\n"
|
||||
<< "help: Display this help text\n"
|
||||
<< "quit: Exit the program\n"
|
||||
<< std::endl;
|
||||
} else {
|
||||
std::cout << "Unrecognized Command" << std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
```
|
||||
|
||||
### Step 4
|
||||
|
||||
_Opening WebSocket connections_
|
||||
|
||||
This step adds two new commands to app_client. The ability to open a new connection and the ability to view information about a previously opened connection. Every connection that gets opened will be assigned an integer connection id that the user of the program can use to interact with that connection.
|
||||
|
||||
#### New Connection Metadata Object
|
||||
|
||||
In order to track information about each connection a `connection_metadata` object is defined. This object stores the numeric connection id and a number of fields that will be filled in as the connection is processed. Initially this includes the state of the connection (opening, open, failed, closed, etc), the original URI connected to, an identifying value from the server, and a description of the reason for connection failure/closure. Future steps will add more information to this metadata object.
|
||||
|
||||
#### Update `websocket_endpoint`
|
||||
|
||||
The `websocket_endpoint` object has gained some new data members and methods. It now tracks a mapping between connection IDs and their associated metadata as well as the next sequential ID number to hand out. The `connect()` method initiates a new connection. The `get_metadata` method retrieves metadata given an ID.
|
||||
|
||||
#### The connect method
|
||||
A new WebSocket connection is initiated via a three step process. First, a connection request is created by `endpoint::get_connection(uri)`. Next, the connection request is configured. Lastly, the connection request is submitted back to the endpoint via `endpoint::connect()` which adds it to the queue of new connections to make.
|
||||
|
||||
> ###### Terminology `connection_ptr`
|
||||
> WebSocket++ keeps track of connection related resources using a reference counted shared pointer. The type of this pointer is `endpoint::connection_ptr`. A `connection_ptr` allows direct access to information about the connection and allows changing connection settings. Because of this direct access and their internal resource management role within the library it is not safe to for end applications to use `connection_ptr` except in the specific circumstances detailed below.
|
||||
>
|
||||
> **When is it safe to use `connection_ptr`?**
|
||||
> - After `endpoint::get_connection(...)` and before `endpoint::connect()`: `get_connection` returns a `connection_ptr`. It is safe to use this pointer to configure your new connection. Once you submit the connection to `connect` you may no longer use the `connection_ptr` and should discard it immediately for optimal memory management.
|
||||
> - During a handler: WebSocket++ allows you to register hooks / callbacks / event handlers for specific events that happen during a connection's lifetime. During the invocation of one of these handlers the library guarantees that it is safe to use a `connection_ptr` for the connection associated with the currently running handler.
|
||||
|
||||
> ###### Terminology `connection_hdl`
|
||||
> Because of the limited thread safety of the `connection_ptr` the library also provides a more flexible connection identifier, the `connection_hdl`. The `connection_hdl` has type `websocketpp::connection_hdl` and it is defined in `<websocketpp/common/connection_hdl.hpp>`. Note that unlike `connection_ptr` this is not dependent on the type or config of the endpoint. Code that simply stores or transmits `connection_hdl` but does not use them can include only the header above and can treat its hdls like values.
|
||||
>
|
||||
> Connection handles are not used directly. They are used by endpoint methods to identify the target of the desired action. For example, the endpoint method that sends a new message will take as a parameter the hdl of the connection to send the message to.
|
||||
>
|
||||
> **When is it safe to use `connection_hdl`?**
|
||||
> `connection_hdl`s may be used at any time from any thread. They may be copied and stored in containers. Deleting a hdl will not affect the connection in any way. Handles may be upgraded to a `connection_ptr` during a handler call by using `endpoint::get_con_from_hdl()`. The resulting `connection_ptr` is safe to use for the duration of that handler invocation.
|
||||
>
|
||||
> **`connection_hdl` FAQs**
|
||||
> - `connection_hdl`s are guaranteed to be unique within a program. Multiple endpoints in a single program will always create connections with unique handles.
|
||||
> - Using a `connection_hdl` with a different endpoint than the one that created its associated connection will result in undefined behavior.
|
||||
> - Using a `connection_hdl` whose associated connection has been closed or deleted is safe. The endpoint will return a specific error saying the operation couldn't be completed because the associated connection doesn't exist.
|
||||
> [TODO: more here? link to a connection_hdl FAQ elsewhere?]
|
||||
|
||||
`websocket_endpoint::connect()` begins by calling `endpoint::get_connection()` using a uri passed as a parameter. Additionally, an error output value is passed to capture any errors that might occur during. If an error does occur an error notice is printed along with a descriptive message and the -1 / 'invalid' value is returned as the new ID.
|
||||
|
||||
> ###### Terminology: `error handling: exceptions vs error_code`
|
||||
> WebSocket++ uses the error code system defined by the C++11 `<system_error>` library. It can optionally fall back to a similar system provided by the Boost libraries. All user facing endpoint methods that can fail take an `error_code` in an output parameter and store the error that occured there before returning. An empty/default constructed value is returned in the case of success.
|
||||
>
|
||||
> **Exception throwing varients**
|
||||
> All user facing endpoint methods that take and use an `error_code` parameter have a version that throws an exception instead. These methods are identical in function and signature except for the lack of the final ec parameter. The type of the exception thrown is `websocketpp::exception`. This type derives from `std::exception` so it can be caught by catch blocks grabbing generic `std::exception`s. The `websocketpp::exception::code()` method may be used to extract the machine readable `error_code` value from an exception.
|
||||
>
|
||||
> For clarity about error handling the app_client example uses exclusively the exception free varients of these methods. Your application may choose to use either.
|
||||
|
||||
If connection creation succeeds, the next sequential connection ID is generated and a `connection_metadata` object is inserted into the connection list under that ID. Initially the metadata object stores the connection ID, the `connection_hdl`, and the URI the connection was opened to.
|
||||
|
||||
```cpp
|
||||
int new_id = m_next_id++;
|
||||
metadata_ptr metadata(new connection_metadata(new_id, con->get_handle(), uri));
|
||||
m_connection_list[new_id] = metadata;
|
||||
```
|
||||
|
||||
Next, the connection request is configured. For this step the only configuration we will do is setting up a few default handlers. Later on we will return and demonstrate some more detailed configuration that can happen here (setting user agents, origin, proxies, custom headers, subprotocols, etc).
|
||||
|
||||
> ###### Terminology: Registering handlers
|
||||
> WebSocket++ provides a number of execution points where you can register to have a handler run. Which of these points are available to your endpoint will depend on its config. TLS handlers will not exist on non-TLS endpoints for example. A complete list of handlers can be found at http://www.zaphoyd.com/websocketpp/manual/reference/handler-list.
|
||||
>
|
||||
> Handlers can be registered at the endpoint level and at the connection level. Endpoint handlers are copied into new connections as they are created. Changing an endpoint handler will affect only future connections. Handlers registered at the connection level will be bound to that specific connection only.
|
||||
>
|
||||
> The signature of handler binding methods is the same for endpoints and connections. The format is: `set_*_handler(...)`. Where * is the name of the handler. For example, `set_open_handler(...)` will set the handler to be called when a new connection is open. `set_fail_handler(...)` will set the handler to be called when a connection fails to connect.
|
||||
>
|
||||
> All handlers take one argument, a callable type that can be converted to a `std::function` with the correct count and type of arguments. You can pass free functions, functors, and Lambdas with matching argument lists as handlers. In addition, you can use `std::bind` (or `boost::bind`) to register functions with non-matching argument lists. This is useful for passing additional parameters not present in the handler signature or member functions that need to carry a 'this' pointer.
|
||||
>
|
||||
> The function signature of each handler can be looked up in the list above in the manual. In general, all handlers include the `connection_hdl` identifying which connection this even is associated with as the first parameter. Some handlers (such as the message handler) include additional parameters. Most handlers have a void return value but some (`validate`, `ping`, `tls_init`) do not. The specific meanings of the return values are documented in the handler list linked above.
|
||||
|
||||
`app_client` registers an open and a fail handler. We will use these to track whether each connection was successfully opened or failed. If it successfully opens, we will gather some information from the opening handshake and store it with our connection metadata.
|
||||
|
||||
In this example we are going to set connection specific handlers that are bound directly to the metadata object associated with our connection. This allows us to avoid performing a lookup in each handler to find the metadata object we plan to update which is a bit more efficient.
|
||||
|
||||
Lets look at the parameters being sent to bind in detail:
|
||||
|
||||
```cpp
|
||||
con->set_open_handler(websocketpp::lib::bind(
|
||||
&connection_metadata::on_open,
|
||||
metadata,
|
||||
&m_endpoint,
|
||||
websocketpp::lib::placeholders::_1
|
||||
));
|
||||
```
|
||||
|
||||
`&connection_metadata::on_open` is the address of the `on_open` member function of the `connection_metadata` class. `metadata_ptr` is a pointer to the `connection_metadata` object associated with this class. It will be used as the object on which the `on_open` member function will be called. `&m_endpoint` is the address of the endpoint in use. This parameter will be passed as-is to the `on_open` method. Lastly, `websocketpp::lib::placeholders::_1` is a placeholder indicating that the bound function should take one additional argument to be filled in at a later time. WebSocket++ will fill in this placeholder with the `connection_hdl` when it invokes the handler.
|
||||
|
||||
Finally, we call `endpoint::connect()` on our configured connection request and return the new connection ID.
|
||||
|
||||
#### Handler Member Functions
|
||||
|
||||
The open handler we registered, `connection_metadata::on_open`, sets the status metadata field to "Open" and retrieves the value of the "Server" header from the remote endpoint's HTTP response and stores it in the metadata object. Servers often set an identifying string in this header.
|
||||
|
||||
The fail handler we registered, `connection_metadata::on_fail`, sets the status metadata field to "Failed", the server field similarly to `on_open`, and retrieves the error code describing why the connection failed. The human readable message associated with that error code is saved to the metadata object.
|
||||
|
||||
#### New Commands
|
||||
|
||||
Two new commands have been set up. "connect [uri]" will pass the URI to the `websocket_endpoint` connect method and report an error or the connection ID of the new connection. "show [connection id]" will retrieve and print out the metadata associated with that connection. The help text has been updated accordingly.
|
||||
|
||||
```cpp
|
||||
} else if (input.substr(0,7) == "connect") {
|
||||
int id = endpoint.connect(input.substr(8));
|
||||
if (id != -1) {
|
||||
std::cout << "> Created connection with id " << id << std::endl;
|
||||
}
|
||||
} else if (input.substr(0,4) == "show") {
|
||||
int id = atoi(input.substr(5).c_str());
|
||||
|
||||
connection_metadata::ptr metadata = endpoint.get_metadata(id);
|
||||
if (metadata) {
|
||||
std::cout << *metadata << std::endl;
|
||||
} else {
|
||||
std::cout << "> Unknown connection id " << id << std::endl;
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
#### Build
|
||||
|
||||
There are no changes to the build instructions from step 3
|
||||
|
||||
#### Run
|
||||
|
||||
```
|
||||
Enter Command: connect not a websocket uri
|
||||
> Connect initialization error: invalid uri
|
||||
Enter Command: show 0
|
||||
> Unknown connection id 0
|
||||
Enter Command: connect ws://echo.websocket.org
|
||||
> Created connection with id 0
|
||||
Enter Command: show 0
|
||||
> URI: ws://echo.websocket.org
|
||||
> Status: Open
|
||||
> Remote Server: Kaazing Gateway
|
||||
> Error/close reason: N/A
|
||||
Enter Command: connect ws://wikipedia.org
|
||||
> Created connection with id 1
|
||||
Enter Command: show 1
|
||||
> URI: ws://wikipedia.org
|
||||
> Status: Failed
|
||||
> Remote Server: Apache
|
||||
> Error/close reason: Invalid HTTP status.
|
||||
```
|
||||
|
||||
#### Code so far
|
||||
|
||||
```cpp
|
||||
#include <websocketpp/config/asio_no_tls_client.hpp>
|
||||
#include <websocketpp/client.hpp>
|
||||
|
||||
#include <websocketpp/common/thread.hpp>
|
||||
#include <websocketpp/common/memory.hpp>
|
||||
|
||||
#include <cstdlib>
|
||||
#include <iostream>
|
||||
#include <map>
|
||||
#include <string>
|
||||
#include <sstream>
|
||||
|
||||
typedef websocketpp::client<websocketpp::config::asio_client> client;
|
||||
|
||||
class connection_metadata {
|
||||
public:
|
||||
typedef websocketpp::lib::shared_ptr<connection_metadata> ptr;
|
||||
|
||||
connection_metadata(int id, websocketpp::connection_hdl hdl, std::string uri)
|
||||
: m_id(id)
|
||||
, m_hdl(hdl)
|
||||
, m_status("Connecting")
|
||||
, m_uri(uri)
|
||||
, m_server("N/A")
|
||||
{}
|
||||
|
||||
void on_open(client * c, websocketpp::connection_hdl hdl) {
|
||||
m_status = "Open";
|
||||
|
||||
client::connection_ptr con = c->get_con_from_hdl(hdl);
|
||||
m_server = con->get_response_header("Server");
|
||||
}
|
||||
|
||||
void on_fail(client * c, websocketpp::connection_hdl hdl) {
|
||||
m_status = "Failed";
|
||||
|
||||
client::connection_ptr con = c->get_con_from_hdl(hdl);
|
||||
m_server = con->get_response_header("Server");
|
||||
m_error_reason = con->get_ec().message();
|
||||
}
|
||||
|
||||
friend std::ostream & operator<< (std::ostream & out, connection_metadata const & data);
|
||||
private:
|
||||
int m_id;
|
||||
websocketpp::connection_hdl m_hdl;
|
||||
std::string m_status;
|
||||
std::string m_uri;
|
||||
std::string m_server;
|
||||
std::string m_error_reason;
|
||||
};
|
||||
|
||||
std::ostream & operator<< (std::ostream & out, connection_metadata const & data) {
|
||||
out << "> URI: " << data.m_uri << "\n"
|
||||
<< "> Status: " << data.m_status << "\n"
|
||||
<< "> Remote Server: " << (data.m_server.empty() ? "None Specified" : data.m_server) << "\n"
|
||||
<< "> Error/close reason: " << (data.m_error_reason.empty() ? "N/A" : data.m_error_reason);
|
||||
|
||||
return out;
|
||||
}
|
||||
|
||||
class websocket_endpoint {
|
||||
public:
|
||||
websocket_endpoint () : m_next_id(0) {
|
||||
m_endpoint.clear_access_channels(websocketpp::log::alevel::all);
|
||||
m_endpoint.clear_error_channels(websocketpp::log::elevel::all);
|
||||
|
||||
m_endpoint.init_asio();
|
||||
m_endpoint.start_perpetual();
|
||||
|
||||
m_thread.reset(new websocketpp::lib::thread(&client::run, &m_endpoint));
|
||||
}
|
||||
|
||||
int connect(std::string const & uri) {
|
||||
websocketpp::lib::error_code ec;
|
||||
|
||||
client::connection_ptr con = m_endpoint.get_connection(uri, ec);
|
||||
|
||||
if (ec) {
|
||||
std::cout << "> Connect initialization error: " << ec.message() << std::endl;
|
||||
return -1;
|
||||
}
|
||||
|
||||
int new_id = m_next_id++;
|
||||
connection_metadata::ptr metadata_ptr(new connection_metadata(new_id, con->get_handle(), uri));
|
||||
m_connection_list[new_id] = metadata_ptr;
|
||||
|
||||
con->set_open_handler(websocketpp::lib::bind(
|
||||
&connection_metadata::on_open,
|
||||
metadata_ptr,
|
||||
&m_endpoint,
|
||||
websocketpp::lib::placeholders::_1
|
||||
));
|
||||
con->set_fail_handler(websocketpp::lib::bind(
|
||||
&connection_metadata::on_fail,
|
||||
metadata_ptr,
|
||||
&m_endpoint,
|
||||
websocketpp::lib::placeholders::_1
|
||||
));
|
||||
|
||||
m_endpoint.connect(con);
|
||||
|
||||
return new_id;
|
||||
}
|
||||
|
||||
connection_metadata::ptr get_metadata(int id) const {
|
||||
con_list::const_iterator metadata_it = m_connection_list.find(id);
|
||||
if (metadata_it == m_connection_list.end()) {
|
||||
return connection_metadata::ptr();
|
||||
} else {
|
||||
return metadata_it->second;
|
||||
}
|
||||
}
|
||||
private:
|
||||
typedef std::map<int,connection_metadata::ptr> con_list;
|
||||
|
||||
client m_endpoint;
|
||||
websocketpp::lib::shared_ptr<websocketpp::lib::thread> m_thread;
|
||||
|
||||
con_list m_connection_list;
|
||||
int m_next_id;
|
||||
};
|
||||
|
||||
int main() {
|
||||
bool done = false;
|
||||
std::string input;
|
||||
websocket_endpoint endpoint;
|
||||
|
||||
while (!done) {
|
||||
std::cout << "Enter Command: ";
|
||||
std::getline(std::cin, input);
|
||||
|
||||
if (input == "quit") {
|
||||
done = true;
|
||||
} else if (input == "help") {
|
||||
std::cout
|
||||
<< "\nCommand List:\n"
|
||||
<< "connect <ws uri>\n"
|
||||
<< "show <connection id>\n"
|
||||
<< "help: Display this help text\n"
|
||||
<< "quit: Exit the program\n"
|
||||
<< std::endl;
|
||||
} else if (input.substr(0,7) == "connect") {
|
||||
int id = endpoint.connect(input.substr(8));
|
||||
if (id != -1) {
|
||||
std::cout << "> Created connection with id " << id << std::endl;
|
||||
}
|
||||
} else if (input.substr(0,4) == "show") {
|
||||
int id = atoi(input.substr(5).c_str());
|
||||
|
||||
connection_metadata::ptr metadata = endpoint.get_metadata(id);
|
||||
if (metadata) {
|
||||
std::cout << *metadata << std::endl;
|
||||
} else {
|
||||
std::cout << "> Unknown connection id " << id << std::endl;
|
||||
}
|
||||
} else {
|
||||
std::cout << "> Unrecognized Command" << std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
```
|
||||
|
||||
### Step 5
|
||||
|
||||
_Closing connections_
|
||||
|
||||
This step adds a command that allows you to close a WebSocket connection and adjusts the quit command so that it cleanly closes all outstanding connections before quitting.
|
||||
|
||||
#### Getting connection close information out of WebSocket++
|
||||
|
||||
> ###### Terminology: WebSocket close codes & reasons
|
||||
> The WebSocket close handshake involves an exchange of optional machine readable close codes and human readable reason strings. Each endpoint sends independent close details. The codes are short integers. The reasons are UTF8 text strings of at most 125 characters. More details about valid close code ranges and the meaning of each code can be found at https://tools.ietf.org/html/rfc6455#section-7.4
|
||||
|
||||
The `websocketpp::close::status` namespace contains named constants for all of the IANA defined close codes. It also includes free functions to determine whether a value is reserved or invalid and to convert a code to a human readable text representation.
|
||||
|
||||
During the close handler call WebSocket++ connections offer the following methods for accessing close handshake information:
|
||||
|
||||
- `connection::get_remote_close_code()`: Get the close code as reported by the remote endpoint
|
||||
- `connection::get_remote_close_reason()`: Get the close reason as reported by the remote endpoint
|
||||
- `connection::get_local_close_code()`: Get the close code that this endpoint sent.
|
||||
- `connection::get_local_close_reason()`: Get the close reason that this endpoint sent.
|
||||
- `connection::get_ec()`: Get a more detailed/specific WebSocket++ `error_code` indicating what library error (if any) ultimately resulted in the connection closure.
|
||||
|
||||
*Note:* there are some special close codes that will report a code that was not actually sent on the wire. For example 1005/"no close code" indicates that the endpoint omitted a close code entirely and 1006/"abnormal close" indicates that there was a problem that resulted in the connection closing without having performed a close handshake.
|
||||
|
||||
#### Add close handler
|
||||
|
||||
The `connection_metadata::on_close` method is added. This method retrieves the close code and reason from the closing handshake and stores it in the local error reason field.
|
||||
|
||||
```cpp
|
||||
void on_close(client * c, websocketpp::connection_hdl hdl) {
|
||||
m_status = "Closed";
|
||||
client::connection_ptr con = c->get_con_from_hdl(hdl);
|
||||
std::stringstream s;
|
||||
s << "close code: " << con->get_remote_close_code() << " ("
|
||||
<< websocketpp::close::status::get_string(con->get_remote_close_code())
|
||||
<< "), close reason: " << con->get_remote_close_reason();
|
||||
m_error_reason = s.str();
|
||||
}
|
||||
```
|
||||
|
||||
Similarly to `on_open` and `on_fail`, `websocket_endpoint::connect` registers this close handler when a new connection is made.
|
||||
|
||||
#### Add close method to `websocket_endpoint`
|
||||
|
||||
This method starts by looking up the given connection ID in the connection list. Next a close request is sent to the connection's handle with the specified WebSocket close code. This is done by calling `endpoint::close`. This is a thread safe method that is used to asynchronously dispatch a close signal to the connection with the given handle. When the operation is complete the connection's close handler will be triggered.
|
||||
|
||||
```cpp
|
||||
void close(int id, websocketpp::close::status::value code) {
|
||||
websocketpp::lib::error_code ec;
|
||||
|
||||
con_list::iterator metadata_it = m_connection_list.find(id);
|
||||
if (metadata_it == m_connection_list.end()) {
|
||||
std::cout << "> No connection found with id " << id << std::endl;
|
||||
return;
|
||||
}
|
||||
|
||||
m_endpoint.close(metadata_it->second->get_hdl(), code, "", ec);
|
||||
if (ec) {
|
||||
std::cout << "> Error initiating close: " << ec.message() << std::endl;
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
#### Add close option to the command loop and help message
|
||||
|
||||
A close option is added to the command loop. It takes a connection ID and optionally a close code and a close reason. If no code is specified the default of 1000/Normal is used. If no reason is specified, none is sent. The `endpoint::send` method will do some error checking and abort the close request if you try and send an invalid code or a reason with invalid UTF8 formatting. Reason strings longer than 125 characters will be truncated.
|
||||
|
||||
An entry is also added to the help system to describe how the new command may be used.
|
||||
|
||||
```cpp
|
||||
else if (input.substr(0,5) == "close") {
|
||||
std::stringstream ss(input);
|
||||
|
||||
std::string cmd;
|
||||
int id;
|
||||
int close_code = websocketpp::close::status::normal;
|
||||
std::string reason = "";
|
||||
|
||||
ss >> cmd >> id >> close_code;
|
||||
std::getline(ss,reason);
|
||||
|
||||
endpoint.close(id, close_code, reason);
|
||||
}
|
||||
```
|
||||
|
||||
#### Close all outstanding connections in `websocket_endpoint` destructor
|
||||
|
||||
Until now quitting the program left outstanding connections and the WebSocket++ network thread in a lurch. Now that we have a method of closing connections we can clean this up properly.
|
||||
|
||||
The destructor for `websocket_endpoint` now stops perpetual mode (so the run thread exits after the last connection is closed) and iterates through the list of open connections and requests a clean close for each. Finally, the run thread is joined which causes the program to wait until those connection closes complete.
|
||||
|
||||
```cpp
|
||||
~websocket_endpoint() {
|
||||
m_endpoint.stop_perpetual();
|
||||
|
||||
for (con_list::const_iterator it = m_connection_list.begin(); it != m_connection_list.end(); ++it) {
|
||||
if (it->second->get_status() != "Open") {
|
||||
// Only close open connections
|
||||
continue;
|
||||
}
|
||||
|
||||
std::cout << "> Closing connection " << it->second->get_id() << std::endl;
|
||||
|
||||
websocketpp::lib::error_code ec;
|
||||
m_endpoint.close(it->second->get_hdl(), websocketpp::close::status::going_away, "", ec);
|
||||
if (ec) {
|
||||
std::cout << "> Error closing connection " << it->second->get_id() << ": "
|
||||
<< ec.message() << std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
m_thread->join();
|
||||
}
|
||||
```
|
||||
|
||||
#### Build
|
||||
|
||||
There are no changes to the build instructions from step 4
|
||||
|
||||
#### Run
|
||||
|
||||
```
|
||||
Enter Command: connect ws://localhost:9002
|
||||
> Created connection with id 0
|
||||
Enter Command: close 0 1001 example message
|
||||
Enter Command: show 0
|
||||
> URI: ws://localhost:9002
|
||||
> Status: Closed
|
||||
> Remote Server: WebSocket++/0.3.0-alpha4
|
||||
> Error/close reason: close code: 1001 (Going away), close reason: example message
|
||||
Enter Command: connect ws://localhost:9002
|
||||
> Created connection with id 1
|
||||
Enter Command: close 1 1006
|
||||
> Error initiating close: Invalid close code used
|
||||
Enter Command: quit
|
||||
> Closing connection 1
|
||||
```
|
||||
|
||||
### Step 6
|
||||
|
||||
_Sending and receiving messages_
|
||||
|
||||
- Sending a messages
|
||||
- terminology: WebSocket opcodes, text vs binary messages
|
||||
- Receiving a message
|
||||
|
||||
### Step 7
|
||||
|
||||
_Using TLS / Secure WebSockets_
|
||||
|
||||
Chapter 2: Intermediate Features
|
||||
--------------------------------
|
||||
|
||||
### Step 8
|
||||
|
||||
_Intermediate level features_
|
||||
|
||||
- Subprotocol negotiation
|
||||
- Setting and reading custom headers
|
||||
- Ping and Pong
|
||||
- Proxies?
|
||||
- Setting user agent
|
||||
- Setting Origin
|
||||
- Timers and security
|
||||
- Close behavior
|
||||
- Send one message to all connections
|
||||
|
||||
|
||||
### Misc stuff not sure if it should be included here or elsewhere?
|
||||
|
||||
core websocket++ control flow.
|
||||
A handshake, followed by a split into 2 independent control strands
|
||||
- Handshake
|
||||
-- use information specified before the call to endpoint::connect to construct a WebSocket handshake request.
|
||||
-- Pass the WebSocket handshake request to the transport policy. The transport policy determines how to get these bytes to the endpoint playing the server role. Depending on which transport policy your endpoint uses this method will be different.
|
||||
-- Receive a handshake response from the underlying transport. This is parsed and checked for conformance to RFC6455. If the validation fails, the fail handler is called. Otherwise the open handler is called.
|
||||
- At this point control splits into two separate strands. One that reads new bytes from the transport policy on the incoming channle, the other that accepts new messages from the local application for framing and writing to the outgoing transport channel.
|
||||
- Read strand
|
||||
-- Read and process new bytes from transport
|
||||
-- If the bytes contain at least one complete message dispatch each message by calling the appropriate handler. This is either the message handler for data messages, or ping/pong/close handlers for each respective control message. If no handler is registered for a particular message it is ignored.
|
||||
-- Ask the transport layer for more bytes
|
||||
- Write strand
|
||||
-- Wait for messages from the application
|
||||
-- Perform error checking on message input,
|
||||
-- Frame message per RFC6455
|
||||
-- Queue message for sending
|
||||
-- Pass all outstanding messages to the transport policy for output
|
||||
-- When there are no messages left to send, return to waiting
|
||||
|
||||
Important observations
|
||||
Handlers run in line with library processing which has several implications applications should be aware of:
|
||||
@@ -1,123 +0,0 @@
|
||||
/*
|
||||
base64.cpp and base64.h
|
||||
|
||||
Copyright (C) 2004-2008 René Nyffenegger
|
||||
|
||||
This source code is provided 'as-is', without any express or implied
|
||||
warranty. In no event will the author be held liable for any damages
|
||||
arising from the use of this software.
|
||||
|
||||
Permission is granted to anyone to use this software for any purpose,
|
||||
including commercial applications, and to alter it and redistribute it
|
||||
freely, subject to the following restrictions:
|
||||
|
||||
1. The origin of this source code must not be misrepresented; you must not
|
||||
claim that you wrote the original source code. If you use this source code
|
||||
in a product, an acknowledgment in the product documentation would be
|
||||
appreciated but is not required.
|
||||
|
||||
2. Altered source versions must be plainly marked as such, and must not be
|
||||
misrepresented as being the original source code.
|
||||
|
||||
3. This notice may not be removed or altered from any source distribution.
|
||||
|
||||
René Nyffenegger rene.nyffenegger@adp-gmbh.ch
|
||||
|
||||
*/
|
||||
|
||||
#include "base64.h"
|
||||
#include <iostream>
|
||||
|
||||
static const std::string base64_chars =
|
||||
"ABCDEFGHIJKLMNOPQRSTUVWXYZ"
|
||||
"abcdefghijklmnopqrstuvwxyz"
|
||||
"0123456789+/";
|
||||
|
||||
|
||||
static inline bool is_base64(unsigned char c) {
|
||||
return (isalnum(c) || (c == '+') || (c == '/'));
|
||||
}
|
||||
|
||||
std::string base64_encode(unsigned char const* bytes_to_encode, unsigned int in_len) {
|
||||
std::string ret;
|
||||
int i = 0;
|
||||
int j = 0;
|
||||
unsigned char char_array_3[3];
|
||||
unsigned char char_array_4[4];
|
||||
|
||||
while (in_len--) {
|
||||
char_array_3[i++] = *(bytes_to_encode++);
|
||||
if (i == 3) {
|
||||
char_array_4[0] = (char_array_3[0] & 0xfc) >> 2;
|
||||
char_array_4[1] = ((char_array_3[0] & 0x03) << 4) + ((char_array_3[1] & 0xf0) >> 4);
|
||||
char_array_4[2] = ((char_array_3[1] & 0x0f) << 2) + ((char_array_3[2] & 0xc0) >> 6);
|
||||
char_array_4[3] = char_array_3[2] & 0x3f;
|
||||
|
||||
for(i = 0; (i <4) ; i++)
|
||||
ret += base64_chars[char_array_4[i]];
|
||||
i = 0;
|
||||
}
|
||||
}
|
||||
|
||||
if (i)
|
||||
{
|
||||
for(j = i; j < 3; j++)
|
||||
char_array_3[j] = '\0';
|
||||
|
||||
char_array_4[0] = (char_array_3[0] & 0xfc) >> 2;
|
||||
char_array_4[1] = ((char_array_3[0] & 0x03) << 4) + ((char_array_3[1] & 0xf0) >> 4);
|
||||
char_array_4[2] = ((char_array_3[1] & 0x0f) << 2) + ((char_array_3[2] & 0xc0) >> 6);
|
||||
char_array_4[3] = char_array_3[2] & 0x3f;
|
||||
|
||||
for (j = 0; (j < i + 1); j++)
|
||||
ret += base64_chars[char_array_4[j]];
|
||||
|
||||
while((i++ < 3))
|
||||
ret += '=';
|
||||
|
||||
}
|
||||
|
||||
return ret;
|
||||
|
||||
}
|
||||
|
||||
std::string base64_decode(std::string const& encoded_string) {
|
||||
size_t in_len = encoded_string.size();
|
||||
int i = 0;
|
||||
int j = 0;
|
||||
int in_ = 0;
|
||||
unsigned char char_array_4[4], char_array_3[3];
|
||||
std::string ret;
|
||||
|
||||
while (in_len-- && ( encoded_string[in_] != '=') && is_base64(encoded_string[in_])) {
|
||||
char_array_4[i++] = encoded_string[in_]; in_++;
|
||||
if (i ==4) {
|
||||
for (i = 0; i <4; i++)
|
||||
char_array_4[i] = static_cast<unsigned char>(base64_chars.find(char_array_4[i]));
|
||||
|
||||
char_array_3[0] = (char_array_4[0] << 2) + ((char_array_4[1] & 0x30) >> 4);
|
||||
char_array_3[1] = ((char_array_4[1] & 0xf) << 4) + ((char_array_4[2] & 0x3c) >> 2);
|
||||
char_array_3[2] = ((char_array_4[2] & 0x3) << 6) + char_array_4[3];
|
||||
|
||||
for (i = 0; (i < 3); i++)
|
||||
ret += char_array_3[i];
|
||||
i = 0;
|
||||
}
|
||||
}
|
||||
|
||||
if (i) {
|
||||
for (j = i; j <4; j++)
|
||||
char_array_4[j] = 0;
|
||||
|
||||
for (j = 0; j <4; j++)
|
||||
char_array_4[j] = static_cast<unsigned char>(base64_chars.find(char_array_4[j]));
|
||||
|
||||
char_array_3[0] = (char_array_4[0] << 2) + ((char_array_4[1] & 0x30) >> 4);
|
||||
char_array_3[1] = ((char_array_4[1] & 0xf) << 4) + ((char_array_4[2] & 0x3c) >> 2);
|
||||
char_array_3[2] = ((char_array_4[2] & 0x3) << 6) + char_array_4[3];
|
||||
|
||||
for (j = 0; (j < i - 1); j++) ret += char_array_3[j];
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
@@ -1,4 +0,0 @@
|
||||
#include <string>
|
||||
|
||||
std::string base64_encode(unsigned char const* , unsigned int len);
|
||||
std::string base64_decode(std::string const& s);
|
||||
@@ -1,12 +1,12 @@
|
||||
/*
|
||||
/*
|
||||
******
|
||||
base64.hpp is a repackaging of the base64.cpp and base64.h files into a
|
||||
single headersuitable for use as a header only library. This conversion was
|
||||
base64.hpp is a repackaging of the base64.cpp and base64.h files into a
|
||||
single header suitable for use as a header only library. This conversion was
|
||||
done by Peter Thorson (webmaster@zaphoyd.com) in 2012. All modifications to
|
||||
the code are redistributed under the same license as the original, which is
|
||||
the code are redistributed under the same license as the original, which is
|
||||
listed below.
|
||||
******
|
||||
|
||||
|
||||
base64.cpp and base64.h
|
||||
|
||||
Copyright (C) 2004-2008 René Nyffenegger
|
||||
@@ -38,7 +38,9 @@
|
||||
|
||||
#include <string>
|
||||
|
||||
static const std::string base64_chars =
|
||||
namespace websocketpp {
|
||||
|
||||
static std::string const base64_chars =
|
||||
"ABCDEFGHIJKLMNOPQRSTUVWXYZ"
|
||||
"abcdefghijklmnopqrstuvwxyz"
|
||||
"0123456789+/";
|
||||
@@ -50,7 +52,7 @@ static inline bool is_base64(unsigned char c) {
|
||||
(c >= 97 && c <= 122)); // a-z
|
||||
}
|
||||
|
||||
inline std::string base64_encode(unsigned char const* bytes_to_encode, unsigned
|
||||
inline std::string base64_encode(unsigned char const * bytes_to_encode, unsigned
|
||||
int in_len)
|
||||
{
|
||||
std::string ret;
|
||||
@@ -63,9 +65,9 @@ inline std::string base64_encode(unsigned char const* bytes_to_encode, unsigned
|
||||
char_array_3[i++] = *(bytes_to_encode++);
|
||||
if (i == 3) {
|
||||
char_array_4[0] = (char_array_3[0] & 0xfc) >> 2;
|
||||
char_array_4[1] = ((char_array_3[0] & 0x03) << 4) +
|
||||
char_array_4[1] = ((char_array_3[0] & 0x03) << 4) +
|
||||
((char_array_3[1] & 0xf0) >> 4);
|
||||
char_array_4[2] = ((char_array_3[1] & 0x0f) << 2) +
|
||||
char_array_4[2] = ((char_array_3[1] & 0x0f) << 2) +
|
||||
((char_array_3[2] & 0xc0) >> 6);
|
||||
char_array_4[3] = char_array_3[2] & 0x3f;
|
||||
|
||||
@@ -82,9 +84,9 @@ inline std::string base64_encode(unsigned char const* bytes_to_encode, unsigned
|
||||
}
|
||||
|
||||
char_array_4[0] = (char_array_3[0] & 0xfc) >> 2;
|
||||
char_array_4[1] = ((char_array_3[0] & 0x03) << 4) +
|
||||
char_array_4[1] = ((char_array_3[0] & 0x03) << 4) +
|
||||
((char_array_3[1] & 0xf0) >> 4);
|
||||
char_array_4[2] = ((char_array_3[1] & 0x0f) << 2) +
|
||||
char_array_4[2] = ((char_array_3[1] & 0x0f) << 2) +
|
||||
((char_array_3[2] & 0xc0) >> 6);
|
||||
char_array_4[3] = char_array_3[2] & 0x3f;
|
||||
|
||||
@@ -100,11 +102,11 @@ inline std::string base64_encode(unsigned char const* bytes_to_encode, unsigned
|
||||
return ret;
|
||||
}
|
||||
|
||||
inline std::string base64_encode(const std::string & data) {
|
||||
inline std::string base64_encode(std::string const & data) {
|
||||
return base64_encode(reinterpret_cast<const unsigned char *>(data.data()),data.size());
|
||||
}
|
||||
|
||||
inline std::string base64_decode(std::string const& encoded_string) {
|
||||
inline std::string base64_decode(std::string const & encoded_string) {
|
||||
size_t in_len = encoded_string.size();
|
||||
int i = 0;
|
||||
int j = 0;
|
||||
@@ -149,4 +151,6 @@ inline std::string base64_decode(std::string const& encoded_string) {
|
||||
return ret;
|
||||
}
|
||||
|
||||
} // namespace websocketpp
|
||||
|
||||
#endif // _BASE64_HPP_
|
||||
@@ -11,10 +11,10 @@
|
||||
* * 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
|
||||
*
|
||||
* 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;
|
||||
@@ -22,7 +22,7 @@
|
||||
* 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_CLIENT_HPP
|
||||
@@ -30,4 +30,4 @@
|
||||
|
||||
#include <websocketpp/roles/client_endpoint.hpp>
|
||||
|
||||
#endif //WEBSOCKETPP_CLIENT_HPP
|
||||
#endif //WEBSOCKETPP_CLIENT_HPP
|
||||
+84
-14
@@ -12,10 +12,10 @@
|
||||
* * 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
|
||||
*
|
||||
* 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;
|
||||
@@ -23,7 +23,7 @@
|
||||
* 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_CLOSE_HPP
|
||||
@@ -33,10 +33,10 @@
|
||||
* A package of types and methods for manipulating WebSocket close codes.
|
||||
*/
|
||||
|
||||
#include <websocketpp/error.hpp>
|
||||
#include <websocketpp/error.hpp>
|
||||
#include <websocketpp/common/network.hpp>
|
||||
#include <websocketpp/common/stdint.hpp>
|
||||
#include <websocketpp/utf8_validator.hpp>
|
||||
#include <websocketpp/utf8_validator.hpp>
|
||||
|
||||
#include <string>
|
||||
|
||||
@@ -47,10 +47,30 @@ namespace close {
|
||||
namespace status {
|
||||
/// The type of a close code value.
|
||||
typedef uint16_t value;
|
||||
|
||||
|
||||
/// A blank value for internal use.
|
||||
static value const blank = 0;
|
||||
|
||||
/// Close the connection without a WebSocket close handshake.
|
||||
/**
|
||||
* This special value requests that the WebSocket connection be closed
|
||||
* without performing the WebSocket closing handshake. This does not comply
|
||||
* with RFC6455, but should be safe to do if necessary. This could be useful
|
||||
* for clients that need to disconnect quickly and cannot afford the
|
||||
* complete handshake.
|
||||
*/
|
||||
static value const omit_handshake = 1;
|
||||
|
||||
/// Close the connection with a forced TCP drop.
|
||||
/**
|
||||
* This special value requests that the WebSocket connection be closed by
|
||||
* forcibly dropping the TCP connection. This will leave the other side of
|
||||
* the connection with a broken connection and some expensive timeouts. this
|
||||
* should not be done except in extreme cases or in cases of malicious
|
||||
* remote endpoints.
|
||||
*/
|
||||
static value const force_tcp_drop = 2;
|
||||
|
||||
/// Normal closure, meaning that the purpose for which the connection was
|
||||
/// established has been fulfilled.
|
||||
static value const normal = 1000;
|
||||
@@ -62,7 +82,7 @@ namespace status {
|
||||
/// A protocol error occurred.
|
||||
static value const protocol_error = 1002;
|
||||
|
||||
/// The connection was terminated because an endpoint received a type of
|
||||
/// The connection was terminated because an endpoint received a type of
|
||||
/// data it cannot accept.
|
||||
/**
|
||||
* (e.g., an endpoint that understands only text data MAY send this if it
|
||||
@@ -112,6 +132,16 @@ namespace status {
|
||||
/// fulfilling the request.
|
||||
static value const internal_endpoint_error = 1011;
|
||||
|
||||
/// Indicates that the service is restarted. A client may reconnect and if
|
||||
/// if it chooses to do so, should reconnect using a randomized delay of
|
||||
/// 5-30s
|
||||
static value const service_restart = 1012;
|
||||
|
||||
/// Indicates that the service is experiencing overload. A client should
|
||||
/// only connect to a different IP (when there are multiple for the target)
|
||||
/// or reconnect to the same IP upon user action.
|
||||
static value const try_again_later = 1013;
|
||||
|
||||
/// An endpoint failed to perform a TLS handshake
|
||||
/**
|
||||
* Designated for use in applications expecting a status code to indicate
|
||||
@@ -133,7 +163,7 @@ namespace status {
|
||||
*/
|
||||
inline bool reserved(value code) {
|
||||
return ((code >= rsv_start && code <= rsv_end) ||
|
||||
code == 1004 || code == 1012 || code == 1013 || code == 1014);
|
||||
code == 1004 || code == 1014);
|
||||
}
|
||||
|
||||
/// First value in range that is always invalid on the wire
|
||||
@@ -160,8 +190,8 @@ namespace status {
|
||||
* determine if the system has the capability of waiting for a close
|
||||
* acknowledgement or if it should drop the TCP connection immediately
|
||||
* after sending its close frame.
|
||||
*
|
||||
* @param [in] code The value to test.
|
||||
*
|
||||
* @param [in] code The value to test.
|
||||
* @return True if the code represents an unrecoverable error
|
||||
*/
|
||||
inline bool terminal(value code) {
|
||||
@@ -169,6 +199,46 @@ namespace status {
|
||||
code == policy_violation || code == message_too_big ||
|
||||
code == internal_endpoint_error);
|
||||
}
|
||||
|
||||
/// Return a human readable interpretation of a WebSocket close code
|
||||
/**
|
||||
* See https://tools.ietf.org/html/rfc6455#section-7.4 for more details.
|
||||
*
|
||||
* @since 0.4.0-beta1
|
||||
*
|
||||
* @param [in] code The code to look up.
|
||||
* @return A human readable interpretation of the code.
|
||||
*/
|
||||
inline std::string get_string(value code) {
|
||||
switch (code) {
|
||||
case normal:
|
||||
return "Normal close";
|
||||
case going_away:
|
||||
return "Going away";
|
||||
case protocol_error:
|
||||
return "Protocol error";
|
||||
case unsupported_data:
|
||||
return "Unsupported data";
|
||||
case no_status:
|
||||
return "No status set";
|
||||
case abnormal_close:
|
||||
return "Abnormal close";
|
||||
case invalid_payload:
|
||||
return "Invalid payload";
|
||||
case policy_violation:
|
||||
return "Policy violoation";
|
||||
case message_too_big:
|
||||
return "Message too big";
|
||||
case extension_required:
|
||||
return "Extension required";
|
||||
case internal_endpoint_error:
|
||||
return "Internal endpoint error";
|
||||
case tls_handshake:
|
||||
return "TLS handshake failure";
|
||||
default:
|
||||
return "Unknown";
|
||||
}
|
||||
}
|
||||
} // namespace status
|
||||
|
||||
/// Type used to convert close statuses between integer and wire representations
|
||||
@@ -187,7 +257,7 @@ union code_converter {
|
||||
*
|
||||
* If the value is in an invalid or reserved range ec is set accordingly.
|
||||
*
|
||||
* @param [in] payload Close frame payload value recieved over the wire.
|
||||
* @param [in] payload Close frame payload value received over the wire.
|
||||
* @param [out] ec Set to indicate what error occurred, if any.
|
||||
* @return The extracted value
|
||||
*/
|
||||
@@ -208,7 +278,7 @@ inline status::value extract_code(std::string const & payload, lib::error_code
|
||||
val.c[0] = payload[0];
|
||||
val.c[1] = payload[1];
|
||||
|
||||
status::value code(ntohs(val.i));
|
||||
status::value code(ntohs(val.i));
|
||||
|
||||
if (status::invalid(code)) {
|
||||
ec = make_error_code(error::invalid_close_code);
|
||||
|
||||
@@ -11,10 +11,10 @@
|
||||
* * 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
|
||||
*
|
||||
* 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;
|
||||
@@ -22,7 +22,7 @@
|
||||
* 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_CHRONO_HPP
|
||||
|
||||
@@ -11,10 +11,10 @@
|
||||
* * 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
|
||||
*
|
||||
* 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;
|
||||
@@ -22,7 +22,7 @@
|
||||
* 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_CONNECTION_HDL_HPP
|
||||
@@ -32,6 +32,19 @@
|
||||
|
||||
namespace websocketpp {
|
||||
|
||||
/// A handle to uniquely identify a connection.
|
||||
/**
|
||||
* This type uniquely identifies a connection. It is implemented as a weak
|
||||
* pointer to the connection in question. This provides uniqueness across
|
||||
* multiple endpoints and ensures that IDs never conflict or run out.
|
||||
*
|
||||
* It is safe to make copies of this handle, store those copies in containers,
|
||||
* and use them from other threads.
|
||||
*
|
||||
* This handle can be upgraded to a full shared_ptr using
|
||||
* `endpoint::get_con_from_hdl()` from within a handler fired by the connection
|
||||
* that owns the handler.
|
||||
*/
|
||||
typedef lib::weak_ptr<void> connection_hdl;
|
||||
|
||||
} // namespace websocketpp
|
||||
|
||||
@@ -11,10 +11,10 @@
|
||||
* * 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
|
||||
*
|
||||
* 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;
|
||||
@@ -22,7 +22,7 @@
|
||||
* 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_CPP11_HPP
|
||||
@@ -41,9 +41,11 @@
|
||||
#endif
|
||||
|
||||
|
||||
#ifdef _WEBSOCKETPP_CPP11_STL_
|
||||
// This flag indicates that all of the C++11 language features are available
|
||||
// to us.
|
||||
#if defined(_WEBSOCKETPP_CPP11_STL_) || __cplusplus >= 201103L
|
||||
// _WEBSOCKETPP_CPP11_STL_ is a flag from the build system that forces
|
||||
// WebSocket++ into C++11 mode. __cplusplus is a define set by the compiler
|
||||
// if it has full support for C++11 language features. If either are set use
|
||||
// C++11 language features
|
||||
#ifndef _WEBSOCKETPP_NOEXCEPT_TOKEN_
|
||||
#define _WEBSOCKETPP_NOEXCEPT_TOKEN_ noexcept
|
||||
#endif
|
||||
@@ -53,6 +55,9 @@
|
||||
#ifndef _WEBSOCKETPP_INITIALIZER_LISTS_
|
||||
#define _WEBSOCKETPP_INITIALIZER_LISTS_
|
||||
#endif
|
||||
#ifndef _WEBSOCKETPP_NULLPTR_TOKEN_
|
||||
#define _WEBSOCKETPP_NULLPTR_TOKEN_ nullptr
|
||||
#endif
|
||||
#else
|
||||
// Test for noexcept
|
||||
#ifndef _WEBSOCKETPP_NOEXCEPT_TOKEN_
|
||||
@@ -69,7 +74,7 @@
|
||||
#endif
|
||||
#endif
|
||||
#endif
|
||||
|
||||
|
||||
// Test for constexpr
|
||||
#ifndef _WEBSOCKETPP_CONSTEXPR_TOKEN_
|
||||
#ifdef _WEBSOCKETPP_CONSTEXPR_
|
||||
@@ -85,11 +90,30 @@
|
||||
#endif
|
||||
#endif
|
||||
#endif
|
||||
|
||||
|
||||
// Enable initializer lists on clang when available.
|
||||
#if __has_feature(cxx_generalized_initializers) && !defined(_WEBSOCKETPP_INITIALIZER_LISTS_)
|
||||
#define _WEBSOCKETPP_INITIALIZER_LISTS_
|
||||
#endif
|
||||
|
||||
// Test for nullptr
|
||||
#ifndef _WEBSOCKETPP_NULLPTR_TOKEN_
|
||||
#ifdef _WEBSOCKETPP_NULLPTR_
|
||||
// build system says we have nullptr
|
||||
#define _WEBSOCKETPP_NULLPTR_TOKEN_ nullptr
|
||||
#else
|
||||
#if __has_feature(cxx_nullptr)
|
||||
// clang feature detect says we have nullptr
|
||||
#define _WEBSOCKETPP_NULLPTR_TOKEN_ nullptr
|
||||
#elif _MSC_VER >= 1600
|
||||
// Visual Studio version that has nullptr
|
||||
#define _WEBSOCKETPP_NULLPTR_TOKEN_ nullptr
|
||||
#else
|
||||
// assume we don't have nullptr
|
||||
#define _WEBSOCKETPP_NULLPTR_TOKEN_ 0
|
||||
#endif
|
||||
#endif
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#endif // WEBSOCKETPP_COMMON_CPP11_HPP
|
||||
@@ -11,10 +11,10 @@
|
||||
* * 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
|
||||
*
|
||||
* 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;
|
||||
@@ -22,7 +22,7 @@
|
||||
* 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_FUNCTIONAL_HPP
|
||||
|
||||
+80
-79
@@ -1,7 +1,8 @@
|
||||
/*
|
||||
md5.hpp is a reformulation of the md5.h and md5.c code to allow it to function
|
||||
as a component of a header only library. This conversion was done by Peter
|
||||
Thorson (webmaster@zaphoyd.com) in 2012 for the WebSocket++ project. The
|
||||
md5.hpp is a reformulation of the md5.h and md5.c code from
|
||||
http://www.opensource.apple.com/source/cups/cups-59/cups/md5.c to allow it to
|
||||
function as a component of a header only library. This conversion was done by
|
||||
Peter Thorson (webmaster@zaphoyd.com) in 2012 for the WebSocket++ project. The
|
||||
changes are released under the same license as the original (listed below)
|
||||
*/
|
||||
/*
|
||||
@@ -33,7 +34,7 @@
|
||||
|
||||
This code implements the MD5 Algorithm defined in RFC 1321, whose
|
||||
text is available at
|
||||
http://www.ietf.org/rfc/rfc1321.txt
|
||||
http://www.ietf.org/rfc/rfc1321.txt
|
||||
The code is derived from the text of the RFC, including the test suite
|
||||
(section A.5) but excluding the rest of Appendix A. It does not include
|
||||
any code or documentation that is identified in the RFC as being
|
||||
@@ -44,12 +45,12 @@
|
||||
that follows (in reverse chronological order):
|
||||
|
||||
2002-04-13 lpd Removed support for non-ANSI compilers; removed
|
||||
references to Ghostscript; clarified derivation from RFC 1321;
|
||||
now handles byte order either statically or dynamically.
|
||||
references to Ghostscript; clarified derivation from RFC 1321;
|
||||
now handles byte order either statically or dynamically.
|
||||
1999-11-04 lpd Edited comments slightly for automatic TOC extraction.
|
||||
1999-10-18 lpd Fixed typo in header comment (ansi2knr rather than md5);
|
||||
added conditionalization for C++ compilation from Martin
|
||||
Purschke <purschke@bnl.gov>.
|
||||
added conditionalization for C++ compilation from Martin
|
||||
Purschke <purschke@bnl.gov>.
|
||||
1999-05-03 lpd Original version.
|
||||
*/
|
||||
|
||||
@@ -79,9 +80,9 @@ typedef unsigned int md5_word_t; /* 32-bit word */
|
||||
|
||||
/* Define the state of the MD5 Algorithm. */
|
||||
typedef struct md5_state_s {
|
||||
md5_word_t count[2]; /* message length in bits, lsw first */
|
||||
md5_word_t abcd[4]; /* digest buffer */
|
||||
md5_byte_t buf[64]; /* accumulate block */
|
||||
md5_word_t count[2]; /* message length in bits, lsw first */
|
||||
md5_word_t abcd[4]; /* digest buffer */
|
||||
md5_byte_t buf[64]; /* accumulate block */
|
||||
} md5_state_t;
|
||||
|
||||
/* Initialize the algorithm. */
|
||||
@@ -93,7 +94,7 @@ inline void md5_append(md5_state_t *pms, md5_byte_t const * data, size_t nbytes)
|
||||
/* Finish the message and return the digest. */
|
||||
inline void md5_finish(md5_state_t *pms, md5_byte_t digest[16]);
|
||||
|
||||
#undef ZSW_MD5_BYTE_ORDER /* 1 = big-endian, -1 = little-endian, 0 = unknown */
|
||||
#undef ZSW_MD5_BYTE_ORDER /* 1 = big-endian, -1 = little-endian, 0 = unknown */
|
||||
#ifdef ARCH_IS_BIG_ENDIAN
|
||||
# define ZSW_MD5_BYTE_ORDER (ARCH_IS_BIG_ENDIAN ? 1 : -1)
|
||||
#else
|
||||
@@ -168,8 +169,8 @@ inline void md5_finish(md5_state_t *pms, md5_byte_t digest[16]);
|
||||
|
||||
static void md5_process(md5_state_t *pms, md5_byte_t const * data /*[64]*/) {
|
||||
md5_word_t
|
||||
a = pms->abcd[0], b = pms->abcd[1],
|
||||
c = pms->abcd[2], d = pms->abcd[3];
|
||||
a = pms->abcd[0], b = pms->abcd[1],
|
||||
c = pms->abcd[2], d = pms->abcd[3];
|
||||
md5_word_t t;
|
||||
#if ZSW_MD5_BYTE_ORDER > 0
|
||||
/* Define storage only for big-endian CPUs. */
|
||||
@@ -182,51 +183,51 @@ static void md5_process(md5_state_t *pms, md5_byte_t const * data /*[64]*/) {
|
||||
|
||||
{
|
||||
#if ZSW_MD5_BYTE_ORDER == 0
|
||||
/*
|
||||
* Determine dynamically whether this is a big-endian or
|
||||
* little-endian machine, since we can use a more efficient
|
||||
* algorithm on the latter.
|
||||
*/
|
||||
static int const w = 1;
|
||||
/*
|
||||
* Determine dynamically whether this is a big-endian or
|
||||
* little-endian machine, since we can use a more efficient
|
||||
* algorithm on the latter.
|
||||
*/
|
||||
static int const w = 1;
|
||||
|
||||
if (*((md5_byte_t const *)&w)) /* dynamic little-endian */
|
||||
if (*((md5_byte_t const *)&w)) /* dynamic little-endian */
|
||||
#endif
|
||||
#if ZSW_MD5_BYTE_ORDER <= 0 /* little-endian */
|
||||
{
|
||||
/*
|
||||
* On little-endian machines, we can process properly aligned
|
||||
* data without copying it.
|
||||
*/
|
||||
if (!((data - (md5_byte_t const *)0) & 3)) {
|
||||
/* data are properly aligned */
|
||||
X = (md5_word_t const *)data;
|
||||
} else {
|
||||
/* not aligned */
|
||||
std::memcpy(xbuf, data, 64);
|
||||
X = xbuf;
|
||||
}
|
||||
}
|
||||
#if ZSW_MD5_BYTE_ORDER <= 0 /* little-endian */
|
||||
{
|
||||
/*
|
||||
* On little-endian machines, we can process properly aligned
|
||||
* data without copying it.
|
||||
*/
|
||||
if (!((data - (md5_byte_t const *)0) & 3)) {
|
||||
/* data are properly aligned */
|
||||
X = (md5_word_t const *)data;
|
||||
} else {
|
||||
/* not aligned */
|
||||
std::memcpy(xbuf, data, 64);
|
||||
X = xbuf;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
#if ZSW_MD5_BYTE_ORDER == 0
|
||||
else /* dynamic big-endian */
|
||||
else /* dynamic big-endian */
|
||||
#endif
|
||||
#if ZSW_MD5_BYTE_ORDER >= 0 /* big-endian */
|
||||
{
|
||||
/*
|
||||
* On big-endian machines, we must arrange the bytes in the
|
||||
* right order.
|
||||
*/
|
||||
const md5_byte_t *xp = data;
|
||||
int i;
|
||||
#if ZSW_MD5_BYTE_ORDER >= 0 /* big-endian */
|
||||
{
|
||||
/*
|
||||
* On big-endian machines, we must arrange the bytes in the
|
||||
* right order.
|
||||
*/
|
||||
const md5_byte_t *xp = data;
|
||||
int i;
|
||||
|
||||
# if ZSW_MD5_BYTE_ORDER == 0
|
||||
X = xbuf; /* (dynamic only) */
|
||||
X = xbuf; /* (dynamic only) */
|
||||
# else
|
||||
# define xbuf X /* (static only) */
|
||||
# define xbuf X /* (static only) */
|
||||
# endif
|
||||
for (i = 0; i < 16; ++i, xp += 4)
|
||||
xbuf[i] = xp[0] + (xp[1] << 8) + (xp[2] << 16) + (xp[3] << 24);
|
||||
}
|
||||
for (i = 0; i < 16; ++i, xp += 4)
|
||||
xbuf[i] = xp[0] + (xp[1] << 8) + (xp[2] << 16) + (xp[3] << 24);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
@@ -360,71 +361,71 @@ void md5_append(md5_state_t *pms, md5_byte_t const * data, size_t nbytes) {
|
||||
md5_word_t nbits = (md5_word_t)(nbytes << 3);
|
||||
|
||||
if (nbytes <= 0)
|
||||
return;
|
||||
return;
|
||||
|
||||
/* Update the message length. */
|
||||
pms->count[1] += nbytes >> 29;
|
||||
pms->count[0] += nbits;
|
||||
if (pms->count[0] < nbits)
|
||||
pms->count[1]++;
|
||||
pms->count[1]++;
|
||||
|
||||
/* Process an initial partial block. */
|
||||
if (offset) {
|
||||
int copy = (offset + nbytes > 64 ? 64 - offset : static_cast<int>(nbytes));
|
||||
int copy = (offset + nbytes > 64 ? 64 - offset : static_cast<int>(nbytes));
|
||||
|
||||
std::memcpy(pms->buf + offset, p, copy);
|
||||
if (offset + copy < 64)
|
||||
return;
|
||||
p += copy;
|
||||
left -= copy;
|
||||
md5_process(pms, pms->buf);
|
||||
std::memcpy(pms->buf + offset, p, copy);
|
||||
if (offset + copy < 64)
|
||||
return;
|
||||
p += copy;
|
||||
left -= copy;
|
||||
md5_process(pms, pms->buf);
|
||||
}
|
||||
|
||||
/* Process full blocks. */
|
||||
for (; left >= 64; p += 64, left -= 64)
|
||||
md5_process(pms, p);
|
||||
md5_process(pms, p);
|
||||
|
||||
/* Process a final partial block. */
|
||||
if (left)
|
||||
std::memcpy(pms->buf, p, left);
|
||||
std::memcpy(pms->buf, p, left);
|
||||
}
|
||||
|
||||
void md5_finish(md5_state_t *pms, md5_byte_t digest[16]) {
|
||||
static md5_byte_t const pad[64] = {
|
||||
0x80, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
|
||||
0x80, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
|
||||
};
|
||||
md5_byte_t data[8];
|
||||
int i;
|
||||
|
||||
/* Save the length before padding. */
|
||||
for (i = 0; i < 8; ++i)
|
||||
data[i] = (md5_byte_t)(pms->count[i >> 2] >> ((i & 3) << 3));
|
||||
data[i] = (md5_byte_t)(pms->count[i >> 2] >> ((i & 3) << 3));
|
||||
/* Pad to 56 bytes mod 64. */
|
||||
md5_append(pms, pad, ((55 - (pms->count[0] >> 3)) & 63) + 1);
|
||||
/* Append the length. */
|
||||
md5_append(pms, data, 8);
|
||||
for (i = 0; i < 16; ++i)
|
||||
digest[i] = (md5_byte_t)(pms->abcd[i >> 2] >> ((i & 3) << 3));
|
||||
digest[i] = (md5_byte_t)(pms->abcd[i >> 2] >> ((i & 3) << 3));
|
||||
}
|
||||
|
||||
// some convenience c++ functions
|
||||
inline std::string md5_hash_string(std::string const & s) {
|
||||
char digest[16];
|
||||
|
||||
md5_state_t state;
|
||||
|
||||
md5_init(&state);
|
||||
md5_append(&state, (md5_byte_t const *)s.c_str(), s.size());
|
||||
md5_finish(&state, (md5_byte_t *)digest);
|
||||
|
||||
char digest[16];
|
||||
|
||||
md5_state_t state;
|
||||
|
||||
md5_init(&state);
|
||||
md5_append(&state, (md5_byte_t const *)s.c_str(), s.size());
|
||||
md5_finish(&state, (md5_byte_t *)digest);
|
||||
|
||||
std::string ret;
|
||||
ret.resize(16);
|
||||
std::copy(digest,digest+16,ret.begin());
|
||||
|
||||
return ret;
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
const char hexval[16] = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f'};
|
||||
@@ -432,12 +433,12 @@ const char hexval[16] = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a',
|
||||
inline std::string md5_hash_hex(std::string const & input) {
|
||||
std::string hash = md5_hash_string(input);
|
||||
std::string hex;
|
||||
|
||||
|
||||
for (size_t i = 0; i < hash.size(); i++) {
|
||||
hex.push_back(hexval[((hash[i] >> 4) & 0xF)]);
|
||||
hex.push_back(hexval[(hash[i]) & 0x0F]);
|
||||
}
|
||||
|
||||
|
||||
return hex;
|
||||
}
|
||||
|
||||
|
||||
@@ -11,10 +11,10 @@
|
||||
* * 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
|
||||
*
|
||||
* 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;
|
||||
@@ -22,7 +22,7 @@
|
||||
* 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_MEMORY_HPP
|
||||
|
||||
@@ -11,10 +11,10 @@
|
||||
* * 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
|
||||
*
|
||||
* 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;
|
||||
@@ -22,14 +22,14 @@
|
||||
* 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_NETWORK_HPP
|
||||
#define WEBSOCKETPP_COMMON_NETWORK_HPP
|
||||
|
||||
// For ntohs and htons
|
||||
#if defined(WIN32)
|
||||
#if defined(_WIN32)
|
||||
#include <winsock2.h>
|
||||
#else
|
||||
//#include <arpa/inet.h>
|
||||
@@ -46,32 +46,32 @@ inline bool is_little_endian() {
|
||||
return (ptr[0] == 1);
|
||||
}
|
||||
|
||||
#define TYP_INIT 0
|
||||
#define TYP_SMLE 1
|
||||
#define TYP_BIGE 2
|
||||
#define TYP_INIT 0
|
||||
#define TYP_SMLE 1
|
||||
#define TYP_BIGE 2
|
||||
|
||||
inline uint64_t htonll(uint64_t src) {
|
||||
static int typ = TYP_INIT;
|
||||
unsigned char c;
|
||||
union {
|
||||
uint64_t ull;
|
||||
unsigned char c[8];
|
||||
} x;
|
||||
if (typ == TYP_INIT) {
|
||||
x.ull = 0x01;
|
||||
typ = (x.c[7] == 0x01ULL) ? TYP_BIGE : TYP_SMLE;
|
||||
}
|
||||
if (typ == TYP_BIGE)
|
||||
inline uint64_t htonll(uint64_t src) {
|
||||
static int typ = TYP_INIT;
|
||||
unsigned char c;
|
||||
union {
|
||||
uint64_t ull;
|
||||
unsigned char c[8];
|
||||
} x;
|
||||
if (typ == TYP_INIT) {
|
||||
x.ull = 0x01;
|
||||
typ = (x.c[7] == 0x01ULL) ? TYP_BIGE : TYP_SMLE;
|
||||
}
|
||||
if (typ == TYP_BIGE)
|
||||
return src;
|
||||
x.ull = src;
|
||||
c = x.c[0]; x.c[0] = x.c[7]; x.c[7] = c;
|
||||
c = x.c[1]; x.c[1] = x.c[6]; x.c[6] = c;
|
||||
c = x.c[2]; x.c[2] = x.c[5]; x.c[5] = c;
|
||||
c = x.c[3]; x.c[3] = x.c[4]; x.c[4] = c;
|
||||
return x.ull;
|
||||
x.ull = src;
|
||||
c = x.c[0]; x.c[0] = x.c[7]; x.c[7] = c;
|
||||
c = x.c[1]; x.c[1] = x.c[6]; x.c[6] = c;
|
||||
c = x.c[2]; x.c[2] = x.c[5]; x.c[5] = c;
|
||||
c = x.c[3]; x.c[3] = x.c[4]; x.c[4] = c;
|
||||
return x.ull;
|
||||
}
|
||||
|
||||
inline uint64_t ntohll(uint64_t src) {
|
||||
inline uint64_t ntohll(uint64_t src) {
|
||||
return htonll(src);
|
||||
}
|
||||
|
||||
|
||||
@@ -11,10 +11,10 @@
|
||||
* * 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
|
||||
*
|
||||
* 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;
|
||||
@@ -22,18 +22,18 @@
|
||||
* 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_PLATFORMS_HPP
|
||||
#define WEBSOCKETPP_COMMON_PLATFORMS_HPP
|
||||
|
||||
/**
|
||||
* This header contains any platform specific preprocessor adjustments that
|
||||
* This header contains any platform specific preprocessor adjustments that
|
||||
* don't fit somewhere else better.
|
||||
*/
|
||||
|
||||
#if defined(WIN32) && !defined(NOMINMAX)
|
||||
|
||||
#if defined(_WIN32) && !defined(NOMINMAX)
|
||||
// don't define min and max macros that conflict with std::min and std::max
|
||||
#define NOMINMAX
|
||||
#endif
|
||||
|
||||
@@ -11,10 +11,10 @@
|
||||
* * 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
|
||||
*
|
||||
* 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;
|
||||
@@ -22,7 +22,7 @@
|
||||
* 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_RANDOM_DEVICE_HPP
|
||||
@@ -38,7 +38,7 @@
|
||||
#include <random>
|
||||
#else
|
||||
#include <boost/version.hpp>
|
||||
|
||||
|
||||
#if (BOOST_VERSION/100000) == 1 && ((BOOST_VERSION/100)%1000) > 46
|
||||
#include <boost/random/uniform_int_distribution.hpp>
|
||||
#include <boost/random/random_device.hpp>
|
||||
|
||||
@@ -11,10 +11,10 @@
|
||||
* * 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
|
||||
*
|
||||
* 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;
|
||||
@@ -22,7 +22,7 @@
|
||||
* 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_REGEX_HPP
|
||||
|
||||
@@ -11,10 +11,10 @@
|
||||
* * 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
|
||||
*
|
||||
* 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;
|
||||
@@ -22,7 +22,7 @@
|
||||
* 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_STDINT_HPP
|
||||
@@ -32,7 +32,7 @@
|
||||
#define __STDC_LIMIT_MACROS 1
|
||||
#endif
|
||||
|
||||
#if WIN32 && (_MSC_VER < 1600)
|
||||
#if defined (_WIN32) && defined (_MSC_VER) && (_MSC_VER < 1600)
|
||||
#include <boost/cstdint.hpp>
|
||||
|
||||
using boost::int8_t;
|
||||
|
||||
@@ -11,10 +11,10 @@
|
||||
* * 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
|
||||
*
|
||||
* 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;
|
||||
@@ -22,7 +22,7 @@
|
||||
* 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_SYSTEM_ERROR_HPP
|
||||
|
||||
@@ -11,10 +11,10 @@
|
||||
* * 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
|
||||
*
|
||||
* 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;
|
||||
@@ -22,7 +22,7 @@
|
||||
* 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_THREAD_HPP
|
||||
|
||||
@@ -11,10 +11,10 @@
|
||||
* * 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
|
||||
*
|
||||
* 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;
|
||||
@@ -22,7 +22,7 @@
|
||||
* 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_CONCURRENCY_BASIC_HPP
|
||||
@@ -37,10 +37,10 @@ namespace concurrency {
|
||||
class basic {
|
||||
public:
|
||||
typedef lib::mutex mutex_type;
|
||||
typedef lib::lock_guard<mutex_type> scoped_lock_type;
|
||||
typedef lib::lock_guard<mutex_type> scoped_lock_type;
|
||||
};
|
||||
|
||||
} // namespace concurrency
|
||||
} // namespace websocketpp
|
||||
|
||||
#endif // WEBSOCKETPP_CONCURRENCY_BASIC_HPP
|
||||
#endif // WEBSOCKETPP_CONCURRENCY_BASIC_HPP
|
||||
@@ -11,10 +11,10 @@
|
||||
* * 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
|
||||
*
|
||||
* 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;
|
||||
@@ -22,7 +22,7 @@
|
||||
* 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_CONCURRENCY_NONE_HPP
|
||||
|
||||
Loaded 100 of 164 files, more files were not shown because too many files have changed in this diff.
Show more
Reference in new issue
Block a user