]> git.pond.sub.org Git - empserver/blobdiff - src/lib/gen/io.c
Update copyright notice.
[empserver] / src / lib / gen / io.c
index bf77d0f27698abf6299fd43721e848b6d5ae33e7..fa57735e9a3b7d0652fb2549b1274d7c853b71ba 100644 (file)
@@ -1,6 +1,6 @@
 /*
  *  Empire - A multi-player, client/server Internet based war game.
- *  Copyright (C) 1986-2005, Dave Pare, Jeff Bailey, Thomas Ruschak,
+ *  Copyright (C) 1986-2007, Dave Pare, Jeff Bailey, Thomas Ruschak,
  *                           Ken Stevens, Steve McClure
  *
  *  This program is free software; you can redistribute it and/or modify
@@ -19,9 +19,9 @@
  *
  *  ---
  *
- *  See the "LEGAL", "LICENSE", "CREDITS" and "README" files for all the
- *  related information and legal notices. It is expected that any future
- *  projects/authors will amend these files as needed.
+ *  See files README, COPYING and CREDITS in the root of the source
+ *  tree for related information and legal notices.  It is expected
+ *  that future projects/authors will amend these files as needed.
  *
  *  ---
  *
  * reading or writing when appropriate.
  */
 
+#include <config.h>
+
 #include <errno.h>
+#include <fcntl.h>
+#include <stdlib.h>
 #include <sys/types.h>
-#if !defined(_WIN32)
+#ifdef _WIN32
+#define WIN32
+#include <winsock2.h>
+#undef NS_ALL
+#else
 #include <sys/uio.h>
 #include <sys/file.h>
-#include <unistd.h>            /* close read shutdown select */
 #include <sys/socket.h>
+#include <unistd.h>
 #endif
 #include <time.h>
-#include <fcntl.h>
-#include <stdlib.h>            /* malloc calloc free */
-
-#if defined(_WIN32)
-#define WIN32
-#include <winsock2.h>
-#undef NS_ALL
-#endif
 
+#include "empio.h"
+#include "ioqueue.h"
 #include "misc.h"
 #include "queue.h"
-#include "ioqueue.h"
-#include "empio.h"
-#include "gen.h"               /* getfdtablesize */
 #include "server.h"
 
 #include "empthread.h"
@@ -71,9 +70,7 @@ struct iop {
     struct ioqueue *input;
     struct ioqueue *output;
     int flags;
-    s_char *assoc;
     int bufsize;
-    int (*notify)(void);
 };
 
 void
@@ -82,8 +79,7 @@ io_init(void)
 }
 
 struct iop *
