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 / dclose.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-06-29  |  1.3 KB  |  50 lines

  1.  
  2. /*
  3.  *  DClose.C
  4.  */
  5.  
  6. #include "lib.h"
  7.  
  8. void
  9. DClose(_chan)
  10. void *_chan;
  11. {
  12.     CHANN *chan = (CHANN *)_chan;
  13.     IOSTD ior;
  14.     IOSTD *io;
  15.     IFDEBUG(int bogositylimit = 100;)
  16.  
  17.     IFDEBUG(printf("starting DClose(%lx)\n", _chan); sleep(1);)
  18.     if(chan == NULL) {
  19.         return;
  20.     }
  21.  
  22.     ior.io_Command = DNCMD_CLOSE;
  23.     ior.io_Unit =  (struct Unit *)((ulong) chan->chan);
  24.     ior.io_Offset = (ulong) chan;
  25.     ior.io_Message.mn_ReplyPort = (PORT *)chan;
  26.     PutMsg(chan->dnetport, (MSG *)&ior);
  27.     IFDEBUG(printf("DCLose message put...\n");sleep(1);)
  28.     ++chan->queued;
  29.     chan->qlen = 0;   /* we want to flush the dnet queue */
  30.     WaitQueue(chan, &ior);     /* wait until the queue is flushed */
  31.     IFDEBUG(printf("WaitQueue() done...\n");sleep(1);)
  32.     if(&(chan->rdylist) != NULL && !(IsListEmpty(&(chan->rdylist) )))
  33.     while ((io = (IOSTD *)RemHead(&chan->rdylist)) != NULL ) {
  34.         io->io_Error = 1;
  35.         ReplyMsg((MSG *)io);
  36.     }
  37.     IFDEBUG(printf("chan->rdylist cleared...\n");sleep(1);)
  38.     if(&chan->port != NULL)
  39.     while ( ((io = (IOSTD *)GetMsg(&chan->port)) != NULL)
  40.         IFDEBUG(&& (bogositylimit-- > 0))
  41.     ) {
  42.         io->io_Error = 1;
  43.         ReplyMsg((MSG *)io);
  44.     }
  45.     IFDEBUG( if(bogositylimit <=0) printf("My BogoMeter broke!\n");)
  46.     IFDEBUG(printf("chan->port cleared\n");sleep(1);)
  47.     DeleteChannel(chan);
  48.     IFDEBUG(printf("Channel deleted...\n");)
  49. }
  50.