home *** CD-ROM | disk | FTP | other *** search
/ The CDPD Public Domain Collection for CDTV 4 / CDPD_IV.bin / networking / dnet / dnet2.3.2 / amiga / lib / waitqueue.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-06-29  |  1.1 KB  |  51 lines

  1. /*
  2.  *  WaitQueue.C
  3.  */
  4.  
  5. #include "lib.h"
  6.  
  7. /* wait until all IORequests on a channel's port are cleared, except
  8. ** for the one called as skipior
  9. */
  10.  
  11. short
  12. WaitQueue(_chan, skipior)
  13. void *_chan;
  14. IOSTD *skipior;
  15. {
  16.     CHANN *chan = (CHANN *)_chan;
  17.     IOSTD *io;
  18.     ulong waitmask;
  19.  
  20.     short error = 0;
  21.     while (chan->queued > chan->qlen) {  /*  while queue size > maxqueuesize */
  22.     IFDEBUG(printf("Waiting for something on port %lx\n", &(chan->port));)
  23.     waitmask = SIGBREAKF_CTRL_C ;
  24.     waitmask |= (1 << chan->port.mp_SigBit);
  25.     Wait( waitmask );        
  26.     io = (IOSTD *)GetMsg( & (chan->port) );
  27.     if(io == NULL){
  28.         IFDEBUG(fprintf(stderr, "NULL from GetMsg(chan->Port)!\n");)
  29.         error = -6;
  30.         break;
  31.     }
  32.  
  33.     /* message has been processed and replyd, remove it */
  34.     if ( io->io_Message.mn_Node.ln_Type == NT_REPLYMSG) {
  35.         if (error == 0)
  36.         error = io->io_Error;
  37.         if (io != skipior) {
  38.         if (io->io_Length)
  39.             FreeMem(io->io_Data, io->io_Length);
  40.         FreeMem(io, sizeof(IOSTD));
  41.         }
  42.         --chan->queued;
  43.     } else {
  44.         /* put message back onto the end of the channel's 
  45.         ** rdylist */
  46.         AddTail( &(chan->rdylist), (NODE *)io);
  47.     }
  48.     }
  49.     return(error);
  50. }
  51.