Legacy Documentclose button

Important: The information in this document is obsolete and should not be used for new development.

Previous Book Contents Book Index Next

Inside Macintosh: Networking With Open Transport / Part 1 - Open Transport Essentials
Chapter 2 - Getting Started With Open Transport


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 InitOpenTransport or InitOpenTransportUtilities function has also called the CloseOpenTransport function. 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 the CloseOpenTransport function.

It is best if 68000 applications call the CloseOpenTransport function, but this will be done automatically if they don't.

Note
If you are running PowerPC applications under version 1.1 (or earlier) of Open Transport, you must call the CloseOpenTransport function 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 the CFMTerminate procedure regardless of how your application terminates.
Listing 2-3 CFM terminate procedure

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 the CloseOpenTransport function before you unload from memory. Note that Open Transport only unloads if all clients are done using Open Transport and have called the CloseOpenTransport function.


Subtopics
Closing From Applications
Closing From Stand-Alone Code

Previous Book Contents Book Index Next

© Apple Computer, Inc.
15 JAN 1998