]> git.pond.sub.org Git - empserver/commitdiff
Use src/lib/w32/w32io.c for client
authorMarkus Armbruster <armbru@pond.sub.org>
Sat, 18 Apr 2009 20:16:00 +0000 (22:16 +0200)
committerMarkus Armbruster <armbru@pond.sub.org>
Sat, 5 Dec 2009 14:19:34 +0000 (15:19 +0100)
Replaces w32_writev_socket() and w32_readv_fd().  Split w32types.h off
w32misc.h, to avoid putting irrelevant stuff into client tarball.

12 files changed:
Make.mk
src/client/Makefile.in
src/client/configure.ac
src/client/expect.c
src/client/play.c
src/client/ringbuf.c
src/client/sysdep_w32.c
src/client/sysdep_w32.h
src/lib/w32/sys/uio.h
src/lib/w32/unistd.h
src/lib/w32/w32misc.h
src/lib/w32/w32types.h [new file with mode: 0644]

diff --git a/Make.mk b/Make.mk
index c385a6240483bd17d7c4d9242b9207b720af1dec..afa731c189239236c3a54539cde2c21e6b37c5dc 100644 (file)
--- a/Make.mk
+++ b/Make.mk
@@ -74,6 +74,7 @@ gamedir := $(localstatedir)/empire
 builtindir := $(datadir)/empire/builtin
 einfodir := $(datadir)/empire/info.nr
 ehtmldir := $(datadir)/empire/info.html
+client/w32 := sys/uio.h w32io.c w32types.h
 
 # How to substitute Autoconf output variables
 # Recursively expanded so that $@ and $< work.
@@ -133,6 +134,7 @@ endif
 
 ifeq ($(empthread),Windows)    # really: W32, regardless of thread package
 libs += lib/libw32.a
+$(client): lib/libw32.a
 endif
 
 # Cleanliness
@@ -333,6 +335,7 @@ dist-client: $(cli_distgen)
                $(notdir $(filter src/client/%, $(src)) $(cli_distgen)) \
        -C $(srcdir)/include proto.h version.h                          \
        -C $(srcdir)/src/lib/global version.c                           \
+       -C $(srcdir)/src/lib $(addprefix w32/, $(client/w32))           \
        -C $(srcdir)/man empire.6                                       \
        -C $(srcdir) COPYING INSTALL install-sh
 
index 9b5e5a568d3e77309b70694399c41ba98008db8b..004913511850cc600a1ab9084a05c39a69af6614 100644 (file)
@@ -35,6 +35,7 @@
 CC = @CC@
 CFLAGS = @CFLAGS@ @CPPFLAGS@ @DEFS@ -I.
 LDFLAGS = @LDFLAGS@
+LIBOBJS := @LIBOBJS@
 LIBS = @LIBS@
 E = @EXEEXT@
 O = @OBJEXT@
@@ -54,7 +55,8 @@ VPATH = @srcdir@
 
 prog = empire$E
 obj = expect.$O host.$O ipglob.$O linebuf.$O login.$O main.$O play.$O  \
-ringbuf.$O secure.$O servcmd.$O sysdep_w32.$O termlib.$O version.$O
+ringbuf.$O secure.$O servcmd.$O sysdep_w32.$O termlib.$O version.$O    \
+$(LIBOBJS)
 
 all: $(prog)
 
@@ -85,10 +87,15 @@ linebuf.$O: linebuf.h
 login.$O: misc.h sysdep_w32.h proto.h
 main.$O: misc.h sysdep_w32.h version.h
 play.$O: linebuf.h misc.h sysdep_w32.h proto.h ringbuf.h secure.h
-ringbuf.$O: misc.h sysdep_w32.h ringbuf.h
+ringbuf.$O: ringbuf.h
 secure.$O: ringbuf.h secure.h
 servcmd.$O: misc.h sysdep_w32.h proto.h secure.h
 sysdep_w32.$O: misc.h sysdep_w32.h
 termlib.$O: misc.h
 version.$O: version.h
 $(obj): config.h
+
+expect.$O: w32/w32types.h
+play.$O: w32/w32types.h
+ringbuf.$O: w32/sys/uio.h w32/w32types.h
+w32/w32io.$O: misc.h w32/sys/uio.h w32/w32types.h
index 7a38f4393e413db025a9b1e4343b3c5bb1aaa1f3..9625e435f213792518c77b886e53cfbe3a0a95ff 100644 (file)
@@ -54,6 +54,9 @@ MY_WINDOWS_API
 ### Checks for libraries.
 LIBS="$LIBS_SOCKETS $LIBS"
 LIB_SOCKET_NSL
