mirror of
https://github.com/Expand-sys/CCash
synced 2026-03-22 12:37:08 +11:00
got web framework working
This commit is contained in:
parent
01bcd2d947
commit
769c0762f3
3 changed files with 25 additions and 10 deletions
|
|
@ -15,6 +15,7 @@ add_executable(${PROJECT_NAME} main.cpp)
|
|||
|
||||
target_include_directories(${PROJECT_NAME} PUBLIC include)
|
||||
target_include_directories(${PROJECT_NAME} PUBLIC third_party)
|
||||
target_include_directories(${PROJECT_NAME} PUBLIC third_party/drogon/lib/inc)
|
||||
|
||||
add_subdirectory(third_party/drogon)
|
||||
target_link_libraries(${PROJECT_NAME} PRIVATE drogon)
|
||||
|
|
|
|||
|
|
@ -16,6 +16,12 @@ private:
|
|||
std::mutex>
|
||||
users;
|
||||
|
||||
/**
|
||||
* @brief any function that WRITES to users in a way that CHANGES its SIZE OR takes MORE THEN ONE OPERATION must share lock this lock
|
||||
* as to be stopped when saving, as saving data must not be corrupted. one operation writes that done modify size aswell as reads are
|
||||
* permitted while saving so they do not have to share this lock
|
||||
*
|
||||
*/
|
||||
std::shared_mutex save_lock;
|
||||
|
||||
public:
|
||||
|
|
@ -54,7 +60,7 @@ public:
|
|||
{
|
||||
//if A exists, A can afford it, and A's password matches
|
||||
bool state = false;
|
||||
std::shared_lock<std::shared_mutex> lock{save_lock}; //because SendFunds is non-atomic, it requires 3 locking operations
|
||||
std::shared_lock<std::shared_mutex> lock{save_lock}; //because SendFunds requires 3 locking operations
|
||||
users.modify_if(a_name, [&state, amount, &attempt](User &a) {
|
||||
if (state = (a.balance >= amount) && (a.password == attempt), state)
|
||||
{
|
||||
|
|
|
|||
26
main.cpp
26
main.cpp
|
|
@ -3,7 +3,9 @@
|
|||
#include <thread>
|
||||
#include <sys/types.h>
|
||||
#include <unistd.h>
|
||||
#include "bank.hpp"
|
||||
#include "bank_f.hpp"
|
||||
|
||||
using namespace drogon;
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
|
|
@ -25,14 +27,20 @@ int main(int argc, char **argv)
|
|||
Bank.admin_pass = argv[1];
|
||||
|
||||
//Auto Saving
|
||||
volatile bool saving_flag = true;
|
||||
std::thread([&argv, &saving_flag]() {
|
||||
while (saving_flag)
|
||||
{
|
||||
std::this_thread::sleep_for(std::chrono::minutes(std::stoi(argv[2])));
|
||||
Bank.Save();
|
||||
}
|
||||
}).detach();
|
||||
const unsigned long saving_freq = std::stoul(argv[2]);
|
||||
if (saving_freq) //if saving frequency is 0 then auto saving is turned off
|
||||
{
|
||||
std::thread([&argv, saving_freq]() {
|
||||
while (1)
|
||||
{
|
||||
std::this_thread::sleep_for(std::chrono::minutes(saving_freq));
|
||||
Bank.Save();
|
||||
}
|
||||
}).detach();
|
||||
}
|
||||
|
||||
auto API = std::make_shared<BankFrontend>();
|
||||
app().addListener("0.0.0.0", 80).registerController(API).run();
|
||||
|
||||
return 0;
|
||||
}
|
||||
Loading…
Reference in a new issue