-io_open(int fd, int flags, int bufsize, int (*notify)(void),
-       s_char *assoc)
+io_open(int fd, int flags, int bufsize)
 {
     struct iop *iop;
 
@@ -103,10 +99,8 @@ io_open(int fd, int flags, int bufsize, int (*notify)(void),
     if ((flags & IO_WRITE) && (flags & IO_NEWSOCK) == 0)
        iop->output = ioq_create(bufsize);
     if (flags & IO_NBLOCK)
-       io_noblocking(iop, 1);
+       io_noblocking(iop, 1);  /* FIXME check success */
     iop->flags = flags;
-    iop->assoc = assoc;
-    iop->notify = notify;
     return iop;
 }
 
@@ -129,7 +123,7 @@ io_close(struct iop *iop)
 int
 io_input(struct iop *iop, int waitforinput)
 {
-    s_char buf[IO_BUFSIZE];
+    char buf[IO_BUFSIZE];
     int cc;
 
     /* Not a read IOP */
@@ -147,7 +141,7 @@ io_input(struct iop *iop, int waitforinput)
     cc = read(iop->fd, buf, sizeof(buf));
     if (cc < 0) {
        /* would block, so nothing to read. */
-       if (errno == EWOULDBLOCK)
+       if (errno == EAGAIN || errno == EWOULDBLOCK)
            return 0;
 
        /* Some form of file error occurred... */
@@ -197,7 +191,7 @@ io_output(struct iop *iop, int waitforoutput)
 #if !defined(_WIN32)
     struct iovec iov[16];
 #else
-    s_char buf[IO_BUFSIZE];
+    char buf[IO_BUFSIZE];
 #endif
     int cc;
     int n;
@@ -215,10 +209,6 @@ io_output(struct iop *iop, int waitforoutput)
     if (iop->flags & IO_ERROR)
        return -1;
 
-    /* This is the same test as io_outputwaiting.... */
-    if (ioq_qsize(iop->output) == 0)
-       return 0;
-
 #if !defined(_WIN32)
     /* make the iov point to the data in the queue. */
     /* I.E., each of the elements in the queue. */
@@ -247,7 +237,7 @@ io_output(struct iop *iop, int waitforoutput)
     /* if it failed.... */
     if (cc < 0) {
        /* Hmm, it would block.  file is opened noblock, soooooo.. */
-       if (errno == EWOULDBLOCK) {
+       if (errno == EAGAIN || errno == EWOULDBLOCK) {
            /* If there are remaining bytes, set the IO as remaining.. */
            remain = ioq_qsize(iop->output);
            return remain;
@@ -273,17 +263,10 @@ io_output(struct iop *iop, int waitforoutput)
 #endif
 
     /* If no bytes were written, something happened..  Like an EOF. */
-#ifndef        hpux
     if (cc == 0) {
        iop->flags |= IO_EOF;
        return 0;
     }
-#else
-    if (cc == 0) {
-       remain = ioq_qsize(iop->output);
-       return remain;
-    }
-#endif /* hpux */
 
     /* Remove the number of written bytes from the queue. */
     ioq_dequeue(iop->output, cc);
@@ -292,7 +275,7 @@ io_output(struct iop *iop, int waitforoutput)
 }
 
 int
-io_peek(struct iop *iop, s_char *buf, int nbytes)
+io_peek(struct iop *iop, char *buf, int nbytes)
 {
     if ((iop->flags & IO_READ) == 0)
        return -1;
@@ -300,7 +283,7 @@ io_peek(struct iop *iop, s_char *buf, int nbytes)
 }
 
 int
-io_read(struct iop *iop, s_char *buf, int nbytes)
+io_read(struct iop *iop, char *buf, int nbytes)
 {
     int cc;
 
@@ -313,7 +296,7 @@ io_read(struct iop *iop, s_char *buf, int nbytes)
 }
 
 int
-io_write(struct iop *iop, s_char *buf, int nbytes, int doWait)
+io_write(struct iop *iop, char *buf, int nbytes, int doWait)
 {
     int len;
 
@@ -349,7 +332,7 @@ io_output_all(struct iop *iop)
 }
 
 int
-io_gets(struct iop *iop, s_char *buf, int nbytes)
+io_gets(struct iop *iop, char *buf, int nbytes)
 {
     if ((iop->flags & IO_READ) == 0)
        return -1;
@@ -357,7 +340,7 @@ io_gets(struct iop *iop, s_char *buf, int nbytes)
 }
 
 int
-io_puts(struct iop *iop, s_char *buf)
+io_puts(struct iop *iop, char *buf)
 {
     if ((iop->flags & IO_WRITE) == 0)
        return -1;
@@ -391,9 +374,9 @@ io_noblocking(struct iop *iop, int value)
     if (flags < 0)
        return -1;
     if (value == 0)
-       flags &= ~FNDELAY;
+       flags &= ~O_NONBLOCK;
     else
-       flags |= FNDELAY;
+       flags |= O_NONBLOCK;
     if (fcntl(iop->fd, F_SETFL, flags) < 0)
        return -1;
 #else
@@ -407,12 +390,6 @@ io_noblocking(struct iop *iop, int value)
     return 0;
 }
 
-int
-io_conn(struct iop *iop)
-{
-    return iop->flags & IO_CONN;
-}
-
 int
 io_error(struct iop *iop)
 {