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: Interapplication Communication /
Chapter 11 - Program-to-Program Communications Toolbox / Using the PPC Toolbox


Ending a Session and Closing a Port

After data is written and read in, use the PPCEnd function to end the session (identified by the session reference number). You may receive an error if you use the PPCEnd 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;
The PPCEnd function causes all calls to the PPCRead and PPCWrite functions to complete (with a sessClosedErr result code) and invalidates the session reference number. The PPCEnd 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 to PPCClose is made synchronously.


Previous Book Contents Book Index Next

© Apple Computer, Inc.
7 JUL 1996