Last active
January 4, 2017 21:58
-
-
Save abhiguru/68041ef47969bb63b7a375aee99d1c93 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | |
} | |
}); | |
} | |
... | |
} |
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
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