Browse Source

Better messages

master
Joshua Moerman 12 years ago
parent
commit
418d2fde0c
  1. 4
      src/main.cpp
  2. 4
      src/websockets.h

4
src/main.cpp

@ -20,10 +20,12 @@ websockets::TestProtocol<User> default_protocol{
// connection established
[](User& user, basic_websocket_info){
app->login(user);
std::cout << "New user!\n";
},
// connection closed
[](User& user, basic_websocket_info){
app->logout(user);
std::cout << "User left: " << &user << ": " << user.name << std::endl;
},
// write (will always come after receive)
[](User& user, basic_websocket_info) -> std::string{
@ -39,8 +41,10 @@ websockets::TestProtocol<User> default_protocol{
auto command = object["command"];
if(command == "add line"){
app->add_line(from_json<AbstractLine>(object["data"]));
std::cout << "Line from: " << &user << ": " << user.name << std::endl;
} else if (command == "update user") {
user = from_json<IncomingPacket>(object["data"]);
std::cout << "Updated user: " << &user << ": " << user.name << std::endl;
}
} catch(std::exception& e) {
throw websockets::runtime_error(e.what());

4
src/websockets.h

@ -124,12 +124,12 @@ namespace websockets {
try{
switch (reason) {
case LWS_CALLBACK_ESTABLISHED:
lwsl_notice("Connection established (%p, %p)\n", this, user_ptr);
if(verbose) lwsl_notice("Connection established (%p, %p)\n", this, user_ptr);
new (user_ptr) user_type();
establish_func(user, binfo);
break;
case LWS_CALLBACK_CLOSED:
lwsl_notice("Connection closed (%p, %p)\n", this, user_ptr);
if(verbose) lwsl_notice("Connection closed (%p, %p)\n", this, user_ptr);
user.~user_type();
close_func(user, binfo);
break;