Line data Source code
1 : #include <iostream>
2 : #include "socket.hpp"
3 :
4 : namespace thinger::asio {
5 :
6 : std::atomic<unsigned long> socket::connections(0);
7 :
8 769740 : socket::socket(const std::string& context, boost::asio::io_context& io_context)
9 769740 : : context_(context), io_context_(io_context) {
10 769740 : ++connections;
11 769740 : std::lock_guard<std::mutex> lock(mutex_);
12 769740 : context_count[context_]++;
13 769740 : }
14 :
15 769740 : socket::~socket() {
16 769740 : --connections;
17 769740 : std::lock_guard<std::mutex> lock(mutex_);
18 769740 : if (--context_count[context_] == 0) {
19 5966 : context_count.erase(context_);
20 : }
21 769740 : }
22 :
23 5624 : boost::asio::io_context& socket::get_io_context() const {
24 5624 : return io_context_;
25 : }
26 :
27 1788 : bool socket::requires_handshake() const {
28 1788 : return false;
29 : }
30 :
31 0 : awaitable<boost::system::error_code> socket::handshake(const std::string& host) {
32 : co_return boost::system::error_code{};
33 0 : }
34 :
35 : std::map<std::string, unsigned long> socket::context_count;
36 : std::mutex socket::mutex_;
37 : }
|