/* WaitMsg.c
** 
** an attempt to recreate the WaitMsg function
** which might have been a normal system call back in the original 
** days of DNet, but which is not now...
*/

#include <exec/nodes.h>
#include <exec/io.h>

typedef struct IORequest IOR;
typedef struct IOStdReq IOSTD;

#ifdef  DEBUG
#include <stdio.h>
#define IFDEBUG(foo) foo
#else
#define IFDEBUG(foo) 
#endif

#define FOO


WaitMsg( IOSTD * ior){
#ifdef FOO
   unsigned long waitmask;
#endif FOO

   IFDEBUG(printf("WaitMsg enter\n");)

#ifdef FOO

   if(ior == NULL) return;

   waitmask = 1L << (ior -> io_Message . mn_ReplyPort -> mp_SigBit);

waitsomemore:
   Wait(waitmask);

   if(!CheckIO((IOR *)ior)){
	IFDEBUG(printf("Wait returned, but we should wait some more\n");)
   	goto waitsomemore;
   }
#endif /* FOO */

   WaitIO((IOR *) ior); /* deal with all the annoying reply crap */
   IFDEBUG(printf("WaitMsg exit\n");)
}
