Wire Sysio Wire Sysion 1.0.0
Loading...
Searching...
No Matches
timers.cpp File Reference
#include <boost/test/unit_test.hpp>
#include <exception>
#include <iostream>
#include <websocketpp/common/thread.hpp>
#include <websocketpp/transport/asio/endpoint.hpp>
#include <websocketpp/transport/asio/security/tls.hpp>
#include <websocketpp/concurrency/none.hpp>
#include <websocketpp/http/request.hpp>
#include <websocketpp/http/response.hpp>
#include <websocketpp/logger/stub.hpp>
#include <boost/asio.hpp>
Include dependency graph for timers.cpp:

Go to the source code of this file.

Classes

struct  config
 
struct  mock_con
 
struct  mock_endpoint
 

Macros

#define BOOST_TEST_MODULE   transport_asio_timers
 

Typedefs

typedef websocketpp::lib::shared_ptr< boost::asio::ssl::context > context_ptr
 
typedef websocketpp::transport::asio::connection< configcon_type
 
typedef websocketpp::lib::shared_ptr< mock_conconnection_ptr
 

Functions

void run_dummy_server (int port)
 
void run_test_timer (long value)
 
context_ptr on_tls_init (websocketpp::connection_hdl)
 
 BOOST_AUTO_TEST_CASE (tls_handshake_timeout)
 

Macro Definition Documentation

◆ BOOST_TEST_MODULE

#define BOOST_TEST_MODULE   transport_asio_timers

Definition at line 28 of file timers.cpp.

Typedef Documentation

◆ con_type

◆ connection_ptr

typedef websocketpp::lib::shared_ptr<mock_con> connection_ptr

Definition at line 136 of file timers.cpp.

◆ context_ptr

typedef websocketpp::lib::shared_ptr<boost::asio::ssl::context> context_ptr

Definition at line 109 of file timers.cpp.

Function Documentation

◆ BOOST_AUTO_TEST_CASE()

BOOST_AUTO_TEST_CASE ( tls_handshake_timeout )

Definition at line 177 of file timers.cpp.

177 {
178 websocketpp::lib::thread dummy_server(websocketpp::lib::bind(&run_dummy_server,9005));
179 websocketpp::lib::thread timer(websocketpp::lib::bind(&run_test_timer,5000));
180 dummy_server.detach();
181 timer.detach();
182
183 mock_endpoint endpoint;
184 endpoint.set_tls_init_handler(&on_tls_init);
185 endpoint.connect("wss://localhost:9005");
186 endpoint.run();
187}
std::size_t run()
wraps the run method of the internal io_service object
Definition endpoint.hpp:612
void connect(std::string u)
Definition timers.cpp:147
void run_test_timer(long value)
Definition timers.cpp:81
context_ptr on_tls_init(websocketpp::connection_hdl)
Definition timers.cpp:110
void run_dummy_server(int port)
Definition timers.cpp:53
Here is the call graph for this function:

◆ on_tls_init()

Definition at line 110 of file timers.cpp.

110 {
111 return context_ptr(new boost::asio::ssl::context(boost::asio::ssl::context::sslv23));
112}
websocketpp::lib::shared_ptr< boost::asio::ssl::context > context_ptr
Definition timers.cpp:109
Here is the caller graph for this function:

◆ run_dummy_server()

void run_dummy_server ( int port)

Definition at line 53 of file timers.cpp.

53 {
54 using boost::asio::ip::tcp;
55
56 try {
57 boost::asio::io_service io_service;
58 tcp::acceptor acceptor(io_service, tcp::endpoint(tcp::v6(), port));
59 tcp::socket socket(io_service);
60
61 acceptor.accept(socket);
62 for (;;) {
63 char data[512];
64 boost::system::error_code ec;
65 socket.read_some(boost::asio::buffer(data), ec);
66 if (ec == boost::asio::error::eof) {
67 break;
68 } else if (ec) {
69 // other error
70 throw ec;
71 }
72 }
73 } catch (std::exception & e) {
74 std::cout << e.what() << std::endl;
75 } catch (boost::system::error_code & ec) {
76 std::cout << ec.message() << std::endl;
77 }
78}
Here is the caller graph for this function:

◆ run_test_timer()

void run_test_timer ( long value)

Definition at line 81 of file timers.cpp.

81 {
82 boost::asio::io_service ios;
83 boost::asio::deadline_timer t(ios,boost::posix_time::milliseconds(value));
84 boost::system::error_code ec;
85 t.wait(ec);
86 BOOST_FAIL( "Test timed out" );
87}
#define value
Definition pkcs11.h:157
Here is the caller graph for this function: