Joedb 10.2.1
The Journal-Only Embedded Database
Loading...
Searching...
No Matches
Server.h
Go to the documentation of this file.
1#ifndef joedb_Server_declared
2#define joedb_Server_declared
3
4#include "joedb/asio/Server.h"
6
7#include <deque>
8#include <map>
9#include <optional>
10
11namespace joedb
12{
13 /// @ingroup concurrency
15 {
16 private:
17 Client &client;
18 Writable_Journal_Client *writable_journal_client;
19 std::optional<Writable_Journal_Client_Lock> client_lock;
20
21 class Session: public joedb::asio::Server::Session
22 {
23 private:
24 const Server &get_server() const {return *(Server *)&server;}
25 Server &get_server() {return *(Server *)&server;}
26
27 boost::asio::steady_timer timer;
28 bool locking = false;
29
30 boost::asio::steady_timer lock_timeout_timer;
31 boost::asio::awaitable<void> lock();
32 void unlock();
33 void refresh_lock_timeout();
34
35 char push_status;
36 std::optional<joedb::Async_Writer> push_writer;
37
38 boost::asio::awaitable<void> send(Async_Reader reader);
39 boost::asio::awaitable<void> handshake();
40 boost::asio::awaitable<void> check_hash();
41 boost::asio::awaitable<void> read();
42 boost::asio::awaitable<void> pull(bool lock_before, bool send_data);
43 boost::asio::awaitable<void> push(bool unlock_after);
44
45 void remove_from_queue(std::deque<Session *> &queue);
46
47 public:
48 Session
49 (
51 boost::asio::local::stream_protocol::socket &&socket
52 );
53
54 boost::asio::awaitable<void> run() override;
55 void cleanup() override;
56 };
57
58 std::unique_ptr<joedb::asio::Server::Session> new_session
59 (
60 boost::asio::local::stream_protocol::socket &&socket
61 ) override
62 {
63 return std::make_unique<Session>(*this, std::move(socket));
64 }
65
66 const std::chrono::milliseconds lock_timeout;
67
68 bool locked;
69 std::deque<Session *> lock_waiters;
70 std::deque<Session *> pull_waiters;
71
72 static const std::map<char, const char *> request_description;
73
74 public:
75 Server
76 (
78 int log_level,
79 int thread_count,
80 std::string endpoint_path,
81 Client &client,
82 std::chrono::milliseconds lock_timeout
83 );
84
85 bool has_client_lock() const {return bool(client_lock);}
86 void cleanup_after_join() override;
87
89 };
90}
91
92#endif
Handle concurrent access to a file with a joedb::Connection.
Definition Client.h:12
void cleanup_after_join() override
Definition Server.cpp:549
bool has_client_lock() const
Definition Server.h:85
boost::asio::local::stream_protocol::socket socket
Definition Server.h:39
Superclass for asio servers.
Definition Server.h:19
const std::string endpoint_path
Definition Server.h:29
Logger & logger
Definition Server.h:21
const int thread_count
Definition Server.h:25
const int log_level
Definition Server.h:22