From: Michael Tremer Date: Wed, 3 Feb 2021 23:19:38 +0000 (+0000) Subject: client: Add scaffolding to dump stats X-Git-Tag: 0.1.0~12 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=7839d6ff31a2e792b08b5b6de1846574ba27689a;p=fireperf.git client: Add scaffolding to dump stats Signed-off-by: Michael Tremer --- diff --git a/src/client.c b/src/client.c index 9c35faa..7e6c8d1 100644 --- a/src/client.c +++ b/src/client.c @@ -101,6 +101,12 @@ static const char* fireperf_random_pool_get_slice(struct fireperf_random_pool* p return pool->data + offset; } +static int dump_stats(struct fireperf_config* conf, struct fireperf_client_stats* stats) { + INFO(conf, "Dumping stats...\n"); + + return 0; +} + static int open_connection(struct fireperf_config* conf) { // Open a new socket int fd = socket(AF_INET6, SOCK_STREAM|SOCK_NONBLOCK|SOCK_CLOEXEC, 0); @@ -281,22 +287,40 @@ int fireperf_client(struct fireperf_config* conf, int epollfd, int timerfd) { // What type of event are we handling? - // Has the socket been disconnected? - if (events[i].events & EPOLLHUP) { - if (epoll_ctl(epollfd, EPOLL_CTL_DEL, fd, NULL)) { - ERROR(conf, "Could not remove socket file descriptor from epoll(): %s\n", - strerror(errno)); + // Handle timer events + if (fd == timerfd) { + uint64_t expirations; + + // Read from the timer to disarm it + ssize_t bytes_read = read(timerfd, &expirations, sizeof(expirations)); + if (bytes_read <= 0) { + ERROR(conf, "Could not read from timerfd: %s\n", strerror(errno)); goto ERROR; } - close(fd); - - stats.connections--; - - } else if (events[i].events & EPOLLOUT) { - r = send_data_to_server(conf, fd, pool); + r = dump_stats(conf, &stats); if (r) goto ERROR; + + // Handle connection sockets + } else { + // Has the socket been disconnected? + if (events[i].events & EPOLLHUP) { + if (epoll_ctl(epollfd, EPOLL_CTL_DEL, fd, NULL)) { + ERROR(conf, "Could not remove socket file descriptor from epoll(): %s\n", + strerror(errno)); + goto ERROR; + } + + close(fd); + + stats.connections--; + + } else if (events[i].events & EPOLLOUT) { + r = send_data_to_server(conf, fd, pool); + if (r) + goto ERROR; + } } } }