MINOR: event_hdl: provide event->when for advanced handlers
authorAurelien DARRAGON <adarragon@haproxy.com>
Tue, 4 Apr 2023 19:41:10 +0000 (21:41 +0200)
committerChristopher Faulet <cfaulet@haproxy.com>
Fri, 21 Apr 2023 12:36:45 +0000 (14:36 +0200)
For advanced async handlers only
(Registered using EVENT_HDL_ASYNC_TASK() macro):

event->when is provided as a struct timeval and fetched from 'date'
haproxy global variable.

Thanks to 'when', related event consumers will be able to timestamp
events, even if they don't work in real-time or near real-time.
Indeed, unlike sync or normal async handlers, advanced async handlers
could purposely delay the consumption of pending events, which means
that the date wouldn't be accurate if computed directly from within
the handler.

include/haproxy/event_hdl-t.h
src/event_hdl.c

index a8062d1..77e7d93 100644 (file)
@@ -23,6 +23,7 @@
 # define _HAPROXY_EVENT_HDL_T_H
 
 #include <stdint.h>
+#include <sys/time.h>
 
 #include <haproxy/api-t.h>
 
@@ -120,6 +121,7 @@ struct event_hdl_async_event
         */
        void                                    *data;
        void                                    *private;
+       struct timeval                          when;
        struct event_hdl_sub_mgmt               sub_mgmt;
 };
 
index 5ec8123..7bf0f16 100644 (file)
@@ -836,6 +836,7 @@ static int _event_hdl_publish(event_hdl_sub_list *sub_list, struct event_hdl_sub
                                }
                                new_event->type = e_type;
                                new_event->private = cur_sub->hdl.private;
+                               new_event->when = date;
                                new_event->sub_mgmt = EVENT_HDL_SUB_MGMT_ASYNC(cur_sub);
                                if (data) {
                                        /* if this fails, please adjust EVENT_HDL_ASYNC_EVENT_DATA in