]> git.pond.sub.org Git - empserver/blobdiff - src/client/ioqueue.c
Update copyright notice.
[empserver] / src / client / ioqueue.c
index ec04c41cb42c18f0911b174c48a335e7e2a6031b..cfff85d328f61a1a3c22fd12f08696a1ddd36f58 100644 (file)
@@ -1,6 +1,6 @@
 /*
  *  Empire - A multi-player, client/server Internet based war game.
- *  Copyright (C) 1986-2000, Dave Pare, Jeff Bailey, Thomas Ruschak,
+ *  Copyright (C) 1986-2004, Dave Pare, Jeff Bailey, Thomas Ruschak,
  *                           Ken Stevens, Steve McClure
  *
  *  This program is free software; you can redistribute it and/or modify
 
 #include <stdio.h>
 #include <stdlib.h>
+#include <string.h>
 #include <sys/types.h>
-#ifndef _WIN32
-#include <sys/uio.h>
-#include <unistd.h>
-#endif
 #include "misc.h"
 #include "queue.h"
 #include "ioqueue.h"
 
-#ifdef _WIN32
-typedef struct iovec {
-    char *iov_base;
-    int iov_len;
-} iovec_t;
-#endif
+static int ioqtobuf(register struct ioqueue *ioq, s_char *buf, int cc);
+static void enqueuecc(struct ioqueue *ioq, s_char *buf, int cc);
+static int dequeuecc(register struct ioqueue *ioq, register int cc);
 
 
-static int ioqtobuf();
-static int ioqtoiov();
-static void enqueuecc();
-static int dequeuecc();
-
-void insque();
-void remque();
-void initque();
-struct qelem *makeqt();
-
 void
-ioq_init(ioq, bsize)
-struct ioqueue *ioq;
-int bsize;
+ioq_init(struct ioqueue *ioq, int bsize)
 {
-    extern s_char num_teles[];
-
     initque(&ioq->queue);
     ioq->cc = 0;
     ioq->bsize = bsize;
     *num_teles = '\0';
 }
 
-/*
- * copy batch of pointers into the passed
- * iovec, but don't actually dequeue the data.
- * return # of iovec initialized.
- */
-int
-ioq_peekiov(ioq, iov, max)
-struct ioqueue *ioq;
-struct iovec *iov;
-int max;
-{
-    if (ioq->cc <= 0)
-       return 0;
-    return ioqtoiov(ioq, iov, max);
-}
-
 /*
  * Copy the specified number of characters into the buffer
  * provided, without actually dequeueing the data.  Return
  * number of bytes actually found.
  */
 int
-ioq_peek(ioq, buf, cc)
-struct ioqueue *ioq;
-s_char *buf;
-int cc;
+ioq_peek(struct ioqueue *ioq, s_char *buf, int cc)
 {
     return ioqtobuf(ioq, buf, cc);
 }
 
 int
-ioq_dequeue(ioq, cc)
-struct ioqueue *ioq;
-int cc;
+ioq_dequeue(struct ioqueue *ioq, int cc)
 {
     if (dequeuecc(ioq, cc) != cc)
        return 0;
@@ -114,10 +73,7 @@ int cc;
 }
 
 int
-ioq_read(ioq, buf, cc)
-struct ioqueue *ioq;
-s_char *buf;
-int cc;
+ioq_read(struct ioqueue *ioq, s_char *buf, int cc)
 {
     int n;
 
@@ -128,24 +84,19 @@ int cc;
 }
 
 void
-ioq_write(ioq, buf, cc)
-struct ioqueue *ioq;
-s_char *buf;
-int cc;
+ioq_write(struct ioqueue *ioq, s_char *buf, int cc)
 {
     enqueuecc(ioq, buf, cc);
 }
 
 int
-ioq_qsize(ioq)
-struct ioqueue *ioq;
+ioq_qsize(struct ioqueue *ioq)
 {
     return ioq->cc;
 }
 
 void
-ioq_drain(ioq)
-struct ioqueue *ioq;
+ioq_drain(struct ioqueue *ioq)
 {
     struct io *io;
     struct qelem *qp;
@@ -160,10 +111,7 @@ struct ioqueue *ioq;
 }
 
 s_char *
-ioq_gets(ioq, buf, cc)
-struct ioqueue *ioq;
-s_char *buf;
-int cc;
+ioq_gets(struct ioqueue *ioq, s_char *buf, int cc)
 {
     register s_char *p;
     register s_char *end;
@@ -194,10 +142,7 @@ int cc;
  * left for a higher level.
  */
 static int
-ioqtobuf(ioq, buf, cc)
-register struct ioqueue *ioq;
-s_char *buf;
-int cc;
+ioqtobuf(register struct ioqueue *ioq, s_char *buf, int cc)
 {
     register struct io *io;
     struct qelem *qp;
@@ -225,49 +170,11 @@ int cc;
     return offset - buf;
 }
 
-/*
- * translate "around" max bytes to an iovec
- * array.  The limit max is only advisory,
- * and more may get buffered.  It is an attempt to limit
- * really silly sends -- like sending 40k on a socket
- * with one writev for example.  This makes the processing
- * of a full ioqueue still be quick.
- */
-static int
-ioqtoiov(ioq, iov, max)
-register struct ioqueue *ioq;
-register struct iovec *iov;
-register int max;
-{
-    register struct io *io;
-    register int cc;
-    register int niov;
-    struct qelem *qp;
-
-    cc = 0;
-    niov = 0;
-    qp = ioq->queue.q_forw;
-    for (qp = ioq->queue.q_forw; qp != &ioq->queue; qp = qp->q_forw) {
-       io = (struct io *)qp;
-       if (niov >= MAXIOV || cc >= max)
-           break;
-       iov->iov_base = io->data + io->offset;
-       iov->iov_len = io->nbytes - io->offset;
-       cc += io->nbytes - io->offset;
-       niov++;
-       iov++;
-    }
-    return niov;
-}
-
 /*
  * append a buffer to the end of the ioq.
  */
 static void
-enqueuecc(ioq, buf, cc)
-struct ioqueue *ioq;
-s_char *buf;
-int cc;
+enqueuecc(struct ioqueue *ioq, s_char *buf, int cc)
 {
     struct io *io;
 
@@ -285,9 +192,7 @@ int cc;
  * which are no longer used.
  */
 static int
-dequeuecc(ioq, cc)
-register struct ioqueue *ioq;
-register int cc;
+dequeuecc(register struct ioqueue *ioq, register int cc)
 {
     register struct io *io;
     register struct qelem *qp;