Skip to content

Commit d782797

Browse files
committed
Merge branch 'js/poll-emu'
* js/poll-emu: make poll() work on platforms that can't recv() on a non-socket poll() exits too early with EFAULT if 1st arg is NULL fix some win32 specific dependencies in poll.c make poll available for other platforms lacking it
2 parents 0ec6aa5 + a677294 commit d782797

File tree

3 files changed

+26
-8
lines changed

3 files changed

+26
-8
lines changed

Makefile

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,11 @@ all::
154154
#
155155
# Define NO_MMAP if you want to avoid mmap.
156156
#
157+
# Define NO_SYS_POLL_H if you don't have sys/poll.h.
158+
#
159+
# Define NO_POLL if you do not have or don't want to use poll().
160+
# This also implies NO_SYS_POLL_H.
161+
#
157162
# Define NO_PTHREADS if you do not have or do not want to use Pthreads.
158163
#
159164
# Define NO_PREAD if you have a problem with pread() system call (e.g.
@@ -604,10 +609,10 @@ LIB_H += compat/bswap.h
604609
LIB_H += compat/cygwin.h
605610
LIB_H += compat/mingw.h
606611
LIB_H += compat/obstack.h
612+
LIB_H += compat/poll/poll.h
607613
LIB_H += compat/precompose_utf8.h
608614
LIB_H += compat/terminal.h
609615
LIB_H += compat/win32/dirent.h
610-
LIB_H += compat/win32/poll.h
611616
LIB_H += compat/win32/pthread.h
612617
LIB_H += compat/win32/syslog.h
613618
LIB_H += connected.h
@@ -1225,7 +1230,7 @@ ifeq ($(uname_S),Windows)
12251230
NO_PREAD = YesPlease
12261231
NEEDS_CRYPTO_WITH_SSL = YesPlease
12271232
NO_LIBGEN_H = YesPlease
1228-
NO_SYS_POLL_H = YesPlease
1233+
NO_POLL = YesPlease
12291234
NO_SYMLINK_HEAD = YesPlease
12301235
NO_IPV6 = YesPlease
12311236
NO_UNIX_SOCKETS = YesPlease
@@ -1266,7 +1271,7 @@ ifeq ($(uname_S),Windows)
12661271
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
12671272
COMPAT_OBJS = compat/msvc.o compat/winansi.o \
12681273
compat/win32/pthread.o compat/win32/syslog.o \
1269-
compat/win32/poll.o compat/win32/dirent.o
1274+
compat/win32/dirent.o
12701275
COMPAT_CFLAGS = -D__USE_MINGW_ACCESS -DNOGDI -DHAVE_STRING_H -DHAVE_ALLOCA_H -Icompat -Icompat/regex -Icompat/win32 -DSTRIP_EXTENSION=\".exe\"
12711276
BASIC_LDFLAGS = -IGNORE:4217 -IGNORE:4049 -NOLOGO -SUBSYSTEM:CONSOLE -NODEFAULTLIB:MSVCRT.lib
12721277
EXTLIBS = user32.lib advapi32.lib shell32.lib wininet.lib ws2_32.lib
@@ -1321,7 +1326,7 @@ ifneq (,$(findstring MINGW,$(uname_S)))
13211326
NO_PREAD = YesPlease
13221327
NEEDS_CRYPTO_WITH_SSL = YesPlease
13231328
NO_LIBGEN_H = YesPlease
1324-
NO_SYS_POLL_H = YesPlease
1329+
NO_POLL = YesPlease
13251330
NO_SYMLINK_HEAD = YesPlease
13261331
NO_UNIX_SOCKETS = YesPlease
13271332
NO_SETENV = YesPlease
@@ -1356,7 +1361,7 @@ ifneq (,$(findstring MINGW,$(uname_S)))
13561361
COMPAT_CFLAGS += -DSTRIP_EXTENSION=\".exe\"
13571362
COMPAT_OBJS += compat/mingw.o compat/winansi.o \
13581363
compat/win32/pthread.o compat/win32/syslog.o \
1359-
compat/win32/poll.o compat/win32/dirent.o
1364+
compat/win32/dirent.o
13601365
EXTLIBS += -lws2_32
13611366
PTHREAD_LIBS =
13621367
X = .exe
@@ -1610,6 +1615,11 @@ ifdef NO_GETTEXT
16101615
BASIC_CFLAGS += -DNO_GETTEXT
16111616
USE_GETTEXT_SCHEME ?= fallthrough
16121617
endif
1618+
ifdef NO_POLL
1619+
NO_SYS_POLL_H = YesPlease
1620+
COMPAT_CFLAGS += -DNO_POLL -Icompat/poll
1621+
COMPAT_OBJS += compat/poll/poll.o
1622+
endif
16131623
ifdef NO_STRCASESTR
16141624
COMPAT_CFLAGS += -DNO_STRCASESTR
16151625
COMPAT_OBJS += compat/strcasestr.o

compat/win32/poll.c renamed to compat/poll/poll.c

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,9 @@
2424
# pragma GCC diagnostic ignored "-Wtype-limits"
2525
#endif
2626

27-
#include <malloc.h>
27+
#if defined(WIN32)
28+
# include <malloc.h>
29+
#endif
2830

2931
#include <sys/types.h>
3032

@@ -48,7 +50,9 @@
4850
#else
4951
# include <sys/time.h>
5052
# include <sys/socket.h>
51-
# include <sys/select.h>
53+
# ifndef NO_SYS_SELECT_H
54+
# include <sys/select.h>
55+
# endif
5256
# include <unistd.h>
5357
#endif
5458

@@ -302,6 +306,10 @@ compute_revents (int fd, int sought, fd_set *rfds, fd_set *wfds, fd_set *efds)
302306
|| socket_errno == ECONNABORTED || socket_errno == ENETRESET)
303307
happened |= POLLHUP;
304308

309+
/* some systems can't use recv() on non-socket, including HP NonStop */
310+
else if (/* (r == -1) && */ socket_errno == ENOTSOCK)
311+
happened |= (POLLIN | POLLRDNORM) & sought;
312+
305313
else
306314
happened |= POLLERR;
307315
}
@@ -349,7 +357,7 @@ poll (struct pollfd *pfd, nfds_t nfd, int timeout)
349357

350358
/* EFAULT is not necessary to implement, but let's do it in the
351359
simplest case. */
352-
if (!pfd)
360+
if (!pfd && nfd)
353361
{
354362
errno = EFAULT;
355363
return -1;
File renamed without changes.

0 commit comments

Comments
 (0)