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

Yup, I mistakenly pasted an older version of the code, As per your example in the original bug I moved it into a threadlocal member of the class and sharing it in the lambda and there is def a considerable drop in memory usage, I am just using the HTTPClient at the moment will check out the example thanks again for the quick response!

Anyone else who might come looking for the timer issue revs with the timer in lamba code here https://gist.github.com/abhiguru/68041ef47969bb63b7a375aee99d1c93/revisions

@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