home *** CD-ROM | disk | FTP | other *** search
-
- /*
- * DWrite.c
- */
-
- #include "lib.h"
-
- /* is the queue for a channel full? if so, return 1
- ** else return 0
- */
- long
- DQueueFull(_chan)
- void *_chan;
- {
- CHANN *chan = (CHANN *)_chan;
-
- return (chan->qlen && (chan->queued > chan->qlen));
- }
-
- long
- DWrite(_chan, _buf, bytes)
- void *_chan;
- void *_buf;
- long bytes;
- {
- int error = bytes;
- CHANN *chan = (CHANN *)_chan;
- APTR buf = (char *)_buf;
-
- IFDEBUG(printf("DWrite %d bytes at %lx\n", bytes, buf);)
-
- IFDEBUG(printf("DWrite qlen %d \n", chan->qlen);)
- if (chan->qlen >0 ) {
- /* wait until all pending IORequests on the channel have been
- ** processed */
- if (WaitQueue(chan, NULL) >= 0) {
- IOSTD *ior = AllocMem(sizeof(IOSTD), MEMF_CLEAR|MEMF_PUBLIC);
- ior->io_Command = DNCMD_WRITE;
- ior->io_Unit = (struct Unit *)((ulong)chan->chan);
- ior->io_Offset = (ulong)chan;
- ior->io_Message.mn_ReplyPort = (PORT *)chan;
- ior->io_Data = AllocMem(bytes, MEMF_PUBLIC);
- ior->io_Length = bytes;
- BMov(buf, ior->io_Data, bytes);
- PutMsg(chan->dnetport, (MSG *)ior);
- ++chan->queued;
- } else {
- error = -1;
- }
- } else {
- IOSTD ior;
- ior.io_Command = DNCMD_WRITE;
- ior.io_Unit = (struct Unit *)((ulong)chan->chan);
- ior.io_Offset = (ulong)chan;
- ior.io_Message.mn_ReplyPort = (PORT *)chan;
- ior.io_Data = (APTR)buf;
- ior.io_Length = bytes;
- PutMsg(chan->dnetport, (MSG *)&ior);
- WaitMsg(&ior);
- if (ior.io_Error){
- error = -2;
- IFDEBUG(printf("DWrite IOError %d\n", ior.io_Error);)
- }
- }
- FixSignal(chan);
- return(error);
- }
-