#include <stdlib.h>
#include <stdint.h>
#include <unistd.h>
+#include <signal.h>
#include <boost/date_time/posix_time/posix_time.hpp>
namespace isc {
namespace perfdhcp {
+bool TestControl::interrupted_ = false;
+
TestControl::TestControlSocket::TestControlSocket(int socket) :
socket_(socket),
addr_("127.0.0.1") {
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());
getSentPacketsNum(static_cast<StatsMgr6::ExchangeType>(xchg_type)));
}
+void
+TestControl::handleInterrupt(int) {
+ interrupted_ = true;
+}
+
void
TestControl::initPacketTemplates() {
CommandOptions& options = CommandOptions::instance();
transid_gen_.reset();
transid_gen_ = TransidGeneratorPtr(new TransidGenerator());
first_packet_serverid_.clear();
+ interrupted_ = false;
}
void
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) {
/// \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
/// Packet template buffers.
TemplateBufferList template_buffers_;
+ static bool interrupted_;
+
uint64_t sent_packets_0_;
uint64_t sent_packets_1_;
};