]> git.ipfire.org Git - fireperf.git/commitdiff
client: Add scaffolding to dump stats
authorMichael Tremer <michael.tremer@ipfire.org>
Wed, 3 Feb 2021 23:19:38 +0000 (23:19 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Wed, 3 Feb 2021 23:19:38 +0000 (23:19 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/client.c

index 9c35faae36c629782d22b08642368dd728ae1856..7e6c8d1f43eb241f9559b8ca7a000f23d1c8a288 100644 (file)
@@ -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;
+                               }
                        }
                }
        }