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