ADC Home > Reference Library > Technical Q&As > Networking > Carbon >

Not Recommended Documentclose button

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

Current information on this Reference Library topic can be found here:

Calling CloseOpenTransport When Writing an App


Q:I read somewhere that you don't have to call CloseOpenTransport if you're writing an application. Is this true?

A: Yes and no. The original OT programming documentation stated that calling CloseOpenTransport was optional for applications. There is however a bug in OT 1.1 and earlier which will not properly clean up PPC native applications when they terminate unless CloseOpenTransport is called.

Here are some rules of thumb:

  1. Non-application code must always call CloseOpenTransport when it terminates.
  2. It is best if 68K applications call CloseOpenTransport, but they will be cleaned up automatically if they don't.
  3. Make sure that PPC applications running under OT 1.1 or earlier call CloseOpenTransport when terminating.

One way of ensuring that you comply with point 3 is to use a CFM terminate procedure in your main application fragment, such as:


static Boolean gOTInited = false;
void CFMTerminate(void)
{
   if (gOTInited) {
       gOTInited = false;
       (void) CloseOpenTransport();
   }
}
void main(void)
{
    OSStatus err;
    err = InitOpenTransport();
    gOTInited = (err == noErr);
    // the rest of your application
    if (gOTInited) {
        (void) CloseOpenTransport();
        gOTInited = false;
    }
}

Note:
Calling CloseOpenTransport is always required for non-application programs.



Note:
When the Mac OS provides an automatic clean up mechanism, it's normally intended as a "safety net." It's generally a good idea to do your own clean up, at least for normal application termination.


[Jul 03 1996]


Did this document help you?
Yes: Tell us what works for you.
It’s good, but: Report typos, inaccuracies, and so forth.
It wasn’t helpful: Tell us what would have helped.