Skip to content
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ using websocketpp::lib::bind;

using websocketpp::lib::thread;
using websocketpp::lib::mutex;
using websocketpp::lib::unique_lock;
using websocketpp::lib::lock_guard;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is part of the vendored copy of websocketpp, so we should avoid modifying it.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see, I'll revert changes in this example.

using websocketpp::lib::condition_variable;

/* on_open insert connection_hdl into channel
Expand Down Expand Up @@ -71,15 +71,15 @@ class broadcast_server {
}

void on_open(connection_hdl hdl) {
unique_lock<mutex> lock(m_action_lock);
lock_guard<mutex> lock(m_action_lock);
//std::cout << "on_open" << std::endl;
m_actions.push(action(SUBSCRIBE,hdl));
lock.unlock();
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmmm apparently this isn't built?

m_action_cond.notify_one();
}

void on_close(connection_hdl hdl) {
unique_lock<mutex> lock(m_action_lock);
lock_guard<mutex> lock(m_action_lock);
//std::cout << "on_close" << std::endl;
m_actions.push(action(UNSUBSCRIBE,hdl));
lock.unlock();
Expand All @@ -88,7 +88,7 @@ class broadcast_server {

void on_message(connection_hdl hdl, server::message_ptr msg) {
// queue message up for sending by processing thread
unique_lock<mutex> lock(m_action_lock);
lock_guard<mutex> lock(m_action_lock);
//std::cout << "on_message" << std::endl;
m_actions.push(action(MESSAGE,hdl,msg));
lock.unlock();
Expand All @@ -97,7 +97,7 @@ class broadcast_server {

void process_messages() {
while(1) {
unique_lock<mutex> lock(m_action_lock);
lock_guard<mutex> lock(m_action_lock);

while(m_actions.empty()) {
m_action_cond.wait(lock);
Expand All @@ -109,13 +109,13 @@ class broadcast_server {
lock.unlock();

if (a.type == SUBSCRIBE) {
unique_lock<mutex> con_lock(m_connection_lock);
lock_guard<mutex> con_lock(m_connection_lock);
m_connections.insert(a.hdl);
} else if (a.type == UNSUBSCRIBE) {
unique_lock<mutex> con_lock(m_connection_lock);
lock_guard<mutex> con_lock(m_connection_lock);
m_connections.erase(a.hdl);
} else if (a.type == MESSAGE) {
unique_lock<mutex> con_lock(m_connection_lock);
lock_guard<mutex> con_lock(m_connection_lock);

con_list::iterator it;
for (it = m_connections.begin(); it != m_connections.end(); ++it) {
Expand Down
Loading