Path: utzoo!mnetor!uunet!husc6!cmcl2!rutgers!ames!ucbcad!ucbvax!CORY.BERKELEY.EDU!dillon From: dillon@CORY.BERKELEY.EDU (Matt Dillon) Newsgroups: comp.sys.amiga Subject: Re: Need help with signals Message-ID: <8801030156.AA04670@cory.Berkeley.EDU> Date: 3 Jan 88 01:56:40 GMT Sender: daemon@ucbvax.BERKELEY.EDU Lines: 68 Since you indicated a relative newness to programming on the Amiga I won't rattle you on your programming style. There are a couple of things wrong here... (*) Wait() clears all waited on signals before it returns. Wait also returns a mask of all requested signals which OCCURED... this is usually used before doing the more expensive GetMsg() or CheckIO() calls. You seem to be assumming that only one signal will come back at a time. In actuality, any one, two, or all the signals may come back at the same time. So if an intuition message occurs at the same time the serial completes, your code will never get to the serial due to your "ELSE IF" ... "if intuition message then to intuition stuff but DO NOT do serial stuff (even if serial message)" is what your code is doing. It gets even worse because your console handling section is also on the tail end of an ELSE... Fix #1: Make each IF independant, not dangling on the previous IF's else. Now, assumming that SerRead and ConRead are each message ports the rest of the code looks correct (at least what you've given us). In fact, your use of GetMsg() is one of the more interesting ways to check for IO completion (and remove the message from the reply port if the IO has completed). In the case of the code below, it only works if each request has its own reply port, which yours do. Most advanced programmers use only one reply port for all their requests and use CheckIO()/WaitIO() instead of GetMsg(). One addition you might want to make to the fragment below is to use the returned signal mask from Wait() as another IF level before making the more expensive GetMsg() calls: mask = Wait(blah) if ((mask & (1 << SerRead->mp_SigBit)) && GetMsg(SerRead)) { blah } -Matt : while(1){ : Wait((1L << MyWindow->UserPort->mp_SigBit) | : (1L << SerRead->mp_SigBit) | : (1L << ConRead->mp_SigBit)); : if(WinMsg = (struct IntuiMessage *)GetMsg(MyWindow->UserPort)){ : mclass = WinMsg->Class; : mcode = WinMsg->Code; : ReplyMsg(WinMsg); : if(mclass == CLOSEWINDOW){ : AbortIO(ser_in); : CloseSerial(); : cleanup("Exiting", 0); : break; : } : } : else if(GetMsg(SerRead)){ <<<<<<<<<<<<<--- remove else : data_in = SerGetChar(); : PutChar(data_in); : } : else if(GetMsg(ConRead)){ <<<<<<<<<<<<<<-- remove else : data_out = GetChar(); : SerPutChar(data_out); : } : }