diff --git a/include/rtc/rtc.h b/include/rtc/rtc.h index eee499f..66c009d 100644 --- a/include/rtc/rtc.h +++ b/include/rtc/rtc.h @@ -114,6 +114,9 @@ int rtcGetAvailableAmount(int dc); // total size available to receive int rtcSetAvailableCallback(int dc, availableCallbackFunc cb); int rtcReceiveMessage(int dc, char *buffer, int *size); +// Cleanup +void rtcCleanup(); + #ifdef __cplusplus } // extern "C" #endif diff --git a/src/rtc.cpp b/src/rtc.cpp index 2746cc1..93ba20d 100644 --- a/src/rtc.cpp +++ b/src/rtc.cpp @@ -450,3 +450,5 @@ int rtcReceiveMessage(int dc, char *buffer, int *size) { *message); }); } + +void rtcCleanup() { rtc::Cleanup(); } diff --git a/src/sctptransport.cpp b/src/sctptransport.cpp index a19d5b1..af0b1c4 100644 --- a/src/sctptransport.cpp +++ b/src/sctptransport.cpp @@ -21,6 +21,7 @@ #include #include #include +#include #include #ifdef USE_JUICE @@ -62,7 +63,10 @@ void SctpTransport::Init() { usrsctp_sysctl_set_sctp_heartbeat_interval_default(10 * 1000); // ms } -void SctpTransport::Cleanup() { usrsctp_finish(); } +void SctpTransport::Cleanup() { + while (usrsctp_finish() != 0) + std::this_thread::sleep_for(100ms); +} SctpTransport::SctpTransport(std::shared_ptr lower, uint16_t port, message_callback recvCallback, amount_callback bufferedAmountCallback, diff --git a/test/capi.cpp b/test/capi.cpp index 52c745c..7670b6a 100644 --- a/test/capi.cpp +++ b/test/capi.cpp @@ -23,7 +23,12 @@ #include #include +#ifdef _WIN32 +#include +static void sleep(unsigned int secs) { Sleep(secs * 1000); } +#else #include // for sleep +#endif using namespace std; @@ -196,6 +201,10 @@ int test_capi_main() { deletePeer(peer2); sleep(1); + // You may call rtcCleanup() when finished to free static resources + rtcCleanup(); + sleep(1); + printf("Success\n"); return 0; diff --git a/test/connectivity.cpp b/test/connectivity.cpp index b9f80a0..f707fa7 100644 --- a/test/connectivity.cpp +++ b/test/connectivity.cpp @@ -140,5 +140,9 @@ void test_connectivity() { pc2->close(); this_thread::sleep_for(1s); + // You may call rtc::Cleanup() when finished to free static resources + rtc::Cleanup(); + this_thread::sleep_for(1s); + cout << "Success" << endl; }