28 #define BOOST_TEST_MODULE transport_integration 29 #include <boost/test/unit_test.hpp> 134 using websocketpp::lib::placeholders::_1;
135 using websocketpp::lib::placeholders::_2;
136 using websocketpp::lib::bind;
138 template <
typename T>
142 websocketpp::lib::error_code ec;
172 websocketpp::lib::error_code ec;
187 websocketpp::lib::lock_guard<websocketpp::lib::mutex> lock(*mutex);
204 websocketpp::lib::error_code ec;
209 websocketpp::lib::thread tthread(websocketpp::lib::bind(
210 &close_after_timeout<client>,
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));
228 acceptor.accept(socket);
231 boost::system::error_code ec;
232 socket.read_some(boost::asio::buffer(data), ec);
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);
257 boost::asio::connect(socket, iterator);
260 boost::system::error_code ec;
261 socket.read_some(boost::asio::buffer(data), ec);
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;
292 template <
typename T>
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" );
322 template <
typename T>
323 void check_ec(T * c, websocketpp::lib::error_code ec,
327 BOOST_CHECK_EQUAL( con->get_ec(), ec );
332 template <
typename T>
337 BOOST_CHECK_EQUAL( con->get_ec(), ec );
343 template <
typename T>
348 BOOST_CHECK_EQUAL( payload, expected_payload );
352 template <
typename T>
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_ 617 #endif // _WEBSOCKETPP_MOVE_SEMANTICS_ static level const all
Special aggregate value representing "all levels".
connection_type::ptr connection_ptr
Type of a shared pointer to the connections this server will create.
static const long timeout_open_handshake
Length of time before an opening handshake is aborted.
base::message_type message_type
base::response_type response_type
Asio based endpoint transport component.
void write(level, std::string const &)
Write a string message to the given channel.
void set_pong_timeout_handler(pong_timeout_handler h)
Client config with asio transport and TLS enabled.
void fail_on_pong(websocketpp::connection_hdl, std::string)
type::response_type response_type
void set_open_handler(open_handler h)
type::concurrency_type concurrency_type
type::request_type request_type
void fail_on_pong_timeout(websocketpp::connection_hdl, std::string)
static level const app
Special channel for application specific logs. Not used by the library.
websocketpp::config::asio base
base::request_type request_type
void set_reuse_addr(bool value)
Sets whether to use the SO_REUSEADDR flag when opening listening sockets.
static const long timeout_pong
Length of time to wait for a pong after a ping.
Client endpoint role based on the given config.
Concurrency policy that uses std::mutex / boost::mutex.
base::con_msg_manager_type con_msg_manager_type
base::response_type response_type
websocketpp::transport::asio::endpoint< transport_config > transport_type
static value const normal
Normal closure, meaning that the purpose for which the connection was established has been fulfilled...
lib::weak_ptr< void > connection_hdl
A handle to uniquely identify a connection.
alog_type & get_alog()
Get reference to access logger.
base::elog_type elog_type
base::concurrency_type concurrency_type
connection_ptr get_con_from_hdl(connection_hdl hdl, lib::error_code &ec)
Retrieves a connection_ptr from a connection_hdl (exception free)
void run_time_limited_client(client &c, std::string uri, long timeout, bool log)
void set_ping_handler(ping_handler h)
void set_close_handler(close_handler h)
type::request_type request_type
connection_ptr connect(connection_ptr con)
Begin the connection process for the given connection.
websocketpp::transport::asio::endpoint< transport_config > transport_type
Stores, parses, and manipulates HTTP responses.
base::alog_type alog_type
websocketpp::transport::asio::basic_socket::endpoint socket_type
void init_asio(io_service_ptr ptr, lib::error_code &ec)
initialize asio transport with external io_service (exception free)
Table::const_iterator iterator
type::concurrency_type concurrency_type
void run_dummy_server(int port)
void stop_perpetual()
Clears the endpoint's perpetual flag, allowing it to exit when empty.
type::response_type response_type
type::alog_type alog_type
void req_pong(std::string expected_payload, websocketpp::connection_hdl, std::string payload)
void req_pong_timeout(T *c, std::string expected_payload, websocketpp::connection_hdl hdl, std::string payload)
Basic logger that outputs to an ostream.
websocketpp::client< config > client
base::endpoint_msg_manager_type endpoint_msg_manager_type
type::elog_type elog_type
websocketpp::client< websocketpp::config::core_client > iostream_client
void stop_on_close(server *s, websocketpp::connection_hdl hdl)
void start_accept(lib::error_code &ec)
Starts the server's async connection acceptance loop (exception free)
base::endpoint_msg_manager_type endpoint_msg_manager_type
Server endpoint role based on the given config.
Thread safe stub "random" integer generator.
void set_pong_handler(pong_handler h)
void clear_error_channels(log::level channels)
Clear Error logging channels.
void set_access_channels(log::level channels)
Set Access logging channel.
void delay(websocketpp::connection_hdl, long duration)
Represents a buffer for a single WebSocket message.
Stub concurrency policy that implements the interface using no-ops.
void close(T *e, websocketpp::connection_hdl hdl)
base::request_type request_type
Basic ASIO endpoint socket component.
void set_fail_handler(fail_handler h)
base::con_msg_manager_type con_msg_manager_type
void stop_listening(lib::error_code &ec)
Stop listening (exception free)
void run_client(client &c, std::string uri, bool log=false)
websocketpp::server< websocketpp::config::core > iostream_server
websocketpp::config::asio base
websocketpp::server< config > server
base::concurrency_type concurrency_type
WebSocket close handshake timed out.
connection_ptr get_connection()
Create and initialize a new connection.
type::alog_type alog_type
websocketpp::client< config_tls > client_tls
void clear_access_channels(log::level channels)
Clear Access logging channels.
base::elog_type elog_type
base::message_type message_type
void stop()
wraps the stop method of the internal io_service object
void check_ec(T *c, websocketpp::lib::error_code ec, websocketpp::connection_hdl hdl)
void set_error_channels(log::level channels)
Set Error logging channel.
Stores, parses, and manipulates HTTP requests.
connection_type::ptr connection_ptr
Type of a shared pointer to the connections this server will create.
bool on_ping(server *s, websocketpp::connection_hdl, std::string)
client::connection_ptr connection_ptr
std::size_t run()
wraps the run method of the internal io_service object
void run_client_and_mark(client *c, bool *flag, websocketpp::lib::mutex *mutex)
websocketpp::server< config_tls > server_tls
type::elog_type elog_type
Catch-all error for socket component errors that don't fit in other categories.
WebSocket opening handshake timed out.
void listen(lib::asio::ip::tcp::endpoint const &ep, lib::error_code &ec)
Set up endpoint for listening manually (exception free)
void close_after_timeout(T &e, websocketpp::connection_hdl hdl, long timeout)
void check_ec_and_stop(T *e, websocketpp::lib::error_code ec, websocketpp::connection_hdl hdl)
void fail_on_open(websocketpp::connection_hdl)
base::alog_type alog_type
Client config with asio transport and TLS disabled.
static const long timeout_close_handshake
Length of time before a closing handshake is aborted.
void run_server(server *s, int port, bool log=false)
A connection message manager that allocates a new message for each request.
void ping_on_open(T *c, std::string payload, websocketpp::connection_hdl hdl)
void run_dummy_client(std::string port)
An endpoint message manager that allocates a new manager for each connection.
static level const all
Special aggregate value representing "all levels".
Stub logger that ignores all input.
connection_ptr get_connection(uri_ptr location, lib::error_code &ec)
Get a new connection.
websocketpp::transport::asio::basic_socket::endpoint socket_type
Server config with asio transport and TLS disabled.
void cancel_on_open(server *s, websocketpp::connection_hdl)
void start_perpetual()
Marks the endpoint as perpetual, stopping it from exiting when empty.
BOOST_AUTO_TEST_CASE(pong_no_timeout)
void run_test_timer(long value)