//application_main.cpp
//Application that starts tor in a new thread in the same process
#include <future>
#include <iostream>
#include "libtor.h"
using namespace std;
int main(int argc, char *argv[]){
auto tor_return=async(launch::async,start_tor_main,argc, argv);
while (tor_return.wait_for(chrono::seconds(2))!=future_status::ready){
char *ans;
const char *errmsg;
handle_getinfo_helper(NULL, "config/names", &ans, &errmsg);
cout<<"application is running! ["<<ans<<"]"<<endl;
}
return tor_return.get();
}
//libtor.h
//Duplicates the definitions in Tor. If there is a way around this, do tell! :)
extern "C"{
int start_tor_main(int argc, char *argv[]);//Tor's main() is renamed to start_tor_main
int
handle_getinfo_helper(void *control_conn,
const char *question, char **answer,
const char **err_out);
}
It seems like handle_getinfo_helper is called asynchronously by tor whenever a GETINFO is recieved on the control port so I don't need locking/synchronization. Can someone confirm this?