version 1.40.130 release
[feisty_meow.git] / octopi / library / tests_sockets / spocket_tester.cpp
index d5f731c0de5fceb2c79a1340a2c6bb423b7a1bb5..11d33bef4bdcdd4f4329b01b6da519872df1f5bd 100644 (file)
 
 #include <errno.h>
 
-//using namespace application;
 using namespace basis;
-//using namespace filesystem;
 using namespace loggers;
 using namespace mathematics;
 using namespace sockets;
 using namespace structures;
 using namespace textual;
 using namespace timely;
-//using namespace unit_test;
 
 #define LOG(to_print) EMERGENCY_LOG(program_wide_logger().get(), astring(to_print))
 
@@ -61,8 +58,8 @@ const int PAUSE_TIME = 200;
 spocket_tester::spocket_tester(const internet_address &where)
 : _where(new internet_address(where)),
   _stack(new tcpip_stack),
-  _socket(NIL),
-  _root_server(NIL),
+  _socket(NULL_POINTER),
+  _root_server(NULL_POINTER),
   _raw(new raw_socket)
 {
 }
@@ -105,9 +102,10 @@ bool spocket_tester::accept(bool wait)
     ret = _root_server->accept(_socket, false);
     if (ret == spocket::OKAY) break;
     if (ret != spocket::NO_CONNECTION) break;
-    if (!wait) return true;  // we accepted at least once.
-    time_control::sleep_ms(100);
+    if (!wait) return true;  // we tried to accept at least once.
+    time_control::sleep_ms(100);  // snooze to avoid slamming with accepts.
   }
+
   return ret == spocket::OKAY;
 }
 
@@ -180,7 +178,6 @@ bool spocket_tester::do_a_receive(int size_expected, testing_statistics &stats)
     if (ret != spocket::OKAY) {
       if (ret == spocket::NONE_READY) {
 if (len != 0) LOG(a_sprintf("supposedly nothing was received (%d bytes)", len));
-///        time_control::sleep_ms(PAUSE_TIME);
         _socket->await_readable(PAUSE_TIME);
         continue;
       } else break;
@@ -220,10 +217,6 @@ if (len != 0) LOG(a_sprintf("supposedly nothing was received (%d bytes)", len));
 bool spocket_tester::perform_test(int size, int count,
     testing_statistics &stats)
 {
-#ifdef DEBUG_SPOCKET_TESTER
-  LOG("into perf test");
-#endif
-
   // the statics are used to generate our random buffer for sending.
   static abyte garbage_buffer[MAXIMUM_WINSOCK_MTU + 1];
   static bool garbage_initialized = false;
@@ -232,12 +225,10 @@ bool spocket_tester::perform_test(int size, int count,
   // if our static buffer full of random stuff was never initialized, we do
   // so now.  this supports efficiently re-using the tester if desired.
   if (!garbage_initialized) {
-    LOG("initializing random send buffer.");
     // note the less than or equal; we know we have one more byte to fill.
     for (int i = 0; i <= MAXIMUM_WINSOCK_MTU; i++)
       garbage_buffer[i] = randomizer.inclusive(0, 255);
     garbage_initialized = true;
-    LOG("random send buffer initialized.");
   }
 
   // reset the statistical package.