Skip to content

Instantly share code, notes, and snippets.

@abhiguru
Last active January 4, 2017 21:58
Show Gist options
  • Save abhiguru/68041ef47969bb63b7a375aee99d1c93 to your computer and use it in GitHub Desktop.
Save abhiguru/68041ef47969bb63b7a375aee99d1c93 to your computer and use it in GitHub Desktop.
int main(){
...
std::thread videoProcTH([&]{
EventBase evb;
ClassA *aclass = new ClassA(&evb);
evb.loopForever();
});
}
class classA{
...
classA::requestData(fbstring url, std::function<void(fbstring)> callback){
evb->runInEventBaseThread([=]() {
CurlClient *curlClient = new CurlClient(evb, fbcurl, callback);
HTTPConnector *connector_ = new HTTPConnector(curlClient, timer_.get());
static const AsyncSocket::OptionMap opts{{{SOL_SOCKET, SO_REUSEADDR}, 1}};
if (url.isSecure()) {
connector_->connectSSL(
evb, *addr, sslContext_, nullptr,
std::chrono::milliseconds(12000), opts,
folly::AsyncSocket::anyAddress(), curlClient->getServerName());
} else {
connector_->connect(evb, *addr, std::chrono::milliseconds(12000), opts);
}
});
}
...
}
@abhiguru
Copy link
Author

abhiguru commented Jan 4, 2017

Actually, there was another thread leading to the requestData which is why runInBaseThread was required.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment