Important: The information in this document is obsolete and should not be used for new development.
Executing Routines Synchronously or Asynchronously
Your program can execute the routines that make up the interface to the AppleTalk protocols either synchronously or asynchronously. Synchronous execution means that your program is prevented from doing any other processing until the current operation completes. Asynchronous execution means that the system returns control to your program after your program calls the routine so that your program can continue with other processing while the asynchronous operation completes.If you execute a routine synchronously, the call does not return until the operation completes; you do not have to use a completion routine that runs at interrupt level or poll a result field to determine when the operation completes; on the other hand, your program cannot continue running until the call returns, which causes the system to come to a standstill. Synchronous calls are useful for operations that execute and return to the calling program quickly, such as opening or closing sockets. On an AppleTalk internet, data is transferred between sockets, which must be opened before they can be used and closed when they are no longer needed.
Calling a routine asynchronously directs the system software to begin the operation process now, return control to the calling program, then complete execution of the routine as soon as possible. Asynchronous execution eliminates program execution delay time, but it requires that your application provide a means of determining when the operation has completed execution. There are two methods an application can use to determine when an operation completes execution:
The parameter block that is used to contain input and output information for
- An application can provide a completion routine to be called at interrupt level.
- An application can poll the routine's parameter block result field.
a function includes a result field calledioResult
. When your application calls a
function asynchronously,
When the function completes execution, the driver sets the result field to a value that indicates either that no error occurred (
- the driver executes the function, if possible.
- if the driver is busy, the driver queues the function and sets the
ioResult
field to 1.
noErr
) or an error condition code value that identifies the type of error.Polling the Result Field
Your application can poll the result field to determine when the result value changes. Your application can use the polling process to inform the user that the system is still busy performing the operation that handles the request; for processes that may take a long time, your application can display a progress dialog box to the user.
- Note
- If you use polling, you must set the call's parameter block
ioCompletion
field toNIL
.Using a Completion Routine
Instead of polling the result field, your application can supply a completion routine to
be executed at interrupt level when the operation completes. You provide the address
of the completion routine in the call's parameter blockioCompletion
field. Because completion routines are executed at interrupt level, they cannot call any routines that move memory.