+if test "$Windows_API" = yes; then
+       AC_LIBOBJ([w32/w32io])
+fi
 
 
 ### Checks for header files.
@@ -62,6 +65,7 @@ LIB_SOCKET_NSL
 ### Checks for typedefs, structures, and compiler characteristics.
 
 if test "$Windows_API" = yes; then
+       CPPFLAGS="$CPPFLAGS -Iw32"
        CFLAGS="$CFLAGS -mthreads"
 fi
 
index 2660b97d9e1bfef6760f9e63de6c7ea9d2bae84a..63735ffa0cc7b130e317f67ea0b184678b942dad 100644 (file)
@@ -39,7 +39,9 @@
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
-#ifndef _WIN32
+#ifdef _WIN32
+#include "w32types.h"
+#else
 #include <sys/types.h>
 #include <sys/socket.h>
 #include <unistd.h>
index 7f5e8f45a1956f14c13dd5922c9ba15263c4325c..313dbeb52ffdeb91a6d945ab27c7f9fb331e69ba 100644 (file)
@@ -45,6 +45,7 @@
 #else
 #include <process.h>
 #include <io.h>
+#include "w32types.h"
 #endif
 #include "linebuf.h"
 #include "misc.h"
index 72ee7ba0b9ce72e89137e49d7951de49f202a8bc..bae84fffc6cb4eac84c5f9601d426d7e147aee02 100644 (file)
 #include <assert.h>
 #include <stdio.h>
 #include <string.h>
-#ifndef _WIN32
 #include <sys/uio.h>
-#include <unistd.h>
-#else
-#define readv(fd, iov, iovcnt) \
-    w32_readv_fd((fd), (iov), (iovcnt))
-#define writev(fd, iov, iovcnt) \
-    w32_writev_socket((fd), (iov), (iovcnt))
-#endif
-#include "misc.h"
 #include "ringbuf.h"
 
 /*
index 61c129ecf71a14f4f3ac4cc341adf62c9386acf2..9fc08f2a6aea08b5cf13d538f0e0f875f8a4ee41 100644 (file)
@@ -185,43 +185,6 @@ w32_recv(int sockfd, void *buffer, size_t buf_size, int flags)
     return result;
 }
 
-/*
- * POSIX compatible writev() replacement specialized to sockets
- * Modelled after the GNU's libc/sysdeps/posix/writev.c
- */
-ssize_t
-w32_writev_socket(int sockfd, const struct iovec *iov, int iovcnt)
-{
-    SOCKET sock = W32_FD_TO_SOCKET(sockfd);
-    int i;
-    char *buffer, *buffer_location;
-    size_t total_bytes = 0;
-    int bytes_written;
-
-    for (i = 0; i < iovcnt; i++)
-       total_bytes += iov[i].iov_len;
-
-    buffer = malloc(total_bytes);
-    if (buffer == NULL && total_bytes != 0) {
-       errno = ENOMEM;
-       return -1;
-    }
-
-    buffer_location = buffer;
-    for (i = 0; i < iovcnt; i++) {
-       memcpy(buffer_location, iov[i].iov_base, iov[i].iov_len);
-       buffer_location += iov[i].iov_len;
-    }
-
-    bytes_written = send(sock, buffer, total_bytes, 0);
-    free(buffer);
-    if (bytes_written == SOCKET_ERROR) {
-       w32_set_winsock_errno();
-       return -1;
-    }
-    return bytes_written;
-}
-
 /*
  * POSIX compatible send() replacement
  */
@@ -260,48 +223,4 @@ w32_close(int fd)
     return _close(fd);
 }
 
-/*
- * POSIX compatible readv() replacement specialized to files.
- * Modelled after the GNU's libc/sysdeps/posix/readv.c
- */
-ssize_t
-w32_readv_fd(int fd, const struct iovec *iov, int iovcnt)
-{
-    int i;
-    char *buffer, *buffer_location;
-    size_t total_bytes = 0;
-    int bytes_read;
-    size_t bytes_left;
-
-    for (i = 0; i < iovcnt; i++) {
-       total_bytes += iov[i].iov_len;
-    }
-
-    buffer = malloc(total_bytes);
-    if (buffer == NULL && total_bytes != 0) {
-       errno = ENOMEM;
-       return -1;
-    }
-
-    bytes_read = read(fd, buffer, total_bytes);
-    if (bytes_read < 0)
-       return -1;
-
-    bytes_left = bytes_read;
-    buffer_location = buffer;
-    for (i = 0; i < iovcnt; i++) {
-       size_t copy = MIN(iov[i].iov_len, bytes_left);
-
-       memcpy(iov[i].iov_base, buffer_location, copy);
-
-       buffer_location += copy;
-       bytes_left -= copy;
-       if (bytes_left == 0)
-           break;
-    }
-
-    free(buffer);
-    return bytes_read;
-}
-
 #endif /* _WIN32 */
