From 7628ecc915c151339588850361a8bea4c46bace0 Mon Sep 17 00:00:00 2001 From: Vincent Batts Date: Mon, 10 Feb 2025 17:58:07 -0500 Subject: [PATCH] main: :ohno: linked to libcurl and did a webconnect Signed-off-by: Vincent Batts --- main.cpp | 21 +++++++++++++++++++++ meson.build | 4 +++- worker.h | 12 +++++++++++- 3 files changed, 35 insertions(+), 2 deletions(-) diff --git a/main.cpp b/main.cpp index c2cffa4..5bf289b 100644 --- a/main.cpp +++ b/main.cpp @@ -21,6 +21,8 @@ #include #include +#include + #include "./common.h" #include "./account.h" #include "./worker.h" @@ -53,13 +55,32 @@ void scoped_account() { delete account; } +void webtest() { + log_out("begin webtest"); + + CURL* c = curl_easy_init(); + if (c) { + CURLcode res; + curl_easy_setopt(c, CURLOPT_URL, "https://hashbangbash.com/"); + res = curl_easy_perform(c); + curl_easy_cleanup(c); + if (res==CURLE_OK) { + log_out("connected to hashbangbash.com"); + } + } + + log_out("end webtest"); +} int main(int argc, char* argv[]) { int ret; scoped_account(); + webtest(); + Dang::Worker worker; + worker.setTimeout(1); ret = worker.work(); if (ret != 0) { std::cout << "worker failed" << std::endl; diff --git a/meson.build b/meson.build index 284e683..5492a76 100644 --- a/meson.build +++ b/meson.build @@ -3,7 +3,8 @@ project('tmp.c', 'cpp', 'c', license: 'MIT' ) -a = run_command('date', check: true) +curl_dep = dependency('libcurl', version : '>=8.0.0') +curl_libs = run_command('curl-config', '--libs', check: true).stdout().strip() read_exe = executable('read', 'read.c', link_language : 'c',) readpp_exe = executable('read++', 'read++.cpp') @@ -18,4 +19,5 @@ account_sources = [ ] account_exe = executable('account', account_sources, cpp_args: ['-std=c++23'], + link_args : [curl_libs], ) diff --git a/worker.h b/worker.h index 13557b2..878a6dc 100644 --- a/worker.h +++ b/worker.h @@ -18,6 +18,7 @@ class Worker { public: Worker() { this->ready = false; + this->timeout = 5; } void run() { @@ -27,10 +28,18 @@ class Worker { std::cout << "Daemon process woke up!" << std::endl; } + int getTimeout() { + return this->timeout; + } + + void setTimeout(int t) { + this->timeout = t; + } + int work() { std::thread daemon([this] {this->run();}); - std::this_thread::sleep_for(std::chrono::seconds(5)); + std::this_thread::sleep_for(std::chrono::seconds(this->timeout)); { std::lock_guard lock(this->mtx); this->ready = true; @@ -42,6 +51,7 @@ class Worker { } private: + int timeout; std::mutex mtx; std::condition_variable cv; bool ready;