minow@bolt.enet.dec.com (Martin Minow) (01/19/91)
When I try to use the PPC Toolbox, my application hangs in PPCInformAsync() (Using the System 7 Beta release and the Think C libraries on the Beta CD). Is this a problem with the PPC Toolbox, the Think interface glue, or my programming? Here's a sample program to illustrate the problem: All help appreciated. Martin Minow minow@bolt.enet.dec.com ------ #include <PPCToolbox.h> OSErr status; PPCOpenPBRec pbOpenRec; PPCInformPBRec pbInform; PPCClosePBRec pbClose; PPCPortRec portRec; LocationNameRec locationNameRec; Str255 userName; short portRefNum; Boolean nbpRegistered; #define pstrcpy(dst, src) BlockMove(src, dst, src[0] + 1) int main(int argc, char *argv[]); void OpenPort(void); void TryInform(void); void ClosePort(void); void check(void); int main( int argc, char *argv[] ) { status = PPCInit(); check(); OpenPort(); TryInform(); ClosePort(); DebugStr("\pFinished"); } void OpenPort() { pbOpenRec.serviceType = ppcServiceRealTime; pbOpenRec.resFlag = 0; pbOpenRec.networkVisible = TRUE; portRec.nameScript = GetEnvirons(smSysScript); pstrcpy(portRec.name, "\pMyPortName"); portRec.portKindSelector = ppcByString; pstrcpy(portRec.u.portTypeStr, "\pMyPortType"); pbOpenRec.portName = &portRec; status = PPCOpenSync(&pbOpenRec); check(); portRefNum = pbOpenRec.portRefNum; nbpRegistered = pbOpenRec.nbpRegistered; } void TryInform() { pbInform.portRefNum = portRefNum; pbInform.autoAccept = TRUE; pbInform.portName = &portRec; pbInform.locationName = &locationNameRec; pbInform.userName = userName; DebugStr("\pThe following never returns!"); status = PPCInformAsync(&pbInform); /* <- Hangs here! */ check(); } void ClosePort() { if (portRefNum != 0) { pbClose.portRefNum = portRefNum; portRefNum = 0; /* Prevent recursion */ status = PPCCloseSync(&pbClose); check(); } } void check() { Str255 errorMsg; if (status != noErr) { NumToString(status, errorMsg); DebugStr(errorMsg); ClosePort(); ExitToShell(); } }
keith@Apple.COM (Keith Rollin) (01/19/91)
In article <19139@shlump.nac.dec.com> minow@bolt.enet.dec.com (Martin Minow) writes: >When I try to use the PPC Toolbox, my application hangs in PPCInformAsync() >(Using the System 7 Beta release and the Think C libraries on the Beta CD). > >Is this a problem with the PPC Toolbox, the Think interface glue, or >my programming? Here's a sample program to illustrate the problem: There was some confusion on the parts of the PPCToolBox guys, the MPW guys, and tradition. Tradition has is that asynchronous calls are signalled by setting a bit in the trap word. However, the PPCToolBox guys didn't know this, and decided that the asynchronicity of a call would depend on a boolean stored in the parameter block that you passed to the PPCToolBox. Accordingly, they wrote their glue routines to take the boolean out of the PPCxxx(pbPtr, boolean) calls and stuff them into the parameter block. Then the MPW guys came along and wrote all the PPCxxxSync and PPCxxxAsync inline versions of the calls. They assumed that the traditional approach was being used, and programmed the inlines to set the bit in the trap word. Since the PPCToolBox wasn't looking at the bit, all calls were effectively being performed synchronously. All of this will be fixed in the next releases of S7.0 and MPW. The traditional method will be followed. In the meantime, don't use the inline versions of the calls; use the versions that take the boolean as the parameter. -- ------------------------------------------------------------------------------ Keith Rollin --- Apple Computer, Inc. --- Developer Technical Support INTERNET: keith@apple.com UUCP: {decwrl, hoptoad, nsc, sun, amdahl}!apple!keith "Argue for your Apple, and sure enough, it's yours" - Keith Rollin, Contusions