]> git.pond.sub.org Git - empserver/blobdiff - src/lib/gen/ioqueue.c
Update copyright notice
[empserver] / src / lib / gen / ioqueue.c
index 5408d68e174ee7fdce18903ce9b4e5b3b86e7401..ce2490c7542cae3d2004ee6c185ab9039a392375 100644 (file)
@@ -1,6 +1,6 @@
 /*
  *  Empire - A multi-player, client/server Internet based war game.
- *  Copyright (C) 1986-2006, Dave Pare, Jeff Bailey, Thomas Ruschak,
+ *  Copyright (C) 1986-2010, Dave Pare, Jeff Bailey, Thomas Ruschak,
  *                           Ken Stevens, Steve McClure
  *
  *  This program is free software; you can redistribute it and/or modify
@@ -26,9 +26,9 @@
  *  ---
  *
  *  ioqueue.c: Read and write i/o queues
- * 
+ *
  *  Known contributors to this file:
- *     
+ *
  */
 
 /*
 
 #include <config.h>
 
-#include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
-#if !defined(_WIN32)
 #include <sys/uio.h>
-#endif
 #include "ioqueue.h"
 #include "misc.h"
 #include "queue.h"
 
+struct io {
+    struct emp_qelem queue;
+    int size;
+    int nbytes;
+    int offset;
+    char *data;
+};
+
+struct ioqueue {
+    struct io list;
+    int bufsize;
+    int cc;
+};
+
 static int ioqtocbuf(struct ioqueue *ioq, char *buf, int cc, int stopc);
-#if !defined(_WIN32)
 static int ioqtoiov(struct ioqueue *ioq, struct iovec *iov, int max);
-#endif
 static int ioqtobuf(struct ioqueue *ioq, char *buf, int cc);
 static int appendcc(struct ioqueue *ioq, char *buf, int cc);
 static int removecc(struct ioqueue *ioq, int cc);
@@ -67,7 +76,7 @@ ioq_create(int size)
     ioq->list.nbytes = 0;
     ioq->list.offset = 0;
     ioq->list.size = 0;
-    ioq->list.data = 0;
+    ioq->list.data = NULL;
     ioq->bufsize = size;
     ioq->cc = 0;
     return ioq;
@@ -101,7 +110,6 @@ ioq_drain(struct ioqueue *ioq)
  * iovec, but don't actually dequeue the data.
  * return # of iovec initialized.
  */
-#if !defined(_WIN32)
 int
 ioq_makeiov(struct ioqueue *ioq, struct iovec *iov, int cc)
 {
@@ -109,7 +117,6 @@ ioq_makeiov(struct ioqueue *ioq, struct iovec *iov, int cc)
        return 0;
     return ioqtoiov(ioq, iov, cc);
 }
-#endif
 
 /*
  * Copy the specified number of characters into the buffer
@@ -247,7 +254,6 @@ ioqtocbuf(struct ioqueue *ioq, char *buf, int cc, int stopc)
  * initialize an iovec to point at max bytes worth
  * of data from the ioqueue.
  */
-#if !defined(_WIN32)
 static int
 ioqtoiov(struct ioqueue *ioq, struct iovec *iov, int max)
 {
@@ -274,7 +280,6 @@ ioqtoiov(struct ioqueue *ioq, struct iovec *iov, int max)
     }
     return niov;
 }
-#endif
 
 /*
  * append a buffer to the end of the ioq.
@@ -356,47 +361,3 @@ removecc(struct ioqueue *ioq, int cc)
     ioq->cc -= nbytes;
     return nbytes;
 }
-
-#if defined(_WIN32)
-/*
- * Make an (output) buffer up to the
- * maximum size of the buffer.
- *
- * We don't free the bytes...
- */
-int
-ioq_makebuf(struct ioqueue *ioq, char *pBuf, int nBufLen)
-{
-    struct io *io;
-    struct emp_qelem *qp;
-    struct emp_qelem *head;
-    int nbytes;
-    int nleft;
-    int ncopied;
-    char *offset;
-
-    ncopied = 0;
-    nleft = nBufLen;
-    offset = pBuf;
-    head = &ioq->list.queue;
-
-    for (qp = head->q_forw; (qp != head) && (nleft > 0); qp = qp->q_forw) {
-       io = (struct io *)qp;
-       nbytes = io->nbytes - io->offset;
-       if (nbytes < 0) {
-           /* Paranoid check for bad buffer. */
-           continue;
-       }
-
-       /* too many bytes, wait till next time. */
-       if (nbytes > nleft)
-           break;
-
-       memcpy(offset, io->data + io->offset, nbytes);
-       offset += nbytes;
-       nleft -= nbytes;
-       ncopied += nbytes;
-    }
-    return ncopied;
-}
-#endif /* _WIN32 */