-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebsocket_session.hpp
42 lines (31 loc) · 981 Bytes
/
websocket_session.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
#pragma once
#include "beast.hpp"
#include "shared_state.hpp"
#include <cstdlib>
#include <memory>
#include <string>
#include <vector>
#include <iostream>
// Forward declaration
class shared_state;
/** Represents an active WebSocket connection to the server
*/
class websocket_session : public std::enable_shared_from_this<websocket_session>
{
beast::flat_buffer buffer_;
websocket::stream<tcp::socket> ws_;
std::shared_ptr<shared_state> state_;
std::vector<std::shared_ptr<std::string const>> queue_;
void fail(error_code ec, char const* what);
void on_accept(error_code ec);
void on_read(error_code ec, std::size_t bytes_transferred);
void on_write(error_code ec, std::size_t bytes_transferred);
public:
websocket_session(
tcp::socket socket,
std::shared_ptr<shared_state> const& state);
~websocket_session();
void run();
// Send a message
void send(std::shared_ptr<std::string const> const& ss);
};