11 -----------------------------------------
22 event_hdl Guide - version 2.8
3- ( Last update: 2022-11-14 )
3+ ( Last update: 2024-06-21 )
44 ------------------------------------------
55
66ABSTRACT
77--------
88
9- The event_hdl support is a new feature of HAProxy 2.7 . It is a way to easily
9+ The event_hdl support is a new feature of HAProxy 2.8 . It is a way to easily
1010handle general events in a simple to maintain fashion, while keeping core code
1111impact to the bare minimum.
1212
@@ -38,7 +38,7 @@ SUMMARY
3838
3939
40401. EVENT_HDL INTRODUCTION
41- -----------------------
41+ -------------------------
4242
4343EVENT_HDL provides two complementary APIs, both are implemented
4444in src/event_hdl.c and include/haproxy/event_hdl(-t).h:
@@ -52,7 +52,7 @@ an event that is happening in the process.
5252(See section 3.)
5353
54542. HOW TO HANDLE EXISTING EVENTS
55- ---------------------
55+ --------------------------------
5656
5757To handle existing events, you must first decide which events you're
5858interested in.
@@ -197,7 +197,7 @@ event subscription is performed using the function:
197197 As the name implies, anonymous subscriptions don't support lookups.
198198
1991992.1 SYNC MODE
200- ---------------------
200+ -------------
201201
202202Example, you want to register a sync handler that will be called when
203203a new server is added.
@@ -280,12 +280,12 @@ identified subscription where freeing private is required when subscription ends
280280```
281281
2822822.2 ASYNC MODE
283- ---------------------
283+ --------------
284284
285285As mentioned before, async mode comes in 2 flavors, normal and task.
286286
2872872.2.1 NORMAL VERSION
288- ---------------------
288+ --------------------
289289
290290Normal is meant to be really easy to use, and highly compatible with sync mode.
291291
@@ -379,7 +379,7 @@ identified subscription where freeing private is required when subscription ends
379379```
380380
3813812.2.2 TASK VERSION
382- ---------------------
382+ ------------------
383383
384384task version requires a bit more setup, but it's pretty
385385straightforward actually.
@@ -510,14 +510,14 @@ Note: it is not recommended to perform multiple subscriptions
510510 that might already be freed. Thus UAF will occur.
511511
5125122.3 ADVANCED FEATURES
513- -----------------------
513+ ---------------------
514514
515515We've already covered some of these features in the previous examples.
516516Here is a documented recap.
517517
518518
5195192.3.1 SUB MGMT
520- -----------------------
520+ --------------
521521
522522From an event handler context, either sync or async mode:
523523 You have the ability to directly manage the subscription
@@ -565,7 +565,7 @@ task and notify async modes (from the event):
565565```
566566
5675672.3.2 SUBSCRIPTION EXTERNAL LOOKUPS
568- -----------------------
568+ -----------------------------------
569569
570570As you've seen in 2.3.1, managing the subscription directly
571571from the handler is a possibility.
@@ -620,7 +620,7 @@ unsubscribing:
620620```
621621
6226222.3.3 SUBSCRIPTION PTR
623- -----------------------
623+ ----------------------
624624
625625To manage existing subscriptions from external code,
626626we already talked about identified subscriptions that
@@ -720,7 +720,7 @@ Example:
720720```
721721
7227222.3.4 PRIVATE FREE
723- -----------------------
723+ ------------------
724724
725725Upon handler subscription, you have the ability to provide
726726a private data pointer that will be passed to the handler
@@ -777,7 +777,7 @@ Then:
777777```
778778
7797793 HOW TO ADD SUPPORT FOR NEW EVENTS
780- -----------------------
780+ -----------------------------------
781781
782782Adding support for a new event is pretty straightforward.
783783
@@ -787,9 +787,20 @@ First, you need to declare a new event subtype in event_hdl-t.h file
787787You might want to declare a whole new event family, in which case
788788you declare both the new family and the associated subtypes (if any).
789789
790+ Up to 256 families containing 16 subtypes each are supported by the API.
791+ Family 0 is reserved for special events, which means there are 255 usable
792+ families.
793+
794+ You can declare a family using EVENT_HDL_SUB_FAMILY(x) where x is the
795+ family.
796+
797+ You can declare a subtype using EVENT_HDL_SUB_TYPE(x, y) where x is the
798+ family previously declared and y the subtype, Subtypes range from 1 to
799+ 16 (included), 0 is not a valid subtype.
800+
790801```
791802 #define EVENT_HDL_SUB_NEW_FAMILY EVENT_HDL_SUB_FAMILY(4)
792- #define EVENT_HDL_SUB_NEW_FAMILY_SUBTYPE_1 EVENT_HDL_SUB_TYPE(4,0 )
803+ #define EVENT_HDL_SUB_NEW_FAMILY_SUBTYPE_1 EVENT_HDL_SUB_TYPE(4,1 )
793804```
794805
795806Then, you need to update the event_hdl_sub_type_map map,
@@ -803,7 +814,7 @@ Please follow this procedure:
803814 You added a new family: go to section 3.1
804815
8058163.1 DECLARING A NEW EVENT DATA STRUCTURE
806- -----------------------
817+ ----------------------------------------
807818
808819You have the ability to provide additional data for a given
809820event family when such events occur.
@@ -943,7 +954,7 @@ Event publishing can be performed from anywhere in the code.
943954--------------------------------------------------------------------------------
944955
9459564 SUBSCRIPTION LISTS
946- -----------------------
957+ --------------------
947958
948959As you may already know, EVENT_HDL API main functions rely on
949960subscription lists.
0 commit comments