Important: The information in this document is obsolete and should not be used for new development.
Ending a Session and Closing a Port
After data is written and read in, use thePPCEndfunction to end the session (identified by the session reference number). You may receive an error if you use thePPCEndfunction to end a session that has already been terminated.Listing 11-18 illustrates how you use the
PPCEndfunction to end a session.Listing 11-18 Ending a PPC session using the
PPCEndfunction
FUNCTION MyPPCEnd(theSessRefNum: PPCSessRefNum): OSErr; VAR thePPCEndPBRec: PPCEndPBRec; BEGIN thePPCEndPBRec.sessRefNum := theSessRefNum; MyPPCEnd := PPCEnd(@thePPCEndPBRec, FALSE); {synchronous} END;ThePPCEndfunction causes all calls to thePPCReadandPPCWritefunctions to complete (with asessClosedErrresult code) and invalidates the session reference number. ThePPCEndfunction also releases any PPC Toolbox resources so that they can be reused.Use the
PPCClosefunction to close the port specified by the port reference number. When you close a port, all sessions associated with a port are ended. Any active asynchronous calls associated with a session then call their completion routines (if they have one).Listing 11-19 illustrates how you use the
PPCClosefunction to close a port.Listing 11-19 Closing a PPC port using the
PPCClosefunction
FUNCTION MyPPCClose(thePortRefNum: PPCPortRefNum): OSErr; VAR theClosePBRec: PPCClosePBRec; BEGIN theClosePBRec.portRefNum := thePortRefNum; {from PPCOpen} MyPPCClose := PPCClose(@theClosePBRec, FALSE); {synchronous} END;In this example, the call toPPCCloseis made synchronously.