From 6380f563840457307e21122df8c17be30ca4e5a8 Mon Sep 17 00:00:00 2001 From: Peter Thorson Date: Sun, 11 Mar 2012 17:02:14 -0500 Subject: [PATCH] wsperf blocking mode --- examples/wsperf/request.hpp | 11 ++++++++-- examples/wsperf/wsperf.cpp | 42 ++++++++++++++----------------------- 2 files changed, 25 insertions(+), 28 deletions(-) diff --git a/examples/wsperf/request.hpp b/examples/wsperf/request.hpp index 024a46557a..f775d20540 100644 --- a/examples/wsperf/request.hpp +++ b/examples/wsperf/request.hpp @@ -138,7 +138,8 @@ public: : m_coordinator(c), m_ident(ident), m_ua(ua), - m_num_workers(num_workers) {} + m_num_workers(num_workers), + m_blocking(num_workers == 0) {} void on_open(connection_ptr con) { std::stringstream o; @@ -158,7 +159,12 @@ public: r.type = PERF_TEST; r.writer = writer_ptr(new ws_writer(con)); r.req = msg->get_payload(); - m_coordinator.add_request(r); + + if (m_blocking) { + r.process(0); + } else { + m_coordinator.add_request(r); + } } void on_fail(connection_ptr con) { @@ -173,6 +179,7 @@ private: std::string m_ident; std::string m_ua; unsigned int m_num_workers; + bool m_blocking; }; // process_requests is the body function for a processing thread. It loops diff --git a/examples/wsperf/wsperf.cpp b/examples/wsperf/wsperf.cpp index c344ec98a0..dfe524b425 100644 --- a/examples/wsperf/wsperf.cpp +++ b/examples/wsperf/wsperf.cpp @@ -65,19 +65,14 @@ int start_server(po::variables_map& vm) { wsperf::request_coordinator rc; server::handler::ptr h; - if (num_threads == 0) { - std::cerr << "bad thread number" << std::endl; - return 1; - } else { - h = server::handler::ptr( - new wsperf::concurrent_handler( - rc, - ident, - user_agent, - num_threads - ) - ); - } + h = server::handler::ptr( + new wsperf::concurrent_handler( + rc, + ident, + user_agent, + num_threads + ) + ); if (!silent) { std::cout << "Starting wsperf server on port " << port << " with " << num_threads << " processing threads." << std::endl; @@ -128,19 +123,14 @@ int start_client(po::variables_map& vm) { wsperf::request_coordinator rc; client::handler::ptr h; - if (num_threads == 0) { - std::cerr << "bad thread number" << std::endl; - return 1; - } else { - h = client::handler::ptr( - new wsperf::concurrent_handler( - rc, - ident, - user_agent, - num_threads - ) - );; - } + h = client::handler::ptr( + new wsperf::concurrent_handler( + rc, + ident, + user_agent, + num_threads + ) + ); if (!silent) { std::cout << "Starting wsperf client connecting to " << uri << " with " << num_threads << " processing threads." << std::endl;