home *** CD-ROM | disk | FTP | other *** search
/ The Fred Fish Collection 1.5 / ffcollection-1-5-1992-11.iso / ff_disks / 200-299 / ff294.lzh / DNet / amiga / lib / dwrite.c < prev    next >
C/C++ Source or Header  |  1989-12-11  |  1KB  |  59 lines

  1.  
  2. /*
  3.  *  DWrite.c
  4.  */
  5.  
  6. #include "lib.h"
  7.  
  8. long
  9. DQueueFull(_chan)
  10. void *_chan;
  11. {
  12.     CHANN *chan = (CHANN *)_chan;
  13.  
  14.     return (chan->qlen && (chan->queued > chan->qlen));
  15. }
  16.  
  17. long
  18. DWrite(_chan, _buf, bytes)
  19. void *_chan;
  20. void *_buf;
  21. long bytes;
  22. {
  23.     int error = bytes;
  24.     CHANN *chan = (CHANN *)_chan;
  25.     char *buf = (char *)_buf;
  26.  
  27.     if (chan->qlen) {
  28.     if (WaitQueue(chan, NULL) >= 0) {
  29.         IOSTD *ior = AllocMem(sizeof(IOSTD), MEMF_CLEAR|MEMF_PUBLIC);
  30.         ior->io_Command = DNCMD_WRITE;
  31.         ior->io_Unit = (void *)chan->chan;
  32.         ior->io_Offset = (long)chan;
  33.         ior->io_Message.mn_ReplyPort = (PORT *)chan;
  34.         ior->io_Data = AllocMem(bytes, MEMF_PUBLIC);
  35.         ior->io_Length = bytes;
  36.         BMov(buf, ior->io_Data, bytes);
  37.         PutMsg(chan->dnetport, (MSG *)ior);
  38.         ++chan->queued;
  39.     } else {
  40.         error = -1;
  41.     }
  42.     } else {
  43.     IOSTD ior;
  44.     ior.io_Command = DNCMD_WRITE;
  45.     ior.io_Unit = (void *)chan->chan;
  46.     ior.io_Offset = (long)chan;
  47.     ior.io_Message.mn_ReplyPort = (PORT *)chan;
  48.     ior.io_Data = (APTR)buf;
  49.     ior.io_Length = bytes;
  50.     PutMsg(chan->dnetport, (MSG *)&ior);
  51.     WaitMsg(&ior);
  52.     if (ior.io_Error)
  53.         error = -1;
  54.     }
  55.     FixSignal(chan);
  56.     return(error);
  57. }
  58.  
  59.