forked from boostorg/beast
Add CppCon2018 chat server example and video
This commit is contained in:
41
example/cppcon2018/shared_state.cpp
Normal file
41
example/cppcon2018/shared_state.cpp
Normal file
@@ -0,0 +1,41 @@
|
||||
//
|
||||
// Copyright (c) 2018 Vinnie Falco (vinnie dot falco at gmail dot com)
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0. (See accompanying
|
||||
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||
//
|
||||
// Official repository: https://github.com/vinniefalco/CppCon2018
|
||||
//
|
||||
|
||||
#include "shared_state.hpp"
|
||||
#include "websocket_session.hpp"
|
||||
|
||||
shared_state::
|
||||
shared_state(std::string doc_root)
|
||||
: doc_root_(std::move(doc_root))
|
||||
{
|
||||
}
|
||||
|
||||
void
|
||||
shared_state::
|
||||
join(websocket_session& session)
|
||||
{
|
||||
sessions_.insert(&session);
|
||||
}
|
||||
|
||||
void
|
||||
shared_state::
|
||||
leave(websocket_session& session)
|
||||
{
|
||||
sessions_.erase(&session);
|
||||
}
|
||||
|
||||
void
|
||||
shared_state::
|
||||
send(std::string message)
|
||||
{
|
||||
auto const ss = std::make_shared<std::string const>(std::move(message));
|
||||
|
||||
for(auto session : sessions_)
|
||||
session->send(ss);
|
||||
}
|
||||
Reference in New Issue
Block a user