diff --git a/examples/wsperf/request.cpp b/examples/wsperf/request.cpp index c20689bbad..d24bbe1536 100644 --- a/examples/wsperf/request.cpp +++ b/examples/wsperf/request.cpp @@ -94,6 +94,11 @@ void request::process(unsigned int id) { boost::thread t(boost::bind(&client::run, &e, true)); + size_t handshake_delay; + if(!wscmd::extract_number(command, "handshake_delay",handshake_delay)) { + handshake_delay = 10; + } + // create connections for (size_t i = 0; i < connection_count; i++) { client::connection_ptr con; @@ -103,6 +108,8 @@ void request::process(unsigned int id) { shandler->on_connect(con); e.connect(con); + + boost::this_thread::sleep(boost::posix_time::milliseconds(handshake_delay)); } for (;;) { @@ -111,12 +118,18 @@ void request::process(unsigned int id) { // check for too few connections - shandler->maintenance(); + bool quit = shandler->maintenance(); // check for done-ness + if (quit) { + break; + } + sleep(1); } + e.end_perpetual(); + t.join(); } writer->write(prepare_response("test_complete","")); diff --git a/examples/wsperf/stress_handler.cpp b/examples/wsperf/stress_handler.cpp index 4a562a13c1..67e3848b58 100644 --- a/examples/wsperf/stress_handler.cpp +++ b/examples/wsperf/stress_handler.cpp @@ -179,15 +179,24 @@ std::string stress_handler::get_data() const { return data.str(); } -void stress_handler::maintenance() { +bool stress_handler::maintenance() { std::list to_process; { boost::lock_guard lock(m_lock); + bool quit = true; + std::map::iterator it; for (it = m_con_data.begin(); it != m_con_data.end(); it++) { to_process.push_back((*it).first); + if ((*it).first->get_state() != websocketpp::session::state::CLOSED) { + quit = false; + } + } + + if (quit) { + return true; } } @@ -220,4 +229,6 @@ void stress_handler::maintenance() { close(con); } } + + return false; } \ No newline at end of file diff --git a/examples/wsperf/stress_handler.hpp b/examples/wsperf/stress_handler.hpp index bb44ccee71..6d5c40e30f 100644 --- a/examples/wsperf/stress_handler.hpp +++ b/examples/wsperf/stress_handler.hpp @@ -116,7 +116,7 @@ public: void end(); std::string get_data() const; - virtual void maintenance(); + virtual bool maintenance(); protected: size_t m_current_connections; size_t m_max_connections;