xref: /aosp_15_r20/external/mdnsresponder/mDNSCore/Implementer Notes.txt (revision 48a54d368dc4fa860885eef7b70b6c53499e7c25)
1*48a54d36SAndroid Build Coastguard WorkerFebruary 2002:
2*48a54d36SAndroid Build Coastguard Worker
3*48a54d36SAndroid Build Coastguard WorkerThe mDNSResponder code has a slight architectural change to improve
4*48a54d36SAndroid Build Coastguard Workerefficiency.
5*48a54d36SAndroid Build Coastguard Worker
6*48a54d36SAndroid Build Coastguard WorkerThe mDNSResponder code previously called ScheduleNextTask() after every
7*48a54d36SAndroid Build Coastguard Workeroperation, to calculate the time at which it needed to be called back to
8*48a54d36SAndroid Build Coastguard Workerperform its next timed operation. When the workload is light, and
9*48a54d36SAndroid Build Coastguard Workerprotocol operations are rare and far apart, this makes sense.
10*48a54d36SAndroid Build Coastguard Worker
11*48a54d36SAndroid Build Coastguard WorkerHowever, on networks where there is a lot of mDNS traffic (or the CPU is
12*48a54d36SAndroid Build Coastguard Workerslow), this leads to the following anomolous behaviour: mDNSResponder
13*48a54d36SAndroid Build Coastguard Workerspends a lot of CPU time working out what to do next, when what it needs
14*48a54d36SAndroid Build Coastguard Workerto do next should be obvious: Finish processing the big backlog of
15*48a54d36SAndroid Build Coastguard Workerpackets that have been received.
16*48a54d36SAndroid Build Coastguard Worker
17*48a54d36SAndroid Build Coastguard WorkerTo remedy this, mDNSResponder now only executes ScheduleNextTask() when
18*48a54d36SAndroid Build Coastguard Workerthere is no other obvious work waiting to be done. However, the
19*48a54d36SAndroid Build Coastguard WorkermDNSResponder code does not have direct access to this knowledge. Only
20*48a54d36SAndroid Build Coastguard Workerthe platform layer below knows whether there are packets waiting to be
21*48a54d36SAndroid Build Coastguard Workerprocessed. Only the client layer above knows whether it is in the
22*48a54d36SAndroid Build Coastguard Workerprocess of performing a long sequence of back-to-back mDNS API calls.
23*48a54d36SAndroid Build Coastguard Worker
24*48a54d36SAndroid Build Coastguard WorkerThis means that the new architecture places an additional responsibility
25*48a54d36SAndroid Build Coastguard Workeron the client layer and/or platform support layer. As long as they have
26*48a54d36SAndroid Build Coastguard Workerimmediate work to do, they should call the appropriate mDNSCore routines
27*48a54d36SAndroid Build Coastguard Workerto accomplish that work. With each call, mDNSCore will do only what it
28*48a54d36SAndroid Build Coastguard Workerimmediately has to do to satisfy the call. Any optional work will be
29*48a54d36SAndroid Build Coastguard Workerdeferred. As soon as there is no more immediate work to do, the calling
30*48a54d36SAndroid Build Coastguard Workerlayer MUST call mDNS_Execute(). Failure to call mDNS_Execute() will lead
31*48a54d36SAndroid Build Coastguard Workerto unreliable or incorrect operation.
32*48a54d36SAndroid Build Coastguard Worker
33*48a54d36SAndroid Build Coastguard WorkerThe value returned from mDNS_Execute() is the next time (in absolute
34*48a54d36SAndroid Build Coastguard Workerplatform time units) at which mDNS_Execute() MUST be called again to
35*48a54d36SAndroid Build Coastguard Workerperform its next necessary operation (e.g. transmitting its next
36*48a54d36SAndroid Build Coastguard Workerscheduled query packet, etc.) Note that the time returned is an absolute
37*48a54d36SAndroid Build Coastguard Workertime, not the time *interval* between now and the next required call.
38*48a54d36SAndroid Build Coastguard WorkerFor OS APIs that work in terms of intervals instead of absolute times,
39*48a54d36SAndroid Build Coastguard WorkermDNSPlatformTimeNow() must be subtracted from the absolute time to get
40*48a54d36SAndroid Build Coastguard Workerthe interval between now and the next event.
41*48a54d36SAndroid Build Coastguard Worker
42*48a54d36SAndroid Build Coastguard WorkerIn a single-threaded application using a blocking select() call as its
43*48a54d36SAndroid Build Coastguard Workermain synchronization point, this means that you should call
44*48a54d36SAndroid Build Coastguard WorkermDNS_Execute() before calling select(), and the timeout value you pass
45*48a54d36SAndroid Build Coastguard Workerto select() MUST NOT be larger than that indicated by the result
46*48a54d36SAndroid Build Coastguard Workerreturned from mDNS_Execute(). After the blocking select() call returns,
47*48a54d36SAndroid Build Coastguard Workeryou should do whatever work you have to do, and then, if mDNS packets
48*48a54d36SAndroid Build Coastguard Workerwere received, or mDNS API calls were made, be sure to call
49*48a54d36SAndroid Build Coastguard WorkermDNS_Execute() again, and if necessary adjust your timeout value
50*48a54d36SAndroid Build Coastguard Workeraccordingly, before going back into the select() call.
51*48a54d36SAndroid Build Coastguard Worker
52*48a54d36SAndroid Build Coastguard WorkerIn an asynchronous or interrupt-driven application, there are three
53*48a54d36SAndroid Build Coastguard Workerplaces that should call mDNS_Execute():
54*48a54d36SAndroid Build Coastguard Worker
55*48a54d36SAndroid Build Coastguard Worker1. After delivering received packets, the platform support layer should
56*48a54d36SAndroid Build Coastguard Workercall mDNS_Execute(), and use the value returned to set the platform
57*48a54d36SAndroid Build Coastguard Workercallback timer to fire at the indicated time.
58*48a54d36SAndroid Build Coastguard Worker
59*48a54d36SAndroid Build Coastguard Worker2. After making any mDNS API call or series of calls, the client layer
60*48a54d36SAndroid Build Coastguard Workershould call mDNS_Execute(), and use the value returned to set the
61*48a54d36SAndroid Build Coastguard Workerplatform callback timer to fire at the indicated time.
62*48a54d36SAndroid Build Coastguard Worker
63*48a54d36SAndroid Build Coastguard Worker3. When the platform callback timer fires, it should call mDNS_Execute()
64*48a54d36SAndroid Build Coastguard Worker(to allow mDNSCore to perform its necessary work) and then the timer
65*48a54d36SAndroid Build Coastguard Workerroutine use the result returned to reset itself to fire at the right
66*48a54d36SAndroid Build Coastguard Workertime for the next scheduled event.
67