develop-13 9313 March 1993
From the originals
13 scansMachine-transcribed text and image descriptions. Check the linked original for uncertain words or fine print.
These are transcribed pages from the documents, not the full publications. Open the original for the remaining pages.
PDF page 12
they’ve completed the task until 23 hours later (a 23-hour latency). To avoid latency, use completion routines instead of polling ioResult to find out when a routine completes. USING COMPLETION ROUTINES Making an asynchronous call with a completion routine is only slightly more complex than polling for completion. A completion routine is a procedure that’s called as soon as the asynchronous function completes its task. When your program fills in the parameter block to pass to the function, it sets the ioCompletion field to point to the completion routine. Then, after calling the function asynchronously, your program can continue. When the function completes, the system interrupts the program that’s running and the completion routine is executed. (There are some special things you need to know about function results to use this model; see “Function Results and Function Completion.”) Since the completion routine is executed as soon as the function’s task is complete, your program finds out about completion immediately and can start processing the results of the function. Using a completion routine is like giving someone a task and then asking them to call you as soon as they’ve completed it. Because a completion routine may be called at interrupt time, it can’t assume things that most application code can. When a completion routine for an asynchronous function gets control, the system is in the following state: • On entry, register A0 points to the parameter block used to make the asynchronous call. d e v e l o p March 1993 10 Not all function results are equal. Ignore some, pay attention to others. Ignore function results from asynchronous File Manager and PPC Toolbox calls. They contain no useful information. To get useful result information, wait for the call to complete, then check ioResult or register D0; both contain the result. Both the File Manager and the PPC Toolbox will always call your completion routine if you specified one. If you didn’t supply one, and instead are polling, test ioResult in your parameter block. The call has completed if ioResult is less than or equal to noErr. Don’t ignore function results from asynchronous Device Manager calls (for example, AppleTalk driver, Serial Driver, and disk driver calls). The function result tells you whether the Device Manager successfully delivered your request to the device driver. Success is indicated by noErr; any other value indicates failure. The system calls your completion routine only if the Device Manager successfully delivered your request to the driver. On completion, check whether your call succeeded by looking in ioResult or register D0. FUNCTION RESULTS AND FUNCTION COMPLETION BY SCOTT BOYD AND JIM LUTHER
Reading notes: Page number '10' and running header text appear mid-passage; reading order around the sidebar block is uncertain.
- Printed dates
- March 1993
- Languages
- English