28#define BOOST_TEST_MODULE transport_integration
29#include <boost/test/unit_test.hpp>
134using websocketpp::lib::placeholders::_1;
135using websocketpp::lib::placeholders::_2;
136using websocketpp::lib::bind;
142 websocketpp::lib::error_code ec;
143 e.close(hdl,websocketpp::close::status::normal,
"",ec);
157 s->set_reuse_addr(
true);
172 websocketpp::lib::error_code ec;
174 c.set_reuse_addr(
true);
187 websocketpp::lib::lock_guard<websocketpp::lib::mutex>
lock(*mutex);
204 websocketpp::lib::error_code ec;
209 websocketpp::lib::thread tthread(websocketpp::lib::bind(
211 websocketpp::lib::ref(c),
221 using boost::asio::ip::tcp;
224 boost::asio::io_service io_service;
225 tcp::acceptor acceptor(io_service, tcp::endpoint(tcp::v6(), port));
226 tcp::socket socket(io_service);
228 acceptor.accept(socket);
231 boost::system::error_code ec;
232 socket.read_some(boost::asio::buffer(data), ec);
233 if (ec == boost::asio::error::eof) {
240 }
catch (std::exception & e) {
241 std::cout << e.what() << std::endl;
242 }
catch (boost::system::error_code & ec) {
243 std::cout << ec.message() << std::endl;
248 using boost::asio::ip::tcp;
251 boost::asio::io_service io_service;
252 tcp::resolver resolver(io_service);
253 tcp::resolver::query query(
"localhost", port);
254 tcp::resolver::iterator iterator = resolver.resolve(query);
255 tcp::socket socket(io_service);
257 boost::asio::connect(socket, iterator);
260 boost::system::error_code ec;
261 socket.read_some(boost::asio::buffer(data), ec);
262 if (ec == boost::asio::error::eof) {
269 }
catch (std::exception & e) {
270 std::cout << e.what() << std::endl;
271 }
catch (boost::system::error_code & ec) {
272 std::cout << ec.message() << std::endl;
294 typename T::connection_ptr con = c->get_con_from_hdl(hdl);
295 websocketpp::lib::error_code ec;
296 con->ping(payload,ec);
297 BOOST_CHECK_EQUAL(ec, websocketpp::lib::error_code());
301 BOOST_FAIL(
"expected no pong handler" );
305 BOOST_FAIL(
"expected no pong timeout" );
311 BOOST_CHECK_EQUAL( expected_payload, payload );
315 BOOST_FAIL(
"expected no open handler" );
326 typename T::connection_ptr con = c->get_con_from_hdl(hdl);
327 BOOST_CHECK_EQUAL( con->get_ec(), ec );
336 typename T::connection_ptr con = e->get_con_from_hdl(hdl);
337 BOOST_CHECK_EQUAL( con->get_ec(), ec );
347 typename T::connection_ptr con = c->get_con_from_hdl(hdl);
348 BOOST_CHECK_EQUAL( payload, expected_payload );
349 con->close(websocketpp::close::status::normal,
"");
354 e->get_con_from_hdl(hdl)->close(websocketpp::close::status::normal,
"");
360 BOOST_FAIL(
"Test timed out" );
376 websocketpp::lib::thread sthread(websocketpp::lib::bind(&
run_server,&
s,9005,
false));
392 websocketpp::lib::error_code(),::_1));
398 websocketpp::lib::error_code(),::_1));
400 websocketpp::lib::thread sthread(websocketpp::lib::bind(&
run_server,&
s,9005,
false));
401 websocketpp::lib::thread tthread(websocketpp::lib::bind(&
run_test_timer,10));
418 websocketpp::lib::thread sthread(websocketpp::lib::bind(&
run_dummy_server,9005));
419 websocketpp::lib::thread tthread(websocketpp::lib::bind(&
run_test_timer,10));
435 websocketpp::lib::thread sthread(websocketpp::lib::bind(&
run_server,&
s,9005,
false));
436 websocketpp::lib::thread tthread(websocketpp::lib::bind(&
run_test_timer,10));
458 websocketpp::lib::thread sthread(websocketpp::lib::bind(&
run_server,&
s,9005,
false));
459 websocketpp::lib::thread tthread(websocketpp::lib::bind(&
run_test_timer,10));
462 run_client(c,
"http://localhost:9005",
false);
490 websocketpp::lib::thread sthread(websocketpp::lib::bind(&
run_server,&
s,9005,
false));
491 websocketpp::lib::thread tthread(websocketpp::lib::bind(&
run_test_timer,10));
502 websocketpp::lib::thread tthread(websocketpp::lib::bind(&
run_test_timer,3));
505 websocketpp::lib::error_code ec;
521 websocketpp::lib::mutex mutex;
523 websocketpp::lib::error_code ec;
529 websocketpp::lib::thread cthread(websocketpp::lib::bind(&
run_client_and_mark,&c,&flag,&mutex));
535 websocketpp::lib::lock_guard<websocketpp::lib::mutex>
lock(mutex);
536 BOOST_CHECK( !flag );
545 websocketpp::lib::lock_guard<websocketpp::lib::mutex>
lock(mutex);
568 websocketpp::lib::thread sthread(websocketpp::lib::bind(&
run_server,&
s,9005,
false));
569 websocketpp::lib::thread tthread(websocketpp::lib::bind(&
run_test_timer,5));
579 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";
580 char buffer[2] = { char(0x81), char(0x80) };
583 std::stringstream null_output;
584 s.register_ostream(&null_output);
590 BOOST_CHECK_EQUAL( con->read_some(handshake.data(), handshake.length()), handshake.length());
597 con->pause_reading();
598 BOOST_CHECK_EQUAL( con->read_some(buffer, 1), 1);
599 BOOST_CHECK_EQUAL( con->read_some(buffer+1, 1), 0);
602 con->resume_reading();
603 BOOST_CHECK_EQUAL( con->read_some(buffer+1, 1), 1);
611#ifdef _WEBSOCKETPP_MOVE_SEMANTICS_
base::response_type response_type
base::endpoint_msg_manager_type endpoint_msg_manager_type
websocketpp::config::asio base
base::request_type request_type
static const long timeout_pong
Length of time to wait for a pong after a ping.
base::alog_type alog_type
websocketpp::transport::asio::endpoint< transport_config > transport_type
static const long timeout_open_handshake
Length of time before an opening handshake is aborted.
static const long timeout_close_handshake
Length of time before a closing handshake is aborted.
base::message_type message_type
base::concurrency_type concurrency_type
base::elog_type elog_type
base::con_msg_manager_type con_msg_manager_type
Client endpoint role based on the given config.
connection_ptr connect(connection_ptr con)
Begin the connection process for the given connection.
connection_ptr get_connection(uri_ptr location, lib::error_code &ec)
Get a new connection.
connection_type::ptr connection_ptr
Concurrency policy that uses std::mutex / boost::mutex.
Stub concurrency policy that implements the interface using no-ops.
void set_pong_timeout_handler(pong_timeout_handler h)
void set_fail_handler(fail_handler h)
alog_type & get_alog()
Get reference to access logger.
void clear_access_channels(log::level channels)
Clear Access logging channels.
void set_open_handler(open_handler h)
void set_access_channels(log::level channels)
Set Access logging channel.
void set_error_channels(log::level channels)
Set Error logging channel.
void set_pong_handler(pong_handler h)
void clear_error_channels(log::level channels)
Clear Error logging channels.
void set_close_handler(close_handler h)
void set_ping_handler(ping_handler h)
Stores, parses, and manipulates HTTP requests.
Stores, parses, and manipulates HTTP responses.
Basic logger that outputs to an ostream.
Stub logger that ignores all input.
Represents a buffer for a single WebSocket message.
Thread safe stub "random" integer generator.
Server endpoint role based on the given config.
connection_ptr get_connection()
Create and initialize a new connection.
connection_type::ptr connection_ptr
Basic ASIO endpoint socket component.
Asio based endpoint transport component.
void stop_on_close(server *s, websocketpp::connection_hdl hdl)
void req_pong_timeout(T *c, std::string expected_payload, websocketpp::connection_hdl hdl, std::string payload)
void run_client(client &c, std::string uri, bool log=false)
websocketpp::client< websocketpp::config::core_client > iostream_client
void run_test_timer(long value)
BOOST_AUTO_TEST_CASE(pong_no_timeout)
void close_after_timeout(T &e, websocketpp::connection_hdl hdl, long timeout)
void fail_on_open(websocketpp::connection_hdl)
void cancel_on_open(server *s, websocketpp::connection_hdl)
void check_ec(T *c, websocketpp::lib::error_code ec, websocketpp::connection_hdl hdl)
websocketpp::server< config_tls > server_tls
websocketpp::client< config_tls > client_tls
void ping_on_open(T *c, std::string payload, websocketpp::connection_hdl hdl)
void delay(websocketpp::connection_hdl, long duration)
websocketpp::server< config > server
websocketpp::server< websocketpp::config::core > iostream_server
void run_dummy_client(std::string port)
void run_server(server *s, int port, bool log=false)
bool on_ping(server *s, websocketpp::connection_hdl, std::string)
void fail_on_pong_timeout(websocketpp::connection_hdl, std::string)
void run_time_limited_client(client &c, std::string uri, long timeout, bool log)
void check_ec_and_stop(T *e, websocketpp::lib::error_code ec, websocketpp::connection_hdl hdl)
void run_dummy_server(int port)
void run_client_and_mark(client *c, bool *flag, websocketpp::lib::mutex *mutex)
void fail_on_pong(websocketpp::connection_hdl, std::string)
void close(T *e, websocketpp::connection_hdl hdl)
void req_pong(std::string expected_payload, websocketpp::connection_hdl, std::string payload)
websocketpp::client< config > client
@ close_handshake_timeout
WebSocket close handshake timed out.
@ open_handshake_timeout
WebSocket opening handshake timed out.
lib::weak_ptr< void > connection_hdl
A handle to uniquely identify a connection.
#define T(meth, val, expected)
type::concurrency_type concurrency_type
websocketpp::transport::asio::basic_socket::endpoint socket_type
type::request_type request_type
type::alog_type alog_type
type::elog_type elog_type
type::response_type response_type
websocketpp::transport::asio::basic_socket::endpoint socket_type
type::elog_type elog_type
type::response_type response_type
type::concurrency_type concurrency_type
type::alog_type alog_type
type::request_type request_type
static const long timeout_open_handshake
Length of time before an opening handshake is aborted.
base::endpoint_msg_manager_type endpoint_msg_manager_type
base::response_type response_type
static const long timeout_close_handshake
Length of time before a closing handshake is aborted.
base::concurrency_type concurrency_type
base::alog_type alog_type
base::con_msg_manager_type con_msg_manager_type
websocketpp::config::asio base
websocketpp::transport::asio::endpoint< transport_config > transport_type
base::elog_type elog_type
static const long timeout_pong
Length of time to wait for a pong after a ping.
base::message_type message_type
base::request_type request_type
Client config with asio transport and TLS disabled.
Client config with asio transport and TLS enabled.
Server config with asio transport and TLS disabled.
static level const all
Special aggregate value representing "all levels".
static level const app
Special channel for application specific logs. Not used by the library.
static level const all
Special aggregate value representing "all levels".