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

  1.  
  2. /*
  3.  *  DNRead.C
  4.  */
  5.  
  6. #include "lib.h"
  7.  
  8. long
  9. DNRead(_chan, _buf, bytes)
  10. void *_chan;
  11. void *_buf;
  12. long bytes;
  13. {
  14.     CHANN *chan = (CHANN *)_chan;
  15.     char *buf = (char *)_buf;
  16.     IOSTD *ior;
  17.     int len = 0;
  18.     long n;
  19.  
  20.     if (chan->eof)
  21.     return(-1);
  22.     while (bytes > 0 ){
  23.         if((ior = (IOSTD *)RemHead(&chan->rdylist)) != NULL) {
  24.         IFDEBUG(printf("ior from chan->rdylist\n");)
  25.     } else if ((ior = (IOSTD *)GetMsg(&chan->port)) != NULL) {
  26.         IFDEBUG(printf("ior from chan->port\n");)
  27.     } else {
  28.         break;
  29.     }
  30.     IFDEBUG(printf("IOR %08lx cmd %d len %d act %d\n", ior, ior->io_Command, ior->io_Length, ior->io_Actual);)
  31.     if (ior->io_Message.mn_Node.ln_Type == NT_REPLYMSG) {
  32.         if (chan->queued <=0)
  33.         IFDEBUG(puts("DNRead: Software Error"));
  34.         else
  35.         --chan->queued;
  36.         IFDEBUG(printf("Freeing reply message");)
  37.         if (ior->io_Length)
  38.         FreeMem(ior->io_Data, ior->io_Length);
  39.         FreeMem(ior, sizeof(IOSTD));
  40.         continue;
  41.     }
  42.     switch(ior->io_Command) {
  43.     case DNCMD_CLOSE:
  44.     case DNCMD_EOF:
  45.         chan->eof = 1;
  46.         ReplyMsg((MSG *)ior);
  47.         break;
  48.     case DNCMD_IOCTL:
  49.         if (ior->io_Message.mn_Node.ln_Type == NT_REQUEUE)
  50.         AddHead(&chan->rdylist, (NODE *)ior);
  51.         else
  52.         AddTail(&chan->rdylist, (NODE *)ior);
  53.         ior->io_Message.mn_Node.ln_Type = NT_REQUEUE;
  54.         if (len == 0)
  55.         len = -2;
  56.         goto done;
  57.     case DNCMD_WRITE:
  58.         IFDEBUG(printf("WRITE LEN/ACT %ld/%ld\n", ior->io_Length, ior->io_Actual);)
  59.         n = ior->io_Length - ior->io_Actual;
  60.         IFDEBUG(if (n < 0) puts("len error, act > len");)
  61.         if (n <= bytes) {
  62.         /* the ior is being written to this channel
  63.         ** it is long enough to be completed by this request */
  64.         BMov((char *)ior->io_Data + ior->io_Actual, buf, n);
  65.         bytes -= n;
  66.         len += n;
  67.         buf += n;
  68.         ReplyMsg((MSG *)ior);
  69.         } else {
  70.         /* the ior is being written to this channel
  71.         ** it is NOT long enough to be completed by this request 
  72.         **  Thus, it needs to be  requeued */
  73.         BMov((char *)ior->io_Data + ior->io_Actual, buf, bytes);
  74.         len += bytes;
  75.         ior->io_Actual += bytes;
  76.         bytes = 0;
  77.         if (ior->io_Message.mn_Node.ln_Type == NT_REQUEUE)
  78.             AddHead(&chan->rdylist, (NODE *)ior);
  79.         else
  80.             AddTail(&chan->rdylist, (NODE *)ior);
  81.         ior->io_Message.mn_Node.ln_Type = NT_REQUEUE;
  82.         }
  83.         break;
  84.     default:
  85.         ior->io_Error = 1;
  86.         IFDEBUG(puts("DNRead():default erroneous ior");)
  87.         ReplyMsg((MSG *)ior);
  88.     }
  89.     }
  90.     IFDEBUG(puts("DONE1");)
  91. done:
  92.     FixSignal(chan);
  93.     if (chan->eof)
  94.     SetSignal(1 << chan->port.mp_SigBit, 1 << chan->port.mp_SigBit);
  95.     IFDEBUG(printf("RETURN %ld\n", len);)
  96.     return(len);
  97. }
  98.