Wire Sysio Wire Sysion 1.0.0
Loading...
Searching...
No Matches
debug_server.cpp File Reference
Include dependency graph for debug_server.cpp:

Go to the source code of this file.

Classes

struct  debug_custom
 
struct  debug_custom::transport_config
 

Typedefs

typedef websocketpp::server< debug_customserver
 
typedef server::message_ptr message_ptr
 

Functions

bool validate (server *, websocketpp::connection_hdl)
 
void on_http (server *s, websocketpp::connection_hdl hdl)
 
void on_fail (server *s, websocketpp::connection_hdl hdl)
 
void on_close (websocketpp::connection_hdl)
 
void on_message (server *s, websocketpp::connection_hdl hdl, message_ptr msg)
 
int main ()
 

Typedef Documentation

◆ message_ptr

Definition at line 94 of file debug_server.cpp.

◆ server

Definition at line 87 of file debug_server.cpp.

Function Documentation

◆ main()

int main ( void )

Definition at line 137 of file debug_server.cpp.

137 {
138 // Create a server endpoint
139 server echo_server;
140
141 try {
142 // Set logging settings
145
146 // Initialize ASIO
147 echo_server.init_asio();
148 echo_server.set_reuse_addr(true);
149
150 // Register our message handler
151 echo_server.set_message_handler(bind(&on_message,&echo_server,::_1,::_2));
152
153 echo_server.set_http_handler(bind(&on_http,&echo_server,::_1));
154 echo_server.set_fail_handler(bind(&on_fail,&echo_server,::_1));
155 echo_server.set_close_handler(&on_close);
156
157 echo_server.set_validate_handler(bind(&validate,&echo_server,::_1));
158
159 // Listen on port 9012
160 echo_server.listen(9012);
161
162 // Start the server accept loop
163 echo_server.start_accept();
164
165 // Start the ASIO io_service run loop
166 echo_server.run();
167 } catch (const std::exception & e) {
168 std::cout << e.what() << std::endl;
169 } catch (websocketpp::lib::error_code e) {
170 std::cout << e.message() << std::endl;
171 } catch (...) {
172 std::cout << "other exception" << std::endl;
173 }
174}
void set_fail_handler(fail_handler h)
Definition endpoint.hpp:287
void set_message_handler(message_handler h)
Definition endpoint.hpp:322
void clear_access_channels(log::level channels)
Clear Access logging channels.
Definition endpoint.hpp:231
void set_http_handler(http_handler h)
Definition endpoint.hpp:312
void set_access_channels(log::level channels)
Set Access logging channel.
Definition endpoint.hpp:220
void set_close_handler(close_handler h)
Definition endpoint.hpp:282
void set_validate_handler(validate_handler h)
Definition endpoint.hpp:317
void start_accept(lib::error_code &ec)
Starts the server's async connection acceptance loop (exception free)
void on_fail(server *s, websocketpp::connection_hdl hdl)
bool validate(server *, websocketpp::connection_hdl)
void on_message(server *s, websocketpp::connection_hdl hdl, message_ptr msg)
void on_close(websocketpp::connection_hdl)
void on_http(server *s, websocketpp::connection_hdl hdl)
static level const all
Special aggregate value representing "all levels".
Definition levels.hpp:152
static level const frame_payload
One line per frame, includes the full message payload (warning: chatty)
Definition levels.hpp:129
Here is the call graph for this function:

◆ on_close()

void on_close ( websocketpp::connection_hdl )

Definition at line 119 of file debug_server.cpp.

119 {
120 std::cout << "Close handler" << std::endl;
121}
Here is the caller graph for this function:

◆ on_fail()

void on_fail ( server * s,
websocketpp::connection_hdl hdl )

Definition at line 113 of file debug_server.cpp.

113 {
114 server::connection_ptr con = s->get_con_from_hdl(hdl);
115
116 std::cout << "Fail handler: " << con->get_ec() << " " << con->get_ec().message() << std::endl;
117}
char * s
Here is the caller graph for this function:

◆ on_http()

void on_http ( server * s,
websocketpp::connection_hdl hdl )

Definition at line 101 of file debug_server.cpp.

101 {
102 server::connection_ptr con = s->get_con_from_hdl(hdl);
103
104 std::string res = con->get_request_body();
105
106 std::stringstream ss;
107 ss << "got HTTP request with " << res.size() << " bytes of body data.";
108
109 con->set_body(ss.str());
110 con->set_status(websocketpp::http::status_code::ok);
111}
static const Segment ss(Segment::ss)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ on_message()

void on_message ( server * s,
websocketpp::connection_hdl hdl,
message_ptr msg )

Definition at line 124 of file debug_server.cpp.

124 {
125 std::cout << "on_message called with hdl: " << hdl.lock().get()
126 << " and message: " << msg->get_payload()
127 << std::endl;
128
129 try {
130 s->send(hdl, msg->get_payload(), msg->get_opcode());
131 } catch (const websocketpp::lib::error_code& e) {
132 std::cout << "Echo failed because: " << e
133 << "(" << e.message() << ")" << std::endl;
134 }
135}
Here is the caller graph for this function:

◆ validate()

bool validate ( server * ,
websocketpp::connection_hdl  )

Definition at line 96 of file debug_server.cpp.

96 {
97 //sleep(6);
98 return true;
99}
Here is the caller graph for this function: