Commit b753e8eb authored by Marcin Siodelski's avatar Marcin Siodelski

[1959] End the program gracefully if interrupted.

parent 23c33b29
......@@ -16,6 +16,7 @@
#include <stdlib.h>
#include <stdint.h>
#include <unistd.h>
#include <signal.h>
#include <boost/date_time/posix_time/posix_time.hpp>
......@@ -37,6 +38,8 @@ using namespace isc::asiolink;
namespace isc {
namespace perfdhcp {
bool TestControl::interrupted_ = false;
TestControl::TestControlSocket::TestControlSocket(int socket) :
socket_(socket),
addr_("127.0.0.1") {
......@@ -84,8 +87,11 @@ TestControl::TestControl() {
bool
TestControl::checkExitConditions() const {
if (interrupted_) {
return(true);
}
CommandOptions& options = CommandOptions::instance();
// Check if test period passed..
// Check if test period passed.
if (options.getPeriod() != 0) {
if (options.getIpVersion() == 4) {
time_period period(stats_mgr4_->getTestPeriod());
......@@ -384,6 +390,11 @@ TestControl::getSentPacketsNum(const ExchangeType xchg_type) const {
getSentPacketsNum(static_cast<StatsMgr6::ExchangeType>(xchg_type)));
}
void
TestControl::handleInterrupt(int) {
interrupted_ = true;
}
void
TestControl::initPacketTemplates() {
CommandOptions& options = CommandOptions::instance();
......@@ -692,6 +703,7 @@ TestControl::reset() {
transid_gen_.reset();
transid_gen_ = TransidGeneratorPtr(new TransidGenerator());
first_packet_serverid_.clear();
interrupted_ = false;
}
void
......@@ -722,6 +734,9 @@ TestControl::run() {
srandom(options.getSeed());
}
// If user interrupts the program we will exit gracefully.
signal(SIGINT, TestControl::handleInterrupt);
// Preload server with number of packets.
const bool do_preload = true;
for (int i = 0; i < options.getPreload(); ++i) {
......
......@@ -584,6 +584,14 @@ private:
/// \return number of sent packets.
uint64_t getSentPacketsNum(const ExchangeType xchg_type) const;
/// \brief Handle interrupt signal.
///
/// Function sets flag indicating that program has been
/// interupted.
///
/// \param sig signal (ignored)
static void handleInterrupt(int sig);
boost::posix_time::ptime send_due_; ///< Due time to initiate next chunk
///< of exchanges.
boost::posix_time::ptime last_sent_; ///< Indicates when the last exchange
......@@ -602,6 +610,8 @@ private:
/// Packet template buffers.
TemplateBufferList template_buffers_;
static bool interrupted_;
uint64_t sent_packets_0_;
uint64_t sent_packets_1_;
};
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment