]> git.pond.sub.org Git - empserver/commitdiff
Remove blocking struct iop operation
authorMarkus Armbruster <armbru@pond.sub.org>
Wed, 22 Apr 2009 18:16:13 +0000 (20:16 +0200)
committerMarkus Armbruster <armbru@pond.sub.org>
Sun, 19 Jul 2009 18:11:52 +0000 (14:11 -0400)
The blocking I/O option makes no sense in the server, because it
blocks the server process instead of the thread.  In fact, it's been
unused since Empire 2, except for one place, where it was used
incorrectly, and got removed in the previous commit.

Make I/O non-blocking in io_open() unconditionally.  Remove IO_NBLOCK
and io_noblocking().

include/empio.h
src/lib/empthread/io.c
src/lib/player/accept.c

index 36050477916d9a1cc1d98c7e559b7ef379856395..70237ebc66a5912db301553f18cea03601f2074b 100644 (file)
@@ -37,7 +37,6 @@
 
 #define        IO_READ         0x1
 #define IO_WRITE       0x2
-#define IO_NBLOCK      0x8
 #define        IO_EOF          0x10
 #define IO_ERROR       0x40
 
@@ -48,7 +47,6 @@
 
 extern struct iop *io_open(int, int, int, struct timeval);
 extern void io_init(void);
-extern int io_noblocking(struct iop *, int);
 extern void io_close(struct iop *);
 extern int io_input(struct iop *, int);
 extern int io_inputwaiting(struct iop *);
index 13d75ad710f501510b174490a1161ac4722ae402..5a50043bd2b412fdea15f89cb44812a22c6a9c6d 100644 (file)
@@ -73,27 +73,33 @@ io_init(void)
 struct iop *
 io_open(int fd, int flags, int bufsize, struct timeval timeout)
 {
+    int fdfl;
     struct iop *iop;
 
-    flags = flags & (IO_READ | IO_WRITE | IO_NBLOCK);
+    flags = flags & (IO_READ | IO_WRITE);
     if ((flags & (IO_READ | IO_WRITE)) == 0)
        return NULL;
+
+    fdfl = fcntl(fd, F_GETFL, 0);
+    if (fdfl < 0)
+       return NULL;
+    fdfl |= O_NONBLOCK;
+    if (fcntl(fd, F_SETFL, fdfl) < 0)
+       return NULL;
+
     iop = malloc(sizeof(struct iop));
     if (!iop)
        return NULL;
     iop->fd = fd;
     iop->input = NULL;
     iop->output = NULL;
-    iop->flags = 0;
-    iop->input_timeout = timeout;
+    iop->flags = flags;
     iop->bufsize = bufsize;
+    iop->input_timeout = timeout;
     if (flags & IO_READ)
        iop->input = ioq_create(bufsize);
     if (flags & IO_WRITE)
        iop->output = ioq_create(bufsize);
-    if (flags & IO_NBLOCK)
-       io_noblocking(iop, 1);  /* FIXME check success */
-    iop->flags = flags;
     return iop;
 }
 
@@ -328,27 +334,6 @@ io_shutdown(struct iop *iop, int flags)
     return 0;
 }
 
-int
-io_noblocking(struct iop *iop, int value)
-{
-    int flags;
-
-    flags = fcntl(iop->fd, F_GETFL, 0);
-    if (flags < 0)
-       return -1;
-    if (value == 0)
-       flags &= ~O_NONBLOCK;
-    else
-       flags |= O_NONBLOCK;
-    if (fcntl(iop->fd, F_SETFL, flags) < 0)
-       return -1;
-    if (value == 0)
-       iop->flags &= ~IO_NBLOCK;
-    else
-       iop->flags |= IO_NBLOCK;
-    return 0;
-}
-
 int
 io_error(struct iop *iop)
 {
index 321e21bbe4c6cacc01a1d98f8176f89b34ea526c..638914875ef7b359b4217e17d7e964a9fb5a3d43 100644 (file)
@@ -82,8 +82,7 @@ player_new(int s)
     idle_timeout.tv_usec = 0 ;
     if (s >= 0) {
        /* real player, not dummy created by update and market update */
-       lp->iop = io_open(s, IO_READ | IO_WRITE | IO_NBLOCK, IO_BUFSIZE,
-                         idle_timeout);
+       lp->iop = io_open(s, IO_READ | IO_WRITE, IO_BUFSIZE, idle_timeout);
        if (!lp->iop) {
            free(lp);
            return NULL;