Browse Source

Fixed call to usrsctp_finish() in Cleanup()

Paul-Louis Ageneau 5 years ago
parent
commit
ddb9f99ed6
5 changed files with 23 additions and 1 deletions
  1. 3 0
      include/rtc/rtc.h
  2. 2 0
      src/rtc.cpp
  3. 5 1
      src/sctptransport.cpp
  4. 9 0
      test/capi.cpp
  5. 4 0
      test/connectivity.cpp

+ 3 - 0
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

+ 2 - 0
src/rtc.cpp

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

+ 5 - 1
src/sctptransport.cpp

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

+ 9 - 0
test/capi.cpp

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

+ 4 - 0
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;
 }