Browse Source

Merge pull request #307 from paullouisageneau/libtorrent-fixes

Merge libtorrent-related fixes on v0.10.4
Paul-Louis Ageneau 4 years ago
parent
commit
bb12c071cf
6 changed files with 25 additions and 11 deletions
  1. 1 0
      CMakeLists.txt
  2. 5 3
      Jamfile
  3. 2 2
      src/candidate.cpp
  4. 3 3
      src/peerconnection.cpp
  5. 13 2
      src/threadpool.cpp
  6. 1 1
      src/threadpool.hpp

+ 1 - 0
CMakeLists.txt

@@ -33,6 +33,7 @@ endif()
 
 set(CMAKE_POSITION_INDEPENDENT_CODE ON)
 set(CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake/Modules)
+set(BUILD_SHARED_LIBS OFF) # to force usrsctp to be built static
 
 if(WIN32)
 	add_definitions(-DWIN32_LEAN_AND_MEAN)

+ 5 - 3
Jamfile

@@ -15,9 +15,9 @@ lib libdatachannel
 	: # requirements
 	<cxxstd>17
 	<include>./include/rtc
-	<define>USE_NICE=0
 	<define>RTC_ENABLE_MEDIA=0
 	<define>RTC_ENABLE_WEBSOCKET=0
+	<define>USE_NICE=0
 	<toolset>msvc:<define>WIN32_LEAN_AND_MEAN
 	<toolset>msvc:<define>NOMINMAX
 	<toolset>msvc:<define>_CRT_SECURE_NO_WARNINGS
@@ -32,6 +32,8 @@ lib libdatachannel
 	<link>static
 	: # usage requirements
 	<include>./include
+	<define>RTC_ENABLE_MEDIA=0
+	<define>RTC_ENABLE_WEBSOCKET=0
 	<library>/libdatachannel//plog
 	<toolset>gcc:<cxxflags>"-pthread -Wno-pedantic -Wno-unused-parameter -Wno-unused-variable"
 	<toolset>clang:<cxxflags>"-pthread -Wno-pedantic -Wno-unused-parameter -Wno-unused-variable"
@@ -94,7 +96,7 @@ rule make_libusrsctp ( targets * : sources * : properties * )
 }
 actions make_libusrsctp
 {
-    (cd $(CWD)/deps/usrsctp && mkdir -p $(BUILD_DIR) && cd $(BUILD_DIR) && cmake -DCMAKE_BUILD_TYPE=$(VARIANT) -DCMAKE_C_FLAGS="-fPIC -Wno-unknown-warning-option -Wno-format-truncation" .. && make -j2 usrsctp-static)
+    (cd $(CWD)/deps/usrsctp && mkdir -p $(BUILD_DIR) && cd $(BUILD_DIR) && cmake -DCMAKE_BUILD_TYPE=$(VARIANT) -DCMAKE_C_FLAGS="-fPIC -Wno-unknown-warning-option -Wno-format-truncation" -Dsctp_build_shared_lib=0 -Dsctp_build_programs=0 .. && make -j2 usrsctp)
     cp $(CWD)/deps/usrsctp/$(BUILD_DIR)/usrsctplib/libusrsctp.a $(<)
 }
 rule make_libusrsctp_msvc ( targets * : sources * : properties * )
@@ -109,7 +111,7 @@ actions make_libusrsctp_msvc
     cd $(CWD)/deps/usrsctp
     mkdir $(BUILD_DIR)
     cd $(BUILD_DIR)
-    cmake -G "Visual Studio 16 2019" ..
+    cmake -G "Visual Studio 16 2019" -Dsctp_build_shared_lib=0 -Dsctp_build_programs=0 ..
     msbuild usrsctplib.sln /property:Configuration=$(VARIANT)
     cd %OLDD%
     cp $(CWD)/deps/usrsctp/$(BUILD_DIR)/usrsctplib/Release/usrsctp.lib $(<)

+ 2 - 2
src/candidate.cpp

@@ -117,9 +117,9 @@ void Candidate::parse(string candidate) {
 		mTransportType = TransportType::Udp;
 	} else if (transport == "TCP" || transport == "tcp") {
 		// Peek tail to find TCP type
-		std::istringstream iss(mTail);
+		std::istringstream tiss(mTail);
 		string tcptype_, tcptype;
-		if (iss >> tcptype_ >> tcptype && tcptype_ == "tcptype") {
+		if (tiss >> tcptype_ >> tcptype && tcptype_ == "tcptype") {
 			if (auto it = TcpTypeMap.find(tcptype); it != TcpTypeMap.end())
 				mTransportType = it->second;
 			else

+ 3 - 3
src/peerconnection.cpp

@@ -663,10 +663,10 @@ void PeerConnection::forwardMessage(message_ptr message) {
 		    stream % 2 == remoteParity) {
 
 			channel = std::make_shared<NegociatedDataChannel>(shared_from_this(), sctpTransport,
-			                                                  message->stream);
+			                                                  stream);
 			channel->onOpen(weak_bind(&PeerConnection::triggerDataChannel, this,
 			                          weak_ptr<DataChannel>{channel}));
-			mDataChannels.emplace(message->stream, channel);
+			mDataChannels.emplace(stream, channel);
 		} else {
 			// Invalid, close the DataChannel
 			sctpTransport->closeStream(message->stream);
@@ -1159,7 +1159,7 @@ void PeerConnection::processRemoteCandidate(Candidate candidate) {
 	} else {
 		// We might need a lookup, do it asynchronously
 		// We don't use the thread pool because we have no control on the timeout
-		if (auto iceTransport = std::atomic_load(&mIceTransport)) {
+		if ((iceTransport = std::atomic_load(&mIceTransport))) {
 			weak_ptr<IceTransport> weakIceTransport{iceTransport};
 			std::thread t([weakIceTransport, candidate = std::move(candidate)]() mutable {
 				if (candidate.resolve(Candidate::ResolveMode::Lookup))

+ 13 - 2
src/threadpool.cpp

@@ -18,15 +18,26 @@
 
 #include "threadpool.hpp"
 
+#include <cstdlib>
+
+namespace {
+	void joinThreadPoolInstance() {
+		rtc::ThreadPool::Instance().join();
+	}
+}
+
 namespace rtc {
 
 ThreadPool &ThreadPool::Instance() {
-	// Init handles joining on cleanup
 	static ThreadPool *instance = new ThreadPool;
 	return *instance;
 }
 
-ThreadPool::~ThreadPool() { join(); }
+ThreadPool::ThreadPool() {
+	std::atexit(joinThreadPoolInstance);
+}
+
+ThreadPool::~ThreadPool() {}
 
 int ThreadPool::count() const {
 	std::unique_lock lock(mWorkersMutex);

+ 1 - 1
src/threadpool.hpp

@@ -66,7 +66,7 @@ public:
 	auto schedule(clock::time_point time, F &&f, Args &&...args) -> invoke_future_t<F, Args...>;
 
 protected:
-	ThreadPool() = default;
+	ThreadPool();
 	~ThreadPool();
 
 	std::function<void()> dequeue(); // returns null function if joining