Synchronous versus Asynchronous Behavior

All functions with the exception of lineInitialize, lineShutdown, phoneInitialize, and phoneShutdown can operate synchronously or asynchronously. Both Initialize and Shutdown functions always operate synchronously. The implementations of such functions have the option to either execute the entire request before the application's thread is allowed to return from the function call (this is synchronous behavior) or the function implementation can forward the request, for example, to the switch or network, and return from the function call before the request has executed in its entirety (this is asynchonous behavior). When the request later completes, a reply message is sent to the application to notify it.

To reflect this to the application, three classes of return values are used by function calls, one of two are used in the asynchonous reply message. A value of zero implies that the whole request was carried out successfully. Success can be returned by a function or in a reply message. A negative value indicates an error condition. The exact error number provides an indication of the nature of the error. Error numbers can be returned by a function or in a reply message, and for a given request, the possible function error returns and reply message error returns are the same. Finally, when a function operates asynchronously, a positive request ID is returned to the application. This positive number tells the application that the request is operating asynchronously and that a reply message will be sent later. The request ID value is passed in the reply message to allow the application to relate the reply to the original request. Request IDs are reused over time.

Note that the Telephony DLL and/or service provider is free to have a request behave synchronously one time, and asynchronously the next. A practical example of where this may be useful is when information that is normally stored on a server may be cached in the client PC. When a request hits the cache, the request may behave synchronously; otherwise, it may be more appropriate to release the application's thread and execute the request asynchronously.