Browse Source

Fixed compilation with MSVC

Paul-Louis Ageneau 5 years ago
parent
commit
0382067d92
8 changed files with 38 additions and 27 deletions
  1. 2 2
      src/candidate.cpp
  2. 4 4
      src/certificate.cpp
  3. 2 2
      src/datachannel.cpp
  4. 2 1
      src/description.cpp
  5. 10 2
      src/dtlstransport.cpp
  6. 4 3
      src/icetransport.cpp
  7. 4 4
      src/peerconnection.cpp
  8. 10 9
      src/rtc.cpp

+ 2 - 2
src/candidate.cpp

@@ -98,8 +98,8 @@ bool Candidate::resolve(ResolveMode mode) {
 					// Rewrite the candidate
 					char nodebuffer[MAX_NUMERICNODE_LEN];
 					char servbuffer[MAX_NUMERICSERV_LEN];
-					if (getnameinfo(p->ai_addr, p->ai_addrlen, nodebuffer, MAX_NUMERICNODE_LEN,
-					                servbuffer, MAX_NUMERICSERV_LEN,
+					if (getnameinfo(p->ai_addr, socklen_t(p->ai_addrlen), nodebuffer,
+					                MAX_NUMERICNODE_LEN, servbuffer, MAX_NUMERICSERV_LEN,
 					                NI_NUMERICHOST | NI_NUMERICSERV) == 0) {
 						const char sp{' '};
 						std::ostringstream oss;

+ 4 - 4
src/certificate.cpp

@@ -132,14 +132,14 @@ namespace rtc {
 
 Certificate::Certificate(string crt_pem, string key_pem) {
 	BIO *bio = BIO_new(BIO_s_mem());
-	BIO_write(bio, crt_pem.data(), crt_pem.size());
+	BIO_write(bio, crt_pem.data(), int(crt_pem.size()));
 	mX509 = shared_ptr<X509>(PEM_read_bio_X509(bio, nullptr, 0, 0), X509_free);
 	BIO_free(bio);
 	if (!mX509)
 		throw std::invalid_argument("Unable to import certificate PEM");
 
 	bio = BIO_new(BIO_s_mem());
-	BIO_write(bio, key_pem.data(), key_pem.size());
+	BIO_write(bio, key_pem.data(), int(key_pem.size()));
 	mPKey = shared_ptr<EVP_PKEY>(PEM_read_bio_PrivateKey(bio, nullptr, 0, 0), EVP_PKEY_free);
 	BIO_free(bio);
 	if (!mPKey)
@@ -233,8 +233,8 @@ namespace {
 // Helper function roughly equivalent to std::async with policy std::launch::async
 // since std::async might be unreliable on some platforms (e.g. Mingw32 on Windows)
 template <class F, class... Args>
-std::future<std::result_of_t<std::decay_t<F>(std::decay_t<Args>...)>> thread_call(F &&f,
-                                                                                  Args &&... args) {
+std::future<std::invoke_result_t<std::decay_t<F>, std::decay_t<Args>...>>
+thread_call(F &&f, Args &&... args) {
 	using R = std::invoke_result_t<std::decay_t<F>, std::decay_t<Args>...>;
 	std::packaged_task<R()> task(std::bind(f, std::forward<Args>(args)...));
 	std::future<R> future = task.get_future();

+ 2 - 2
src/datachannel.cpp

@@ -186,8 +186,8 @@ void DataChannel::open(shared_ptr<SctpTransport> transport) {
 	open.channelType = mReliability->type;
 	open.priority = htons(0);
 	open.reliabilityParameter = htonl(reliabilityParameter);
-	open.labelLength = htons(mLabel.size());
-	open.protocolLength = htons(mProtocol.size());
+	open.labelLength = htons(uint16_t(mLabel.size()));
+	open.protocolLength = htons(uint16_t(mProtocol.size()));
 
 	auto end = reinterpret_cast<char *>(buffer.data() + sizeof(OpenMessage));
 	std::copy(mLabel.begin(), mLabel.end(), end);

+ 2 - 1
src/description.cpp

@@ -26,6 +26,7 @@
 
 using std::size_t;
 using std::string;
+using std::chrono::system_clock;
 
 namespace {
 
@@ -54,7 +55,7 @@ Description::Description(const string &sdp, Type type, Role role)
 	mData.mid = "data";
 	hintType(type);
 
-	auto seed = std::chrono::system_clock::now().time_since_epoch().count();
+	auto seed = static_cast<unsigned int>(system_clock::now().time_since_epoch().count());
 	std::default_random_engine generator(seed);
 	std::uniform_int_distribution<uint32_t> uniform;
 	mSessionId = std::to_string(uniform(generator));

+ 10 - 2
src/dtlstransport.cpp

@@ -24,6 +24,14 @@
 #include <exception>
 #include <iostream>
 
+#if !USE_GNUTLS
+#ifdef _WIN32
+#include <winsock2.h> // for timeval
+#else
+#include <sys/time.h> // for timeval
+#endif
+#endif
+
 using namespace std::chrono;
 
 using std::shared_ptr;
@@ -382,7 +390,7 @@ bool DtlsTransport::send(message_ptr message) {
 
 	PLOG_VERBOSE << "Send size=" << message->size();
 
-	int ret = SSL_write(mSsl, message->data(), message->size());
+	int ret = SSL_write(mSsl, message->data(), int(message->size()));
 	return openssl::check(mSsl, ret);
 }
 
@@ -416,7 +424,7 @@ void DtlsTransport::runRecvLoop() {
 			// Process pending messages
 			while (!mIncomingQueue.empty()) {
 				auto message = *mIncomingQueue.pop();
-				BIO_write(mInBio, message->data(), message->size());
+				BIO_write(mInBio, message->data(), int(message->size()));
 
 				if (state() == State::Connecting) {
 					// Continue the handshake

+ 4 - 3
src/icetransport.cpp

@@ -40,6 +40,7 @@ using namespace std::chrono_literals;
 
 using std::shared_ptr;
 using std::weak_ptr;
+using std::chrono::system_clock;
 
 #if USE_JUICE
 
@@ -69,7 +70,7 @@ IceTransport::IceTransport(const Configuration &config, Description::Role role,
 
 	// Randomize servers order
 	std::vector<IceServer> servers = config.iceServers;
-	unsigned seed = std::chrono::system_clock::now().time_since_epoch().count();
+	auto seed = static_cast<unsigned int>(system_clock::now().time_since_epoch().count());
 	std::shuffle(servers.begin(), servers.end(), std::default_random_engine(seed));
 
 	// Pick a STUN server (TURN support is not implemented in libjuice yet)
@@ -82,7 +83,7 @@ IceTransport::IceTransport(const Configuration &config, Description::Role role,
 			mStunHostname = server.hostname;
 			mStunService = server.service;
 			jconfig.stun_server_host = mStunHostname.c_str();
-			jconfig.stun_server_port = std::stoul(mStunService);
+			jconfig.stun_server_port = uint16_t(std::stoul(mStunService));
 			break;
 		}
 	}
@@ -337,7 +338,7 @@ IceTransport::IceTransport(const Configuration &config, Description::Role role,
 
 	// Randomize order
 	std::vector<IceServer> servers = config.iceServers;
-	unsigned seed = std::chrono::system_clock::now().time_since_epoch().count();
+	auto seed = static_cast<unsigned int>(system_clock::now().time_since_epoch().count());
 	std::shuffle(servers.begin(), servers.end(), std::default_random_engine(seed));
 
 	// Add one STUN server

+ 4 - 4
src/peerconnection.cpp

@@ -659,12 +659,12 @@ void PeerConnection::resetCallbacks() {
 }
 
 bool PeerConnection::getSelectedCandidatePair(CandidateInfo *local, CandidateInfo *remote) {
-#if not USE_JUICE
+#if USE_JUICE
+	PLOG_WARNING << "getSelectedCandidatePair() is not implemented for libjuice";
+	return false;
+#else
 	auto iceTransport = std::atomic_load(&mIceTransport);
 	return iceTransport->getSelectedCandidatePair(local, remote);
-#else
-	PLOG_WARNING << "getSelectedCandidatePair is not implemented for libjuice";
-	return false;
 #endif
 }
 

+ 10 - 9
src/rtc.cpp

@@ -145,7 +145,7 @@ shared_ptr<Channel> getChannel(int id) {
 
 template <typename F> int wrap(F func) {
 	try {
-		return func();
+		return int(func());
 
 	} catch (const std::invalid_argument &e) {
 		PLOG_ERROR << e.what();
@@ -173,14 +173,15 @@ public:
 
 	void write(const plog::Record &record) override {
 		plog::Severity severity = record.getSeverity();
-		std::string formatted = plog::FuncMessageFormatter::format(record);
+		auto formatted = plog::FuncMessageFormatter::format(record);
+		std::string str(formatted.begin(), formatted.end());
 		formatted.pop_back(); // remove newline
 
 		std::lock_guard lock(mutex);
 		if (callback)
-			callback(static_cast<rtcLogLevel>(record.getSeverity()), formatted.c_str());
+			callback(static_cast<rtcLogLevel>(record.getSeverity()), str.c_str());
 		else
-			std::cout << plog::severityToString(severity) << " " << formatted << std::endl;
+			std::cout << plog::severityToString(severity) << " " << str << std::endl;
 	}
 
 private:
@@ -376,7 +377,7 @@ int rtcGetLocalAddress(int pc, char *buffer, int size) {
 			size = std::min(size_t(size - 1), addr->size());
 			std::copy(data, data + size, buffer);
 			buffer[size] = '\0';
-			return size + 1;
+			return int(size + 1);
 		}
 	});
 }
@@ -396,7 +397,7 @@ int rtcGetRemoteAddress(int pc, char *buffer, int size) {
 			size = std::min(size_t(size - 1), addr->size());
 			std::copy(data, data + size, buffer);
 			buffer[size] = '\0';
-			return size + 1;
+			return int(size + 1);
 		}
 	});
 }
@@ -416,7 +417,7 @@ int rtcGetDataChannelLabel(int dc, char *buffer, int size) {
 		size = std::min(size_t(size - 1), label.size());
 		std::copy(data, data + size, buffer);
 		buffer[size] = '\0';
-		return size + 1;
+		return int(size + 1);
 	});
 }
 
@@ -457,7 +458,7 @@ int rtcSetMessageCallback(int id, rtcMessageCallbackFunc cb) {
 		if (cb)
 			channel->onMessage(
 			    [id, cb](const binary &b) {
-				    cb(reinterpret_cast<const char *>(b.data()), b.size(), getUserPointer(id));
+				    cb(reinterpret_cast<const char *>(b.data()), int(b.size()), getUserPointer(id));
 			    },
 			    [id, cb](const string &s) { cb(s.c_str(), -1, getUserPointer(id)); });
 		else
@@ -478,7 +479,7 @@ int rtcSendMessage(int id, const char *data, int size) {
 			return size;
 		} else {
 			string str(data);
-			int len = str.size();
+			int len = int(str.size());
 			channel->send(std::move(str));
 			return len;
 		}