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 thePPCEnd
function to end the session (identified by the session reference number). You may receive an error if you use thePPCEnd
function to end a session that has already been terminated.Listing 11-18 illustrates how you use the
PPCEnd
function to end a session.Listing 11-18 Ending a PPC session using the
PPCEnd
function
FUNCTION MyPPCEnd(theSessRefNum: PPCSessRefNum): OSErr; VAR thePPCEndPBRec: PPCEndPBRec; BEGIN thePPCEndPBRec.sessRefNum := theSessRefNum; MyPPCEnd := PPCEnd(@thePPCEndPBRec, FALSE); {synchronous} END;ThePPCEnd
function causes all calls to thePPCRead
andPPCWrite
functions to complete (with asessClosedErr
result code) and invalidates the session reference number. ThePPCEnd
function also releases any PPC Toolbox resources so that they can be reused.Use the
PPCClose
function 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
PPCClose
function to close a port.Listing 11-19 Closing a PPC port using the
PPCClose
function
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 toPPCClose
is made synchronously.