Wire Sysio Wire Sysion 1.0.0
Loading...
Searching...
No Matches
broadcast_server Class Reference

Public Member Functions

 broadcast_server ()
 
void on_open (connection_hdl hdl)
 
void on_close (connection_hdl hdl)
 
void on_message (connection_hdl hdl, server::message_ptr msg)
 
void run (uint16_t port)
 
 broadcast_server ()
 
void run (uint16_t port)
 
void on_open (connection_hdl hdl)
 
void on_close (connection_hdl hdl)
 
void on_message (connection_hdl hdl, server::message_ptr msg)
 
void process_messages ()
 
 broadcast_server ()
 
void on_open (connection_hdl hdl)
 
void on_close (connection_hdl hdl)
 
void on_message (connection_hdl hdl, server::message_ptr msg)
 
void run (uint16_t port)
 

Detailed Description

Definition at line 13 of file simple_broadcast_server.cpp.

Constructor & Destructor Documentation

◆ broadcast_server() [1/3]

broadcast_server::broadcast_server ( )
inline

Definition at line 15 of file simple_broadcast_server.cpp.

15 {
16 m_server.init_asio();
17
18 m_server.set_open_handler(bind(&broadcast_server::on_open,this,::_1));
19 m_server.set_close_handler(bind(&broadcast_server::on_close,this,::_1));
20 m_server.set_message_handler(bind(&broadcast_server::on_message,this,::_1,::_2));
21 }
void on_open(connection_hdl hdl)
void on_message(connection_hdl hdl, server::message_ptr msg)
void on_close(connection_hdl hdl)
void set_message_handler(message_handler h)
Definition endpoint.hpp:322
void set_open_handler(open_handler h)
Definition endpoint.hpp:277
void set_close_handler(close_handler h)
Definition endpoint.hpp:282
Here is the call graph for this function:

◆ broadcast_server() [2/3]

broadcast_server::broadcast_server ( )
inline

Definition at line 49 of file broadcast_server.cpp.

49 {
50 // Initialize Asio Transport
51 m_server.init_asio();
52
53 // Register handler callbacks
54 m_server.set_open_handler(bind(&broadcast_server::on_open,this,::_1));
55 m_server.set_close_handler(bind(&broadcast_server::on_close,this,::_1));
56 m_server.set_message_handler(bind(&broadcast_server::on_message,this,::_1,::_2));
57 }
Here is the call graph for this function:

◆ broadcast_server() [3/3]

broadcast_server::broadcast_server ( )
inline

Definition at line 14 of file simple_broadcast_server.cpp.

14 {
15 m_server.init_asio();
16
17 m_server.set_open_handler(bind(&broadcast_server::on_open,this,::_1));
18 m_server.set_close_handler(bind(&broadcast_server::on_close,this,::_1));
19 m_server.set_message_handler(bind(&broadcast_server::on_message,this,::_1,::_2));
20 }
Here is the call graph for this function:

Member Function Documentation

◆ on_close() [1/3]

void broadcast_server::on_close ( connection_hdl hdl)
inline

Definition at line 27 of file simple_broadcast_server.cpp.

27 {
28 m_connections.erase(hdl);
29 }
Here is the caller graph for this function:

◆ on_close() [2/3]

void broadcast_server::on_close ( connection_hdl hdl)
inline

Definition at line 83 of file broadcast_server.cpp.

83 {
84 {
85 lock_guard<mutex> guard(m_action_lock);
86 //std::cout << "on_close" << std::endl;
87 m_actions.push(action(UNSUBSCRIBE,hdl));
88 }
89 m_action_cond.notify_one();
90 }
@ UNSUBSCRIBE

◆ on_close() [3/3]

void broadcast_server::on_close ( connection_hdl hdl)
inline

Definition at line 26 of file simple_broadcast_server.cpp.

26 {
27 m_connections.erase(hdl);
28 }

◆ on_message() [1/3]

void broadcast_server::on_message ( connection_hdl hdl,
server::message_ptr msg )
inline

Definition at line 31 of file simple_broadcast_server.cpp.

31 {
32 for (auto it : m_connections) {
33 m_server.send(it,msg);
34 }
35 }
void send(connection_hdl hdl, std::string const &payload, frame::opcode::value op, lib::error_code &ec)
Create a message and add it to the outgoing send queue (exception free)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ on_message() [2/3]

