@matheusbsbs / matheus-bagliano / commits / fdc1211463
Fork 0

mingw: use poll-emulation from gnulib

Signed-off-by: Erik Faye-Lund <kusmabite@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Erik Faye-Lund committed Nov 4, 2010 at 02:35 UTC fdc12114635581b6901940ddb467a78716bc12ca
5 files changed +6 -81
Makefile
+4 -2
@@ -497,6 +497,7 @@ LIB_H += compat/cygwin.h
497 LIB_H += compat/mingw.h
498 LIB_H += compat/win32/pthread.h
499 LIB_H += compat/win32/syslog.h
500 +LIB_H += compat/win32/sys/poll.h
501 LIB_H += csum-file.h
502 LIB_H += decorate.h
503 LIB_H += delta.h
@@ -1082,7 +1083,7 @@ ifeq ($(uname_S),Windows)
1083 AR = compat/vcbuild/scripts/lib.pl
1084 CFLAGS =
1085 BASIC_CFLAGS = -nologo -I. -I../zlib -Icompat/vcbuild -Icompat/vcbuild/include -DWIN32 -D_CONSOLE -DHAVE_STRING_H -D_CRT_SECURE_NO_WARNINGS -D_CRT_NONSTDC_NO_DEPRECATE
1085 - COMPAT_OBJS = compat/msvc.o compat/fnmatch/fnmatch.o compat/winansi.o compat/win32/pthread.o compat/win32/syslog.o
1086 + COMPAT_OBJS = compat/msvc.o compat/fnmatch/fnmatch.o compat/winansi.o compat/win32/pthread.o compat/win32/syslog.o compat/win32/sys/poll.o
1087 COMPAT_CFLAGS = -D__USE_MINGW_ACCESS -DNOGDI -DHAVE_STRING_H -DHAVE_ALLOCA_H -Icompat -Icompat/fnmatch -Icompat/regex -Icompat/fnmatch -Icompat/win32 -DSTRIP_EXTENSION=\".exe\"
1088 BASIC_LDFLAGS = -IGNORE:4217 -IGNORE:4049 -NOLOGO -SUBSYSTEM:CONSOLE -NODEFAULTLIB:MSVCRT.lib
1089 EXTLIBS = advapi32.lib shell32.lib wininet.lib ws2_32.lib
@@ -1132,7 +1133,8 @@ ifneq (,$(findstring MINGW,$(uname_S)))
1133 COMPAT_CFLAGS += -D__USE_MINGW_ACCESS -DNOGDI -Icompat -Icompat/fnmatch -Icompat/win32
1134 COMPAT_CFLAGS += -DSTRIP_EXTENSION=\".exe\"
1135 COMPAT_OBJS += compat/mingw.o compat/fnmatch/fnmatch.o compat/winansi.o \
1135 - compat/win32/pthread.o compat/win32/syslog.o
1136 + compat/win32/pthread.o compat/win32/syslog.o \
1137 + compat/win32/sys/poll.o
1138 EXTLIBS += -lws2_32
1139 PTHREAD_LIBS =
1140 X = .exe
compat/mingw.c
-65
@@ -408,71 +408,6 @@ int pipe(int filedes[2])
408 return 0;
409 }
410
411 -int poll(struct pollfd *ufds, unsigned int nfds, int timeout)
412 -{
413 - int i, pending;
414 -
415 - if (timeout >= 0) {
416 - if (nfds == 0) {
417 - Sleep(timeout);
418 - return 0;
419 - }
420 - return errno = EINVAL, error("poll timeout not supported");
421 - }
422 -
423 - /* When there is only one fd to wait for, then we pretend that
424 - * input is available and let the actual wait happen when the
425 - * caller invokes read().
426 - */
427 - if (nfds == 1) {
428 - if (!(ufds[0].events & POLLIN))
429 - return errno = EINVAL, error("POLLIN not set");
430 - ufds[0].revents = POLLIN;
431 - return 0;
432 - }
433 -
434 -repeat:
435 - pending = 0;
436 - for (i = 0; i < nfds; i++) {
437 - DWORD avail = 0;
438 - HANDLE h = (HANDLE) _get_osfhandle(ufds[i].fd);
439 - if (h == INVALID_HANDLE_VALUE)
440 - return -1; /* errno was set */
441 -
442 - if (!(ufds[i].events & POLLIN))
443 - return errno = EINVAL, error("POLLIN not set");
444 -
445 - /* this emulation works only for pipes */
446 - if (!PeekNamedPipe(h, NULL, 0, NULL, &avail, NULL)) {
447 - int err = GetLastError();
448 - if (err == ERROR_BROKEN_PIPE) {
449 - ufds[i].revents = POLLHUP;
450 - pending++;
451 - } else {
452 - errno = EINVAL;
453 - return error("PeekNamedPipe failed,"
454 - " GetLastError: %u", err);
455 - }
456 - } else if (avail) {
457 - ufds[i].revents = POLLIN;
458 - pending++;
459 - } else
460 - ufds[i].revents = 0;
461 - }
462 - if (!pending) {
463 - /* The only times that we spin here is when the process
464 - * that is connected through the pipes is waiting for
465 - * its own input data to become available. But since
466 - * the process (pack-objects) is itself CPU intensive,
467 - * it will happily pick up the time slice that we are
468 - * relinquishing here.
469 - */
470 - Sleep(0);
471 - goto repeat;
472 - }
473 - return 0;
474 -}
475 -
411 struct tm *gmtime_r(const time_t *timep, struct tm *result)
412 {
413 /* gmtime() in MSVCRT.DLL is thread-safe, but not reentrant */
compat/mingw.h
-11
@@ -59,16 +59,6 @@ struct passwd {
59
60 extern char *getpass(const char *prompt);
61
62 -#ifndef POLLIN
63 -struct pollfd {
64 - int fd; /* file descriptor */
65 - short events; /* requested events */
66 - short revents; /* returned events */
67 -};
68 -#define POLLIN 1
69 -#define POLLHUP 2
70 -#endif
71 -
62 typedef void (__cdecl *sig_handler_t)(int);
63 struct sigaction {
64 sig_handler_t sa_handler;
@@ -175,7 +165,6 @@ int pipe(int filedes[2]);
165 unsigned int sleep (unsigned int seconds);
166 int mkstemp(char *template);
167 int gettimeofday(struct timeval *tv, void *tz);
178 -int poll(struct pollfd *ufds, unsigned int nfds, int timeout);
168 struct tm *gmtime_r(const time_t *timep, struct tm *result);
169 struct tm *localtime_r(const time_t *timep, struct tm *result);
170 int getpagesize(void); /* defined in MinGW's libgcc.a */
compat/win32/sys/poll.c
+1 -2
@@ -24,8 +24,7 @@
24 # pragma GCC diagnostic ignored "-Wtype-limits"
25 #endif
26
27 -#include <config.h>
28 -#include <alloca.h>
27 +#include <malloc.h>
28
29 #include <sys/types.h>
30 #include "poll.h"
git-compat-util.h
+1 -1
@@ -105,9 +105,9 @@
105 #include <regex.h>
106 #include <utime.h>
107 #include <syslog.h>
108 +#include <sys/poll.h>
109 #ifndef __MINGW32__
110 #include <sys/wait.h>
110 -#include <sys/poll.h>
111 #include <sys/socket.h>
112 #include <sys/ioctl.h>
113 #include <termios.h>