libport: Replacement for poll().

This commit is contained in:
Alexandre Julliard 2008-12-22 17:36:18 +01:00
parent 028617b90b
commit dc1a9f19c1
8 changed files with 105 additions and 3 deletions

5
configure vendored
View File

@ -7436,6 +7436,7 @@ done
for ac_header in \
@ -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

View File

@ -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

View File

@ -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)

View File

@ -6,6 +6,7 @@ MODULE = winhttp.dll
IMPORTLIB = winhttp
IMPORTS = shlwapi kernel32
DELAYIMPORTS = crypt32
EXTRALIBS = @SOCKETLIBS@
C_SRCS = \
cookie.c \

View File

@ -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

View File

@ -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 */

View File

@ -21,6 +21,7 @@ C_SRCS = \
memcpy_unaligned.c \
memmove.c \
mkstemps.c \
poll.c \
pread.c \
pwrite.c \
readlink.c \

77
libs/port/poll.c Normal file
View File

@ -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 */