Alexandre Julliard : libport: Replacement for poll().
Alexandre Julliard
julliard at winehq.org
Tue Dec 23 13:40:38 CST 2008
Module: wine
Branch: master
Commit: dc1a9f19c1f4c462f1e68e0def50e9c09812bc71
URL: http://source.winehq.org/git/wine.git/?a=commit;h=dc1a9f19c1f4c462f1e68e0def50e9c09812bc71
Author: Alexandre Julliard <julliard at winehq.org>
Date: Mon Dec 22 17:36:18 2008 +0100
libport: Replacement for poll().
---
configure | 5 ++-
configure.ac | 3 +-
dlls/Makedll.rules.in | 2 +-
dlls/winhttp/Makefile.in | 1 +
include/config.h.in | 3 ++
include/wine/port.h | 16 +++++++++
libs/port/Makefile.in | 1 +
libs/port/poll.c | 77 ++++++++++++++++++++++++++++++++++++++++++++++
8 files changed, 105 insertions(+), 3 deletions(-)
diff --git a/configure b/configure
index 8574025..43ea106 100755
--- a/configure
+++ b/configure
@@ -7438,6 +7438,7 @@ done
+
for ac_header in \
AudioUnit/AudioUnit.h \
Carbon/Carbon.h \
@@ -7551,6 +7552,7 @@ for ac_header in \
termios.h \
unistd.h \
utime.h \
+ winsock2.h \
valgrind/memcheck.h \
valgrind/valgrind.h
@@ -14580,6 +14582,7 @@ fi
+
for ac_header in ft2build.h \
freetype/freetype.h \
freetype/ftglyph.h \
@@ -17694,7 +17697,7 @@ case $host_os in
mingw32*)
CRTLIBS="-lmsvcrt"
- SOCKETLIBS="-lws2_32"
+ SOCKETLIBS="-L\$(TOPOBJDIR)/dlls/ws2_32 -lws2_32"
;;
esac
diff --git a/configure.ac b/configure.ac
index ce90fca..400011c 100644
--- a/configure.ac
+++ b/configure.ac
@@ -351,6 +351,7 @@ AC_CHECK_HEADERS(\
termios.h \
unistd.h \
utime.h \
+ winsock2.h \
valgrind/memcheck.h \
valgrind/valgrind.h
)
@@ -1334,7 +1335,7 @@ dnl Mingw needs explicit msvcrt for linking libwine and winsock for wininet
case $host_os in
mingw32*)
AC_SUBST(CRTLIBS,"-lmsvcrt")
- AC_SUBST(SOCKETLIBS,"-lws2_32")
+ AC_SUBST(SOCKETLIBS,"-L\$(TOPOBJDIR)/dlls/ws2_32 -lws2_32")
;;
esac
diff --git a/dlls/Makedll.rules.in b/dlls/Makedll.rules.in
index 965302f..c916966 100644
--- a/dlls/Makedll.rules.in
+++ b/dlls/Makedll.rules.in
@@ -18,7 +18,7 @@ MAINSPEC = $(BASEMODULE).spec
SPEC_DEF = $(BASEMODULE).def
WIN16_FILES = $(SPEC_SRCS16:.spec=.spec.o) $(C_SRCS16:.c=.o) $(EXTRA_OBJS16)
ALL_OBJS = @WIN16_FILES@ $(OBJS) $(RC_SRCS:.rc=.res)
-ALL_LIBS = $(EXTRALIBS) $(LIBPORT) $(LDFLAGS) $(LIBS)
+ALL_LIBS = $(LIBPORT) $(EXTRALIBS) $(LDFLAGS) $(LIBS)
IMPLIB_OBJS = $(IMPLIB_SRCS:.c=.o)
IMPORTLIBFILE = $(IMPORTLIB:%=lib%.$(IMPLIBEXT))
STATICIMPLIB = $(IMPORTLIBFILE:.def=.def.a)
diff --git a/dlls/winhttp/Makefile.in b/dlls/winhttp/Makefile.in
index 40e8fa9..78d3814 100644
--- a/dlls/winhttp/Makefile.in
+++ b/dlls/winhttp/Makefile.in
@@ -6,6 +6,7 @@ MODULE = winhttp.dll
IMPORTLIB = winhttp
IMPORTS = shlwapi kernel32
DELAYIMPORTS = crypt32
+EXTRALIBS = @SOCKETLIBS@
C_SRCS = \
cookie.c \
diff --git a/include/config.h.in b/include/config.h.in
index 790c6ba..4aafaed 100644
--- a/include/config.h.in
+++ b/include/config.h.in
@@ -960,6 +960,9 @@
/* Define to 1 if you have the `waitpid' function. */
#undef HAVE_WAITPID
+/* Define to 1 if you have the <winsock2.h> header file. */
+#undef HAVE_WINSOCK2_H
+
/* Define to 1 if you have the <X11/extensions/shape.h> header file. */
#undef HAVE_X11_EXTENSIONS_SHAPE_H
diff --git a/include/wine/port.h b/include/wine/port.h
index 4080444..e445c08 100644
--- a/include/wine/port.h
+++ b/include/wine/port.h
@@ -305,6 +305,22 @@ int lstat(const char *file_name, struct stat *buf);
void *memmove(void *dest, const void *src, size_t len);
#endif /* !defined(HAVE_MEMMOVE) */
+#ifndef HAVE_POLL
+struct pollfd
+{
+ int fd;
+ short events;
+ short revents;
+};
+#define POLLIN 0x01
+#define POLLPRI 0x02
+#define POLLOUT 0x04
+#define POLLERR 0x08
+#define POLLHUP 0x10
+#define POLLNVAL 0x20
+int poll( struct pollfd *fds, unsigned int count, int timeout );
+#endif /* HAVE_POLL */
+
#ifndef HAVE_PREAD
ssize_t pread( int fd, void *buf, size_t count, off_t offset );
#endif /* HAVE_PREAD */
diff --git a/libs/port/Makefile.in b/libs/port/Makefile.in
index da0b708..c4c0127 100644
--- a/libs/port/Makefile.in
+++ b/libs/port/Makefile.in
@@ -21,6 +21,7 @@ C_SRCS = \
memcpy_unaligned.c \
memmove.c \
mkstemps.c \
+ poll.c \
pread.c \
pwrite.c \
readlink.c \
diff --git a/libs/port/poll.c b/libs/port/poll.c
new file mode 100644
index 0000000..b633a0d
--- /dev/null
+++ b/libs/port/poll.c
@@ -0,0 +1,77 @@
+/*
+ * poll function
+ *
+ * Copyright 2008 Alexandre Julliard
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
+ */
+
+#include "config.h"
+#include "wine/port.h"
+
+#ifndef HAVE_POLL
+
+#ifdef HAVE_WINSOCK2_H
+#include <winsock2.h>
+#endif
+#ifdef HAVE_SYS_TIME_H
+#include <sys/time.h>
+#endif
+#ifdef HAVE_UNISTD_H
+#include <unistd.h>
+#endif
+
+int poll( struct pollfd *fds, unsigned int count, int timeout )
+{
+ fd_set read_set, write_set, except_set;
+ unsigned int i;
+ int maxfd = -1, ret;
+
+ FD_ZERO( &read_set );
+ FD_ZERO( &write_set );
+ FD_ZERO( &except_set );
+
+ for (i = 0; i < count; i++)
+ {
+ if (fds[i].fd == -1) continue;
+ if (fds[i].events & (POLLIN|POLLPRI)) FD_SET( fds[i].fd, &read_set );
+ if (fds[i].events & POLLOUT) FD_SET( fds[i].fd, &write_set );
+ FD_SET( fds[i].fd, &except_set ); /* POLLERR etc. are always selected */
+ if (fds[i].fd > maxfd) maxfd = fds[i].fd;
+ }
+ if (timeout != -1)
+ {
+ struct timeval tv;
+ tv.tv_sec = timeout / 1000;
+ tv.tv_usec = timeout % 1000;
+ ret = select( maxfd + 1, &read_set, &write_set, &except_set, &tv );
+ }
+ else ret = select( maxfd + 1, &read_set, &write_set, &except_set, NULL );
+
+ if (ret >= 0)
+ {
+ for (i = 0; i < count; i++)
+ {
+ fds[i].revents = 0;
+ if (fds[i].fd == -1) continue;
+ if (FD_ISSET( fds[i].fd, &read_set )) fds[i].revents |= POLLIN;
+ if (FD_ISSET( fds[i].fd, &write_set )) fds[i].revents |= POLLOUT;
+ if (FD_ISSET( fds[i].fd, &except_set )) fds[i].revents |= POLLERR;
+ }
+ }
+ return ret;
+}
+
+#endif /* HAVE_POLL */
More information about the wine-cvs
mailing list