mirror of
https://github.com/mii443/libdatachannel.git
synced 2025-08-22 15:15:28 +00:00
Added optional preloading
This commit is contained in:
@ -31,6 +31,7 @@ using init_token = std::shared_ptr<Init>;
|
||||
class Init {
|
||||
public:
|
||||
static init_token Token();
|
||||
static void Preload();
|
||||
static void Cleanup();
|
||||
|
||||
~Init();
|
||||
@ -43,6 +44,7 @@ private:
|
||||
static std::mutex Mutex;
|
||||
};
|
||||
|
||||
inline void Preload() { Init::Preload(); }
|
||||
inline void Cleanup() { Init::Cleanup(); }
|
||||
|
||||
} // namespace rtc
|
||||
|
@ -61,7 +61,7 @@ string make_fingerprint(X509 *x509);
|
||||
using certificate_ptr = std::shared_ptr<Certificate>;
|
||||
using future_certificate_ptr = std::shared_future<certificate_ptr>;
|
||||
|
||||
future_certificate_ptr make_certificate(string commonName); // cached
|
||||
future_certificate_ptr make_certificate(string commonName = "libdatachannel"); // cached
|
||||
|
||||
void CleanupCertificateCache();
|
||||
|
||||
|
@ -55,6 +55,11 @@ init_token Init::Token() {
|
||||
return Global;
|
||||
}
|
||||
|
||||
void Init::Preload() {
|
||||
Token(); // pre-init
|
||||
make_certificate().wait(); // preload certificate
|
||||
}
|
||||
|
||||
void Init::Cleanup() { Global.reset(); }
|
||||
|
||||
Init::Init() {
|
||||
|
@ -39,7 +39,7 @@ using std::weak_ptr;
|
||||
PeerConnection::PeerConnection() : PeerConnection(Configuration()) {}
|
||||
|
||||
PeerConnection::PeerConnection(const Configuration &config)
|
||||
: mConfig(config), mCertificate(make_certificate("libdatachannel")), mState(State::New),
|
||||
: mConfig(config), mCertificate(make_certificate()), mState(State::New),
|
||||
mGatheringState(GatheringState::New) {
|
||||
PLOG_VERBOSE << "Creating PeerConnection";
|
||||
}
|
||||
|
@ -183,10 +183,13 @@ size_t benchmark(milliseconds duration) {
|
||||
#ifdef BENCHMARK_MAIN
|
||||
int main(int argc, char **argv) {
|
||||
try {
|
||||
rtc::Preload();
|
||||
|
||||
size_t goodput = benchmark(30s);
|
||||
if (goodput == 0)
|
||||
throw runtime_error("No data received");
|
||||
|
||||
rtc::Cleanup();
|
||||
return 0;
|
||||
|
||||
} catch (const std::exception &e) {
|
||||
|
Reference in New Issue
Block a user