Path: utzoo!utgpu!news-server.csri.toronto.edu!rpi!zaphod.mps.ohio-state.edu!swrinde!cs.utexas.edu!sun-barr!rutgers!cbmvax!drysdale From: drysdale@cbmvax.commodore.com (Scott Drysdale) Newsgroups: comp.sys.amiga.programmer Subject: Re: Message Ports Message-ID: <22192@cbmvax.commodore.com> Date: 5 Jun 91 22:38:06 GMT References: Reply-To: drysdale@cbmvax.commodore.com (Scott Drysdale) Distribution: comp Organization: Commodore, West Chester, PA Lines: 74 In article bart@asgard.pub.uu.oz.au (John Butcher) writes: >Ive been trying to do message ports, but I havent had lots of success, my ports >wont get properly recognized by name. Below small test program I wrote : > >main( argc, argv ) > int argc; > char *argv[]; >{ > struct MsgPort *mp; > > mp = FindPort( argv[1] ); > if ( mp == NULL ) /* No port with that name */ > { > mp = CreatePort( argv[1], 0 ); /* so create one ! */ CreatePort() simply points to the name you give it (argv[1] in your case). you want to do something like this: char *name; name = AllocMem(strlen(argv[1]) + 1, MEMF_PUBLIC); strcpy(name, argv[1]); mp = CreatePort(name, 0); *note* do NOT free(name) - you want the port to live forever (or until you delete it, whichever comes first). > printf("Created \"%s\" at 0x%0x\n", argv[1], mp ); > } > else /* found the given port */ > { > printf("Found \"%s\" at 0x%0x\n", argv[1], mp ); FreeMem(mp->mp_Node.ln_Name, strlen(mp->mp_Node.ln_Name) + 1); > DeletePort( mp ); /* so remove it */ > } >} > >And here is some test runs.... ( with added comments ;-) > >2.RAMB0:> port crud >Created "crud" at 0x208d28 Yay, it created ok !! seems to behave as you desire. the port is allocated and initialized. however, the port's name points to argv[1], which is transient. >2.RAMB0:> port anticrud >Found "anticrud" at 0x208d28 Whats this, I thought I called you crud ! this time it runs, the port's name still points to the memory for argv[1], which just happens to be the same physical address as before. ie, the port's name now points to the name on the command line, so of course it'll find the port. >2.RAMB0:> port crud >Created "crud" at 0x208d28 Yep, well it created ok ad nauseum. >2.RAMB0:> port zzzz >Found "zzzz" at 0x208d28 But a different name is found at the address >So....Can anyone tell me what is going on ?? > John Butcher : bart@asgard.pub.uu.oz.au --Scotty -- =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= Scott Drysdale Software Engineer Commodore Amiga Inc. UUCP {allegra|burdvax|rutgers|ihnp4}!cbmvax!drysdale PHONE - yes. "Have you hugged your hog today?" =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=