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

  1.  
  2. /*
  3.  *  DWrite.c
  4.  */
  5.  
  6. #include "lib.h"
  7.  
  8. /* is the queue for a channel full? if so, return 1
  9. ** else return 0 
  10. */
  11. long
  12. DQueueFull(_chan)
  13. void *_chan;
  14. {
  15.     CHANN *chan = (CHANN *)_chan;
  16.  
  17.     return (chan->qlen && (chan->queued > chan->qlen));
  18. }
  19.  
  20. long
  21. DWrite(_chan, _buf, bytes)
  22. void *_chan;
  23. void *_buf;
  24. long bytes;
  25. {
  26.     int error = bytes;
  27.     CHANN *chan = (CHANN *)_chan;
  28.     APTR  buf = (char *)_buf;
  29.  
  30.     IFDEBUG(printf("DWrite %d bytes at %lx\n", bytes, buf);)
  31.  
  32.     IFDEBUG(printf("DWrite qlen %d \n", chan->qlen);)
  33.     if (chan->qlen >0 ) {
  34.     /* wait until all pending IORequests on the channel have been 
  35.     ** processed */
  36.     if (WaitQueue(chan, NULL) >= 0) {
  37.         IOSTD *ior = AllocMem(sizeof(IOSTD), MEMF_CLEAR|MEMF_PUBLIC);
  38.         ior->io_Command = DNCMD_WRITE;
  39.         ior->io_Unit = (struct Unit *)((ulong)chan->chan);
  40.         ior->io_Offset = (ulong)chan;
  41.         ior->io_Message.mn_ReplyPort = (PORT *)chan;
  42.         ior->io_Data = AllocMem(bytes, MEMF_PUBLIC);
  43.         ior->io_Length = bytes;
  44.         BMov(buf, ior->io_Data, bytes);
  45.         PutMsg(chan->dnetport, (MSG *)ior);
  46.         ++chan->queued;
  47.     } else {
  48.         error = -1;
  49.     }
  50.     } else {
  51.     IOSTD ior;
  52.     ior.io_Command = DNCMD_WRITE;
  53.     ior.io_Unit = (struct Unit *)((ulong)chan->chan);
  54.     ior.io_Offset = (ulong)chan;
  55.     ior.io_Message.mn_ReplyPort = (PORT *)chan;
  56.     ior.io_Data = (APTR)buf;
  57.     ior.io_Length = bytes;
  58.     PutMsg(chan->dnetport, (MSG *)&ior);
  59.     WaitMsg(&ior);
  60.     if (ior.io_Error){
  61.         error = -2;
  62.         IFDEBUG(printf("DWrite IOError %d\n", ior.io_Error);)
  63.     }
  64.     }
  65.     FixSignal(chan);
  66.     return(error);
  67. }
  68.