2
0
Murat Dogan 4 жил өмнө
parent
commit
367cd09195

+ 24 - 7
examples/client-benchmark/main.cpp

@@ -57,6 +57,7 @@ string randomId(size_t length);
 const size_t messageSize = 65535;
 binary messageData(messageSize);
 atomic<size_t> receivedSize = 0, sentSize = 0;
+bool noSend = false;
 
 int main(int argc, char **argv) try {
 	Cmdline params(argc, argv);
@@ -66,6 +67,11 @@ int main(int argc, char **argv) try {
 	// Benchmark - construct message to send
 	fill(messageData.begin(), messageData.end(), std::byte(0xFF));
 
+	// No Send option
+	noSend = params.noSend();
+	if (noSend)
+		cout << "Not Sending data. (One way benchmark)." << endl;
+
 	Configuration config;
 	string stunServer = "";
 	if (params.noStun()) {
@@ -171,6 +177,8 @@ int main(int argc, char **argv) try {
 
 	dc->onOpen([id, wdc = make_weak_ptr(dc)]() {
 		cout << "DataChannel from " << id << " open" << endl;
+		if (noSend)
+			return;
 		if (auto dcLocked = wdc.lock()) {
 			cout << "Starting benchmark test. Sending data..." << endl;
 			try {
@@ -185,6 +193,9 @@ int main(int argc, char **argv) try {
 	});
 
 	dc->onBufferedAmountLow([wdc = make_weak_ptr(dc)]() {
+		if (noSend)
+			return;
+
 		auto dcLocked = wdc.lock();
 		if (!dcLocked)
 			return;
@@ -277,20 +288,26 @@ shared_ptr<PeerConnection> createPeerConnection(const Configuration &config,
 		cout << "DataChannel from " << id << " received with label \"" << dc->label() << "\""
 		     << endl;
 
-		cout << "Starting benchmark test. Sending data..." << endl;
 		cout << "###########################################" << endl;
 		cout << "### Check other peer's screen for stats ###" << endl;
 		cout << "###########################################" << endl;
-		try {
-			while (dc->bufferedAmount() == 0) {
-				dc->send(messageData);
-				sentSize += messageData.size();
+
+		if (!noSend) {
+			cout << "Starting benchmark test. Sending data ..." << endl;
+			try {
+				while (dc->bufferedAmount() == 0) {
+					dc->send(messageData);
+					sentSize += messageData.size();
+				}
+			} catch (const std::exception &e) {
+				std::cout << "Send failed: " << e.what() << std::endl;
 			}
-		} catch (const std::exception &e) {
-			std::cout << "Send failed: " << e.what() << std::endl;
 		}
 
 		dc->onBufferedAmountLow([wdc = make_weak_ptr(dc)]() {
+			if (noSend)
+				return;
+
 			auto dcLocked = wdc.lock();
 			if (!dcLocked)
 				return;

+ 9 - 1
examples/client-benchmark/parse_cl.cpp

@@ -49,6 +49,7 @@ Cmdline::Cmdline (int argc, char *argv[]) // ISO C++17 not allowed: throw (std::
     {"webSocketServer", required_argument, NULL, 'w'},
     {"webSocketPort", required_argument, NULL, 'x'},
     {"durationInSec",required_argument,NULL,'d'},
+    {"noSend", no_argument, NULL, 'o'},
     {"help", no_argument, NULL, 'h'},
     {NULL, 0, NULL, 0}
   };
@@ -63,9 +64,10 @@ Cmdline::Cmdline (int argc, char *argv[]) // ISO C++17 not allowed: throw (std::
   _x = 8000;
   _h = false;
   _d = 300;
+  _o = false;
 
   optind = 0;
-  while ((c = getopt_long (argc, argv, "s:t:w:x:d:enhv", long_options, &optind)) != - 1)
+  while ((c = getopt_long (argc, argv, "s:t:w:x:d:enhvo", long_options, &optind)) != - 1)
     {
       switch (c)
         {
@@ -123,6 +125,10 @@ Cmdline::Cmdline (int argc, char *argv[]) // ISO C++17 not allowed: throw (std::
             }
           break;
 
+        case 'o':
+          _o = true;
+          break;
+
         case 'h':
           _h = true;
           this->usage (EXIT_SUCCESS);
@@ -166,6 +172,8 @@ libdatachannel client implementing WebRTC Data Channels with WebSocket signaling
           Web socket server port.\n\
    [ -d ] [ --durationInSec ] (type=INTEGER, range>=0...INT32_MAX, 0:infinite(INT32_MAX), Valid only for offering client, default=300)\n\
           Benchmark duration in seconds.\n\
+   [ -n ] [ --noSend ] (type=FLAG)\n\
+          Do NOT send message (Only Receive, for one-way testing purposes).\n\
    [ -h ] [ --help ] (type=FLAG)\n\
           Display this help and exit.\n";
     }

+ 2 - 0
examples/client-benchmark/parse_cl.h

@@ -41,6 +41,7 @@ private:
   int _x;
   bool _h;
   int _d;
+  bool _o;
 
   /* other stuff to keep track of */
   std::string _program_name;
@@ -64,6 +65,7 @@ public:
   int webSocketPort () const { return _x; }
   bool h () const { return _h; }
   int durationInSec () const { return _d; }
+  bool noSend () const { return _o; }
 };
 
 #endif