Important: The information in this document is obsolete and should not be used for new development.
Closing Open Transport
This section describes the steps you should take when you no longer need Open Transport. Although the Mac OS provides an automatic clean-up mechanism for applications that call Open Transport functions, it is intended only as a safety net. It's a good idea to do your own clean up, at least for normal application termination. In addition non-application programs are always required to close Open Transport.System software cannot unload the Open Transport kernel until the last program on the computer that called the
InitOpenTransportorInitOpenTransportUtilitiesfunction has also called theCloseOpenTransportfunction. So, if your application only uses the network occasionally, it might be wise to initialize Open Transport only when you need the network, and to close Open Transport immediately after you stop using it.Closing From Applications
When you are no longer using Open Transport, you can unload the Open Transport software modules by calling theCloseOpenTransportfunction.It is best if 68000 applications call the
CloseOpenTransportfunction, but this will be done automatically if they don't.
Listing 2-3 CFM terminate procedure
- Note
 - If you are running PowerPC applications under version 1.1 (or earlier) of Open Transport, you must call the
 CloseOpenTransportfunction when terminating. One way to make sure that you do this is to use a CFM terminate procedure in your main application fragment, as shown in Listing 2-3. If you set the appropriate linker option, the system will call theCFMTerminateprocedure regardless of how your application terminates.![]()
static Boolean gOTInited = false; void CFMTerminate (void);/* do this if abnormal termination */ { if (gOTInited) { gOTInited = false; (void) CloseOpenTransport(); } } void main (void) { OSStatus err; err = InitOpenTransport(); gOTInited = (err ==noErr); /* the rest of your application goes here */ if (gOTInited) /* do this for normal termination */ { gOTInited = false; (void) CloseOpenTransport(); } }
- Note
 - Open Transport only provides CFM support for 68000 code beginning with version 1.3
 ![]()
Closing From Stand-Alone Code
For stand-alone code segments, you must call theCloseOpenTransportfunction before you unload from memory. Note that Open Transport only unloads if all clients are done using Open Transport and have called theCloseOpenTransportfunction.
Subtopics
- Closing From Applications
 - Closing From Stand-Alone Code