Skip to content

Commit 75a9d54

Browse files
Darleletcapflam
authored andcommitted
DOC: api/event_hdl: small updates, fix an example and add some precisions
Fix an example suggesting that using EVENT_HDL_SUB_TYPE(x, y) with y being 0 was valid. Then add some notes to explain how to use EVENT_HDL_SUB_FAMILY() and EVENT_HDL_SUB_TYPE() with valid values. Also mention that the feature is available starting from 2.8 and not 2.7. Finally, perform some purely cosmetic updates. This could be backported in 2.8. (cherry picked from commit 13e0972) Signed-off-by: Christopher Faulet <[email protected]>
1 parent a4c5cae commit 75a9d54

File tree

1 file changed

+28
-17
lines changed

1 file changed

+28
-17
lines changed

doc/internals/api/event_hdl.txt

Lines changed: 28 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
-----------------------------------------
22
event_hdl Guide - version 2.8
3-
( Last update: 2022-11-14 )
3+
( Last update: 2024-06-21 )
44
------------------------------------------
55

66
ABSTRACT
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
1010
handle general events in a simple to maintain fashion, while keeping core code
1111
impact to the bare minimum.
1212

@@ -38,7 +38,7 @@ SUMMARY
3838

3939

4040
1. EVENT_HDL INTRODUCTION
41-
-----------------------
41+
-------------------------
4242

4343
EVENT_HDL provides two complementary APIs, both are implemented
4444
in 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

5454
2. HOW TO HANDLE EXISTING EVENTS
55-
---------------------
55+
--------------------------------
5656

5757
To handle existing events, you must first decide which events you're
5858
interested in.
@@ -197,7 +197,7 @@ event subscription is performed using the function:
197197
As the name implies, anonymous subscriptions don't support lookups.
198198

199199
2.1 SYNC MODE
200-
---------------------
200+
-------------
201201

202202
Example, you want to register a sync handler that will be called when
203203
a new server is added.
@@ -280,12 +280,12 @@ identified subscription where freeing private is required when subscription ends
280280
```
281281

282282
2.2 ASYNC MODE
283-
---------------------
283+
--------------
284284

285285
As mentioned before, async mode comes in 2 flavors, normal and task.
286286

287287
2.2.1 NORMAL VERSION
288-
---------------------
288+
--------------------
289289

290290
Normal 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

381381
2.2.2 TASK VERSION
382-
---------------------
382+
------------------
383383

384384
task version requires a bit more setup, but it's pretty
385385
straightforward 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

512512
2.3 ADVANCED FEATURES
513-
-----------------------
513+
---------------------
514514

515515
We've already covered some of these features in the previous examples.
516516
Here is a documented recap.
517517

518518

519519
2.3.1 SUB MGMT
520-
-----------------------
520+
--------------
521521

522522
From 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

567567
2.3.2 SUBSCRIPTION EXTERNAL LOOKUPS
568-
-----------------------
568+
-----------------------------------
569569

570570
As you've seen in 2.3.1, managing the subscription directly
571571
from the handler is a possibility.
@@ -620,7 +620,7 @@ unsubscribing:
620620
```
621621

622622
2.3.3 SUBSCRIPTION PTR
623-
-----------------------
623+
----------------------
624624

625625
To manage existing subscriptions from external code,
626626
we already talked about identified subscriptions that
@@ -720,7 +720,7 @@ Example:
720720
```
721721

722722
2.3.4 PRIVATE FREE
723-
-----------------------
723+
------------------
724724

725725
Upon handler subscription, you have the ability to provide
726726
a private data pointer that will be passed to the handler
@@ -777,7 +777,7 @@ Then:
777777
```
778778

779779
3 HOW TO ADD SUPPORT FOR NEW EVENTS
780-
-----------------------
780+
-----------------------------------
781781

782782
Adding 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
787787
You might want to declare a whole new event family, in which case
788788
you 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

795806
Then, 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

805816
3.1 DECLARING A NEW EVENT DATA STRUCTURE
806-
-----------------------
817+
----------------------------------------
807818

808819
You have the ability to provide additional data for a given
809820
event family when such events occur.
@@ -943,7 +954,7 @@ Event publishing can be performed from anywhere in the code.
943954
--------------------------------------------------------------------------------
944955

945956
4 SUBSCRIPTION LISTS
946-
-----------------------
957+
--------------------
947958

948959
As you may already know, EVENT_HDL API main functions rely on
949960
subscription lists.

0 commit comments

Comments
 (0)