void broadcast_server::on_message ( connection_hdl hdl,
server::message_ptr msg )
inline

Definition at line 92 of file broadcast_server.cpp.

92 {
93 // queue message up for sending by processing thread
94 {
95 lock_guard<mutex> guard(m_action_lock);
96 //std::cout << "on_message" << std::endl;
97 m_actions.push(action(MESSAGE,hdl,msg));
98 }
99 m_action_cond.notify_one();
100 }
@ MESSAGE

◆ on_message() [3/3]

void broadcast_server::on_message ( connection_hdl hdl,
server::message_ptr msg )
inline

Definition at line 30 of file simple_broadcast_server.cpp.

30 {
31 for (auto it : m_connections) {
32 m_server.send(it,msg);
33 }
34 }
Here is the call graph for this function:

◆ on_open() [1/3]

void broadcast_server::on_open ( connection_hdl hdl)
inline

Definition at line 23 of file simple_broadcast_server.cpp.

23 {
24 m_connections.insert(hdl);
25 }
Here is the caller graph for this function:

◆ on_open() [2/3]

void broadcast_server::on_open ( connection_hdl hdl)
inline

Definition at line 74 of file broadcast_server.cpp.

74 {
75 {
76 lock_guard<mutex> guard(m_action_lock);
77 //std::cout << "on_open" << std::endl;
78 m_actions.push(action(SUBSCRIBE,hdl));
79 }
80 m_action_cond.notify_one();
81 }
@ SUBSCRIBE

◆ on_open() [3/3]

void broadcast_server::on_open ( connection_hdl hdl)
inline

Definition at line 22 of file simple_broadcast_server.cpp.

22 {
23 m_connections.insert(hdl);
24 }

◆ process_messages()

void broadcast_server::process_messages ( )
inline

Definition at line 102 of file broadcast_server.cpp.

102 {
103 while(1) {
104 unique_lock<mutex> lock(m_action_lock);
105
106 while(m_actions.empty()) {
107 m_action_cond.wait(lock);
108 }
109
110 action a = m_actions.front();
111 m_actions.pop();
112
113 lock.unlock();
114
115 if (a.type == SUBSCRIBE) {
116 lock_guard<mutex> guard(m_connection_lock);
117 m_connections.insert(a.hdl);
118 } else if (a.type == UNSUBSCRIBE) {
119 lock_guard<mutex> guard(m_connection_lock);
120 m_connections.erase(a.hdl);
121 } else if (a.type == MESSAGE) {
122 lock_guard<mutex> guard(m_connection_lock);
123
124 con_list::iterator it;
125 for (it = m_connections.begin(); it != m_connections.end(); ++it) {
126 m_server.send(*it,a.msg);
127 }
128 } else {
129 // undefined.
130 }
131 }
132 }
const GenericPointer< typename T::ValueType > T2 T::AllocatorType & a
Definition pointer.h:1181
void lock()
Here is the call graph for this function:
Here is the caller graph for this function:

◆ run() [1/3]

void broadcast_server::run ( uint16_t port)
inline

Definition at line 37 of file simple_broadcast_server.cpp.

37 {
38 m_server.listen(port);
39 m_server.start_accept();
40 m_server.run();
41 }
void start_accept(lib::error_code &ec)
Starts the server's async connection acceptance loop (exception free)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ run() [2/3]

void broadcast_server::run ( uint16_t port)
inline

Definition at line 59 of file broadcast_server.cpp.

59 {
60 // listen on specified port
61 m_server.listen(port);
62
63 // Start the server accept loop
64 m_server.start_accept();
65
66 // Start the ASIO io_service run loop
67 try {
68 m_server.run();
69 } catch (const std::exception & e) {
70 std::cout << e.what() << std::endl;
71 }
72 }
Here is the call graph for this function:

◆ run() [3/3]

void broadcast_server::run ( uint16_t port)
inline

Definition at line 36 of file simple_broadcast_server.cpp.

36 {
37 m_server.listen(port);
38 m_server.start_accept();
39 m_server.run();
40 }
Here is the call graph for this function:

The documentation for this class was generated from the following files: