Browse Source

rtt as optional & delete const

Murat Dogan 5 years ago
parent
commit
070582d87a

+ 3 - 3
include/rtc/peerconnection.hpp

@@ -91,9 +91,9 @@ public:
 
 
 	// Stats
 	// Stats
 	void clearStats();
 	void clearStats();
-	const size_t bytesSent();
-	const size_t bytesReceived();
-	const std::chrono::milliseconds rtt();
+	size_t bytesSent();
+	size_t bytesReceived();
+	std::optional<std::chrono::milliseconds> rtt();
 
 
 private:
 private:
 	init_token mInitToken = Init::Token();
 	init_token mInitToken = Init::Token();

+ 8 - 8
src/peerconnection.cpp

@@ -579,31 +579,32 @@ bool PeerConnection::getSelectedCandidatePair(CandidateInfo *local, CandidateInf
 #endif
 #endif
 }
 }
 
 
-void PeerConnection::clearStats(){
-auto sctpTransport = std::atomic_load(&mSctpTransport);
+void PeerConnection::clearStats() {
+	auto sctpTransport = std::atomic_load(&mSctpTransport);
 	if (sctpTransport)
 	if (sctpTransport)
-		return sctpTransport->clearStats();	
+		return sctpTransport->clearStats();
 }
 }
 
 
-const size_t PeerConnection::bytesSent() {
+size_t PeerConnection::bytesSent() {
 	auto sctpTransport = std::atomic_load(&mSctpTransport);
 	auto sctpTransport = std::atomic_load(&mSctpTransport);
 	if (sctpTransport)
 	if (sctpTransport)
 		return sctpTransport->bytesSent();
 		return sctpTransport->bytesSent();
 	return 0;
 	return 0;
 }
 }
 
 
-const size_t PeerConnection::bytesReceived() {
+size_t PeerConnection::bytesReceived() {
 	auto sctpTransport = std::atomic_load(&mSctpTransport);
 	auto sctpTransport = std::atomic_load(&mSctpTransport);
 	if (sctpTransport)
 	if (sctpTransport)
 		return sctpTransport->bytesReceived();
 		return sctpTransport->bytesReceived();
 	return 0;
 	return 0;
 }
 }
 
 
-const std::chrono::milliseconds PeerConnection::rtt() {
+std::optional<std::chrono::milliseconds> PeerConnection::rtt() {
 	auto sctpTransport = std::atomic_load(&mSctpTransport);
 	auto sctpTransport = std::atomic_load(&mSctpTransport);
 	if (sctpTransport)
 	if (sctpTransport)
 		return sctpTransport->rtt();
 		return sctpTransport->rtt();
-	return std::chrono::milliseconds(0);
+	PLOG_WARNING << "Could not load sctpTransport";
+	return std::nullopt;
 }
 }
 
 
 } // namespace rtc
 } // namespace rtc
@@ -656,4 +657,3 @@ std::ostream &operator<<(std::ostream &out, const rtc::PeerConnection::Gathering
 	}
 	}
 	return out << str;
 	return out << str;
 }
 }
-

+ 7 - 5
src/sctptransport.cpp

@@ -589,16 +589,18 @@ void SctpTransport::clearStats() {
 	mBytesSent = 0;
 	mBytesSent = 0;
 }
 }
 
 
-const size_t SctpTransport::bytesSent() { return mBytesSent; }
+size_t SctpTransport::bytesSent() { return mBytesSent; }
 
 
-const size_t SctpTransport::bytesReceived() { return mBytesReceived; }
+size_t SctpTransport::bytesReceived() { return mBytesReceived; }
 
 
-const std::chrono::milliseconds SctpTransport::rtt() {
+std::optional<std::chrono::milliseconds> SctpTransport::rtt() {
 	struct sctp_status status = {};
 	struct sctp_status status = {};
 	socklen_t len = sizeof(status);
 	socklen_t len = sizeof(status);
 
 
-	if (usrsctp_getsockopt(this->mSock, IPPROTO_SCTP, SCTP_STATUS, &status, &len))
-		return std::chrono::milliseconds(0);
+	if (usrsctp_getsockopt(this->mSock, IPPROTO_SCTP, SCTP_STATUS, &status, &len)) {
+		PLOG_WARNING << "Could not read SCTP_STATUS";
+		return std::nullopt;
+	}
 	return std::chrono::milliseconds(status.sstat_primary.spinfo_srtt);
 	return std::chrono::milliseconds(status.sstat_primary.spinfo_srtt);
 }
 }
 
 

+ 3 - 3
src/sctptransport.hpp

@@ -56,9 +56,9 @@ public:
 
 
 	// Stats
 	// Stats
 	void clearStats();
 	void clearStats();
-	const size_t bytesSent();
-	const size_t bytesReceived();
-	const std::chrono::milliseconds rtt();
+	size_t bytesSent();
+	size_t bytesReceived();
+	std::optional<std::chrono::milliseconds> rtt();
 
 
 private:
 private:
 	// Order seems wrong but these are the actual values
 	// Order seems wrong but these are the actual values

+ 12 - 6
test/p2p/answerer.cpp

@@ -128,13 +128,19 @@ int main(int argc, char **argv) {
 				break;
 				break;
 			}
 			}
 			CandidateInfo local, remote;
 			CandidateInfo local, remote;
+			std::optional<std::chrono::milliseconds> rtt = pc->rtt();
 			if (pc->getSelectedCandidatePair(&local, &remote)) {
 			if (pc->getSelectedCandidatePair(&local, &remote)) {
-				cout << "Local Candidate: " << local.address << ":" << local.port << " "
-				     << local.type << " " << local.transportType << endl;
-				cout << "Remote Candidate: " << remote.address << ":" << remote.port << " "
-				     << remote.type << " " << remote.transportType << endl;
-				cout << "Bytes Sent:" << pc->bytesSent() << " / Bytes Received:" << pc->bytesReceived()
-				     << " / Round-Trip Time:" << pc->rtt().count() << " ms" << endl;
+				cout << "Local: " << local.address << ":" << local.port << " " << local.type << " "
+				     << local.transportType << endl;
+				cout << "Remote: " << remote.address << ":" << remote.port << " " << remote.type
+				     << " " << remote.transportType << endl;
+				cout << "Bytes Sent:" << pc->bytesSent()
+				     << " / Bytes Received:" << pc->bytesReceived() << " / Round-Trip Time:";
+				if (rtt.has_value())
+					cout << rtt.value().count();
+				else
+					cout << "null";
+				cout << " ms";
 			} else
 			} else
 				cout << "Could not get Candidate Pair Info" << endl;
 				cout << "Could not get Candidate Pair Info" << endl;
 			break;
 			break;

+ 8 - 2
test/p2p/offerer.cpp

@@ -128,13 +128,19 @@ int main(int argc, char **argv) {
 				break;
 				break;
 			}
 			}
 			CandidateInfo local, remote;
 			CandidateInfo local, remote;
+			std::optional<std::chrono::milliseconds> rtt = pc->rtt();
 			if (pc->getSelectedCandidatePair(&local, &remote)) {
 			if (pc->getSelectedCandidatePair(&local, &remote)) {
 				cout << "Local: " << local.address << ":" << local.port << " " << local.type << " "
 				cout << "Local: " << local.address << ":" << local.port << " " << local.type << " "
 				     << local.transportType << endl;
 				     << local.transportType << endl;
 				cout << "Remote: " << remote.address << ":" << remote.port << " " << remote.type
 				cout << "Remote: " << remote.address << ":" << remote.port << " " << remote.type
 				     << " " << remote.transportType << endl;
 				     << " " << remote.transportType << endl;
-				cout << "Bytes Sent:" << pc->bytesSent() << " / Bytes Received:" << pc->bytesReceived()
-				     << " / Round-Trip Time:" << pc->rtt().count() << " ms" << endl;
+				cout << "Bytes Sent:" << pc->bytesSent()
+				     << " / Bytes Received:" << pc->bytesReceived() << " / Round-Trip Time:";
+				if (rtt.has_value())
+					cout << rtt.value().count();
+				else
+					cout << "null";
+				cout << " ms";
 			} else
 			} else
 				cout << "Could not get Candidate Pair Info" << endl;
 				cout << "Could not get Candidate Pair Info" << endl;
 			break;
 			break;