Fixed call to usrsctp_finish() in Cleanup()

This commit is contained in:
Paul-Louis Ageneau
2020-05-22 14:55:01 +02:00
parent 3a737e940c
commit ddb9f99ed6
5 changed files with 23 additions and 1 deletions

View File

@ -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

View File

@ -450,3 +450,5 @@ int rtcReceiveMessage(int dc, char *buffer, int *size) {
*message);
});
}
void rtcCleanup() { rtc::Cleanup(); }

View File

@ -21,6 +21,7 @@
#include <chrono>
#include <exception>
#include <iostream>
#include <thread>
#include <vector>
#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<Transport> lower, uint16_t port,
message_callback recvCallback, amount_callback bufferedAmountCallback,

View File

@ -23,7 +23,12 @@
#include <cstdlib>
#include <cstring>
#ifdef _WIN32
#include <windows.h>
static void sleep(unsigned int secs) { Sleep(secs * 1000); }
#else
#include <unistd.h> // 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;

View File

@ -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;
}