#############################################################################*/
#include <errno.h>
+#include <signal.h>
#include <sys/epoll.h>
#include <string.h>
#include <unistd.h>
#include "logging.h"
#include "main.h"
+// Set to one when the timeout has expired
+static int timeout_expired = 0;
+
+static void handle_SIGALRM(int signal) {
+ switch (signal) {
+ // Terminate after timeout has expired
+ case SIGALRM:
+ timeout_expired = 1;
+ break;
+ }
+}
+
static int connect_socket(struct fireperf_config* conf, int fd) {
DEBUG(conf, "(Re-)connecting socket %d...\n", fd);
}
}
+ // Configure timeout if set
+ if (conf->timeout) {
+ // Register signal handler
+ signal(SIGALRM, handle_SIGALRM);
+
+ alarm(conf->timeout);
+ }
+
DEBUG(conf, "Entering main loop...\n");
- while (!conf->terminated) {
+ while (!conf->terminated && !timeout_expired) {
int fds = epoll_wait(epollfd, events, EPOLL_MAX_EVENTS, -1);
if (fds < 1) {
ERROR(conf, "epoll_wait() failed: %s\n", strerror(errno));
{"parallel", required_argument, 0, 'P'},
{"port", required_argument, 0, 'p'},
{"server", no_argument, 0, 's'},
+ {"timeout", required_argument, 0, 't'},
{0, 0, 0, 0},
};
int done = 0;
while (!done) {
- int c = getopt_long(argc, argv, "c:dp:sP:", long_options, &option_index);
+ int c = getopt_long(argc, argv, "c:dp:st:P:", long_options, &option_index);
// End
if (c == -1)
conf->mode = FIREPERF_MODE_SERVER;
break;
+ case 't':
+ conf->timeout = strtoul(optarg, NULL, 10);
+ break;
+
default:
done = 1;
break;
.mode = FIREPERF_MODE_NONE,
.port = DEFAULT_PORT,
.parallel = DEFAULT_PARALLEL,
+ .timeout = DEFAULT_TIMEOUT,
};
int r;
#define DEFAULT_LOG_LEVEL LOG_INFO
#define DEFAULT_PARALLEL 1
#define DEFAULT_PORT 5001
+#define DEFAULT_TIMEOUT 300
#define MAX_PARALLEL (1 << 20)
struct in6_addr address;
int port;
unsigned long parallel;
+ unsigned int timeout;
};
#endif /* FIREPERF_MAIN_H */