main: :ohno: linked to libcurl and did a webconnect
Signed-off-by: Vincent Batts <vbatts@hashbangbash.com>
This commit is contained in:
parent
98ec9e2a9c
commit
7628ecc915
3 changed files with 35 additions and 2 deletions
21
main.cpp
21
main.cpp
|
@ -21,6 +21,8 @@
|
|||
#include <cstdlib>
|
||||
#include <cassert>
|
||||
|
||||
#include <curl/curl.h>
|
||||
|
||||
#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;
|
||||
|
|
|
@ -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],
|
||||
)
|
||||
|
|
12
worker.h
12
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<std::mutex> lock(this->mtx);
|
||||
this->ready = true;
|
||||
|
@ -42,6 +51,7 @@ class Worker {
|
|||
}
|
||||
|
||||
private:
|
||||
int timeout;
|
||||
std::mutex mtx;
|
||||
std::condition_variable cv;
|
||||
bool ready;
|
||||
|
|
Loading…
Add table
Reference in a new issue