]> git.ipfire.org Git - thirdparty/squid.git/blame - src/base/AsyncCalls.dox
Update the Comm:: API for read(2)
[thirdparty/squid.git] / src / base / AsyncCalls.dox
CommitLineData
946b016d
AR
1/**
2\defgroup AsyncCalls Asynchronous Calls
3\ingroup Components
4
5
6\section Terminology Terminology
7
8- \b Call: an AsyncCall object meant to be delivered from the Caller to the
9 Recipient.
10- \b Recipient: the code being the destination of the Call. The specific
11 function receiving the call is often called "handler".
12- \b Caller: the code scheduling or placing the Call.
13- \b Creator: the code creating the Call.
14- \b Dialing: the final act of delivering the Call to the Recipient.
15- \b Canceling: preventing the call from being dialed in the future.
16- <b>Pending call</b>: the call which has been scheduled but no attempt to dial
17 it has been made.
18- <b>Live call</b>: the in-progress call that has been dialed and the Recipient
19 (receiving) function has not finished yet.
20
21
22\section Life Typical life cycle
23
24-# Creator creates a Call object and stores its pointer, possibly in a
25temporary variable. If Creator is the future Recipient of the Call, it
26is customary to talk about a "callback". In such context, Creator gives
27the Call pointer to some other code (the future Caller). Calls are
28refcounted and the AsyncCall::Pointer class must be used to point and
29share them.
30-# Time passes and something triggers the need to dial the call.
31-# Caller schedules (a.k.a, places) the Call. The Call is placed in the
32AsyncCallQueue. The queue preserves the scheduling call order.
33-# Time passes and it is now time to dial the call.
34-# AsyncCallQueue checks whether the call can be dialed. If yes,
35AsyncCallQueue dials the Call and the Recipient receives it. Otherwise,
36only a debugging message is logged (if enabled). Dialing a call involves
37several state checks at several stages, depending on the Call type.
38-# The Call is alive while the Recipient is handling it. That state ends
39when the Recipient code (a.k.a., handler) returns. At that point, the
40AsyncCallQueue proceeds to handle other calls.
41-# The Call object is destroyed when the last reference to it is gone.
42One should not try to invalidate or delete the call.
43
44
45\section Rules Basic rules
46
47- Callbacks must be called: If a Caller has a Call pointer as a
48callback, the Caller must make that Call when conditions are right
49(possibly with a call-specific error indicator). Whether that Call will
50be dialed is irrelevant here.
51
52- Unwanted calls must be canceled: If Recipient may not be able to
53handle the call back, then it must cancel it. Whether that Call will be
54scheduled is irrelevant here. If the Recipient has an AsyncCall pointer,
55calling AsyncCall::cancel is sufficient, but the code should use
56call-specific APIs when possible (e.g., comm_read_cancel or comm_close).
57
58- Processed calls should be forgotten: If you scheduled, received, or
59cancel the call, set its pointer to NULL. The Caller should forget the
60call after scheduling it. the recipient should forget the call when it
61receives or cancels it. These are just cleanup rules to avoid
62double-scheduling or double-cancellation as well as situations where the
63code assumes it can still change a pending Call (which will not work for
64SMP code).
65
66- The calls are received in the order they were scheduled.
67
68- The Recipient is guaranteed to receive at most one Call at a time. An
69attempt to dial call B while some call A is alive is a bug, and call B
70will not be dialed.
71
72
73\section Canceling Call Canceling
74
75- A call may be canceled at any time.
76
77- A canceled call will not be dialed.
78
79- Cancellation has immediate effect: The call will never be dialed
80after cancel() is called
81
82- Cancellation by non-Recipients is discouraged because it may not work
83in an SMP environment.
84
85- A late call cancellation is cancellation that is performed after the Call
86has already been dialed (i.e., the call is or was alive at the time of the
87cancellation). Late cancellation is a no-op. It is not a bug to cancel
88something late, but the canceling code should be aware of that possibility.
89
90
91*/