index 15b3afe1d83bfd8a7b6bbceb0a312aff2289b172..0ab4c303d465c6d46aeb19ca4a18600ebc6e2e28 100644 (file)
 #include <ws2tcpip.h>
 #include <windows.h>
 
-#ifdef _MSC_VER
-typedef int __w64 ssize_t;
-#endif
-
 struct passwd {
     char *pw_name;
 };
 
-struct iovec {
-    void *iov_base;
-    size_t iov_len;
-};
-
 #define W32_FD_TO_SOCKET(fd) ((SOCKET)_get_osfhandle((fd)))
 #define W32_SOCKET_TO_FD(fh) (_open_osfhandle((long)(fh), O_RDWR | O_BINARY))
 
@@ -62,10 +53,6 @@ extern int w32_send(int sockfd, const void *, size_t, int flags);
 extern int w32_close(int fd);
 extern int w32_socket(int domain, int type, int protocol);
 extern int w32_connect(int sockfd, const struct sockaddr *, int addrlen);
-extern ssize_t w32_readv_fd(int fd, const struct iovec *iov,
-                           int iovcnt);
-extern ssize_t w32_writev_socket(int sockfd, const struct iovec *iov,
-                                int iovcnt);
 
 extern struct passwd *w32_getpw(void);
 extern void w32_sysdep_init(void);
index 07542b1184b873a4c472747e172ae35afaac8e7e..5a388a36c1f09c0e48a745a791b0ee47b03c253e 100644 (file)
@@ -35,7 +35,7 @@
 #define SYS_UIO_H
 
 #include <sys/types.h>
-#include "w32misc.h"
+#include "w32types.h"
 
 struct iovec {
     /* Base address of a memory region for input or output. */
index e7ff6a95b01f3c57998c60ee0212eb281937d52e..eeb1c6e1bf76b43ef1bf1757394b73f82c52106e 100644 (file)
@@ -50,8 +50,7 @@
 #include <io.h>
 #include <direct.h>
 #include <sys/stat.h>
-
-#include "w32misc.h"
+#include "w32types.h"
 
 /*
  * w32file.c
index ffeff1ed86214a3670edf25706b2422e5e80d89e..f89408323124d2b06771646fc83ca7729a35e998 100644 (file)
@@ -75,14 +75,6 @@ extern long __random(void);
 extern char *__setstate(char *state);
 extern void __srandom(unsigned seed);
 
-/* sys/types.h */
-#ifdef _MSC_VER
-typedef unsigned short mode_t;
-typedef long off_t;
-typedef int pid_t;
-typedef int __w64 ssize_t;
-#endif
-
 /* time.h */
 struct tm;
 extern char *strptime(const char *buf, const char *fmt, struct tm *tm);
diff --git a/src/lib/w32/w32types.h b/src/lib/w32/w32types.h
new file mode 100644 (file)
index 0000000..7479015
--- /dev/null
@@ -0,0 +1,46 @@
+/*
+ *  Empire - A multi-player, client/server Internet based war game.
+ *  Copyright (C) 1986-2009, Dave Pare, Jeff Bailey, Thomas Ruschak,
+ *                           Ken Stevens, Steve McClure
+ *
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; either version 2 of the License, or
+ *  (at your option) any later version.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with this program; if not, write to the Free Software
+ *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ *
+ *  ---
+ *
+ *  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.
+ *
+ *  ---
+ *
+ *  w32types.h: POSIX emulation for WIN32, missing types
+ *
+ *  Known contributors to this file:
+ *     Ron Koenderink, 2007
+ *     Markus Armbruster, 2009
+ */
+
+#ifndef W32TYPES_H
+#define W32TYPES_H
+
+/* sys/types.h */
+#ifdef _MSC_VER
+typedef unsigned short mode_t;
+typedef long off_t;
+typedef int pid_t;
+typedef int __w64 ssize_t;
+#endif
+
+#endif