From 0598bf8533d070c4410193072506aa78da0faacd Mon Sep 17 00:00:00 2001 From: Quentin Dufour Date: Thu, 14 Feb 2019 18:08:20 +0100 Subject: [PATCH] WIP Measuring latency --- src/evt_core.c | 2 +- src/meas_lat.c | 42 +++++++++++++++++++++++++++++++++++++++--- 2 files changed, 40 insertions(+), 4 deletions(-) diff --git a/src/evt_core.c b/src/evt_core.c index 939bb85..469fc37 100644 --- a/src/evt_core.c +++ b/src/evt_core.c @@ -12,7 +12,7 @@ void free_char(void* c) { void free_cat(void* vcat) { struct evt_core_cat* cat = (struct evt_core_cat*) vcat; - cat->free_app_ctx(cat->app_ctx); + if (cat->free_app_ctx != NULL) cat->free_app_ctx(cat->app_ctx); g_array_free(cat->socklist, TRUE); free(cat->name); free(cat); diff --git a/src/meas_lat.c b/src/meas_lat.c index 14220b1..9572556 100644 --- a/src/meas_lat.c +++ b/src/meas_lat.c @@ -1,13 +1,49 @@ #include #include #include "evt_core.h" +#include "net_tools.h" -int main(void) { +struct timer_ctx { + uint64_t counter; +}; + +void on_udp(struct evt_core_ctx* ctx, struct evt_core_cat* cat, int fd) { +} + +void on_timer(struct evt_core_ctx* ctx, struct evt_core_cat* cat, int fd) { +} + +int main(int argc, char** argv) { + printf("~ measlat ~\n"); + if (argc < 3) exit(EXIT_FAILURE); + + struct timer_ctx apptime = {0}; struct evt_core_ctx evts = {0}; - struct evt_core_cat udp_read = {}; - struct evt_core_cat timer = {}; + struct evt_core_cat udp_read = { + .app_ctx = NULL, + .free_app_ctx = NULL, + .cb = on_udp, + .name = "udp-read", + .flags = EPOLLIN | EPOLLET, + .socklist = NULL + }; + struct evt_core_cat timer = { + .app_ctx = &apptime, + .free_app_ctx = NULL, + .cb = on_timer, + .name = "timer", + .flags = EPOLLIN | EPOLLET, + .socklist = NULL + }; evt_core_init(&evts); + evt_core_add_cat (&evts, &udp_read); + evt_core_add_cat(&evts, &timer); + printf("--- Categories registered\n"); + + int udp_sock = create_udp_client (argv[1], argv[2]); + evt_core_add_fd (&evts, "udp-read", udp_sock); + return 0; }