From: Jonathan Nieder <jrnieder@gmail.com>
To: Jonathan Callen <abcd@gentoo.org>
Cc: git@vger.kernel.org, mduft@gentoo.org,
Sverre Rabbelier <srabbelier@gmail.com>,
Michael J Gruber <git@drmicha.warpmail.net>,
Johannes Sixt <j6t@kdbg.org>
Subject: [PATCH] compat: Add another rudimentary poll() emulation
Date: Thu, 27 May 2010 05:10:43 -0500 [thread overview]
Message-ID: <20100527101043.GA4390@progeny.tock> (raw)
In-Reply-To: <1274948384-167-2-git-send-email-abcd@gentoo.org>
Implement the subset of poll() semantics needed by git in terms of
select(), for use by the Interix port. Inspired by commit 6ed807f
(Windows: A rudimentary poll() emulation, 2007-12-01).
Cc: Johannes Sixt <j6t@kdbg.org>
Cc: Jonathan Callen <abcd@gentoo.org>
Signed-off-by: Jonathan Nieder <jrnieder@gmail.com>
---
Jonathan Callen wrote:
> Some systems do not have sys/poll.h or poll(2).
Maybe this could help. Thanks to DrNick on IRC for the suggestion.
Warning: untested.
Makefile | 8 ++++++++
compat/poll.c | 33 +++++++++++++++++++++++++++++++++
compat/poll.h | 13 +++++++++++++
git-compat-util.h | 6 +++++-
4 files changed, 59 insertions(+), 1 deletions(-)
create mode 100644 compat/poll.c
create mode 100644 compat/poll.h
diff --git a/Makefile b/Makefile
index 2f5d631..6715528 100644
--- a/Makefile
+++ b/Makefile
@@ -111,6 +111,9 @@ all::
#
# Define NO_PTHREADS if you do not have or do not want to use Pthreads.
#
+# Define NO_POLL if you have a problem with the poll() system call (e.g.
+# Interix).
+#
# Define NO_PREAD if you have a problem with pread() system call (e.g.
# cygwin1.dll before v1.5.22).
#
@@ -470,6 +473,7 @@ LIB_H += commit.h
LIB_H += compat/bswap.h
LIB_H += compat/cygwin.h
LIB_H += compat/mingw.h
+LIB_H += compat/poll.h
LIB_H += compat/win32/pthread.h
LIB_H += csum-file.h
LIB_H += decorate.h
@@ -1284,6 +1288,10 @@ endif
ifdef OBJECT_CREATION_USES_RENAMES
COMPAT_CFLAGS += -DOBJECT_CREATION_MODE=1
endif
+ifdef NO_POLL
+ BASIC_CFLAGS += -DNO_POLL
+ COMPAT_OBJS += compat/poll.o
+endif
ifdef NO_PREAD
COMPAT_CFLAGS += -DNO_PREAD
COMPAT_OBJS += compat/pread.o
diff --git a/compat/poll.c b/compat/poll.c
new file mode 100644
index 0000000..33c6ae0
--- /dev/null
+++ b/compat/poll.c
@@ -0,0 +1,33 @@
+#include "../git-compat-util.h"
+
+int git_poll(struct git_pollfd *ufds, int nfds, int timeout)
+{
+ int i, maxfd, result;
+ fd_set fds;
+
+ if (timeout >= 0) {
+ if (nfds == 0) {
+ sleep(timeout);
+ return 0;
+ }
+ return errno = EINVAL, error("poll timeout not supported");
+ }
+
+ FD_ZERO(&fds);
+ maxfd = 0;
+ for (i = 0; i < nfds; i++) {
+ if (ufds[i].events != POLLIN)
+ return errno = EINVAL, error("poll: unsupported events");
+ maxfd = (ufds[i].fd > maxfd) ? ufds[i].fd : maxfd;
+ FD_SET(ufds[i].fd, &fds);
+ }
+
+ result = select(maxfd + 1, &fds, NULL, NULL, NULL);
+ if (result == -1)
+ return result;
+ for (i = 0; i < nfds; i++) {
+ if (FD_ISSET(ufds[i].fd, &fds))
+ ufds[i].revents |= POLLIN;
+ }
+ return result;
+}
diff --git a/compat/poll.h b/compat/poll.h
new file mode 100644
index 0000000..65775ab
--- /dev/null
+++ b/compat/poll.h
@@ -0,0 +1,13 @@
+#ifndef POLLIN
+#define POLLIN 1
+#define POLLHUP 2
+#endif
+
+#define pollfd git_pollfd
+#define poll git_poll
+struct git_pollfd {
+ int fd; /* file descriptor */
+ short events; /* requested events */
+ short revents; /* returned events */
+};
+extern int git_poll(struct git_pollfd *fds, int nfds, int timeout);
diff --git a/git-compat-util.h b/git-compat-util.h
index 824c175..2494378 100644
--- a/git-compat-util.h
+++ b/git-compat-util.h
@@ -94,13 +94,17 @@
#include <utime.h>
#ifndef __MINGW32__
#include <sys/wait.h>
-#include <sys/poll.h>
#include <sys/socket.h>
#include <sys/ioctl.h>
#include <termios.h>
#ifndef NO_SYS_SELECT_H
#include <sys/select.h>
#endif
+#ifdef NO_POLL
+#include "compat/poll.h"
+#else
+#include <sys/poll.h>
+#endif
#include <netinet/in.h>
#include <netinet/tcp.h>
#include <arpa/inet.h>
--
1.7.1
next prev parent reply other threads:[~2010-05-27 10:10 UTC|newest]
Thread overview: 39+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-05-27 8:19 [PATCH 0/3] Interix support Jonathan Callen
2010-05-27 8:19 ` [PATCH 1/3] Support building on systems without poll(2) Jonathan Callen
2010-05-27 8:43 ` Sverre Rabbelier
2010-05-27 13:02 ` Jeff King
2010-05-27 8:51 ` Michael J Gruber
2010-05-27 9:13 ` Jonathan Callen
2010-05-27 10:10 ` Jonathan Nieder [this message]
2010-05-27 11:00 ` [PATCH] compat: Add another rudimentary poll() emulation Erik Faye-Lund
2010-05-27 11:39 ` Marko Kreen
2010-05-27 12:00 ` Erik Faye-Lund
2010-05-27 12:36 ` Marko Kreen
2010-05-27 12:57 ` Erik Faye-Lund
2010-05-27 13:43 ` [msysGit] " Albert Dvornik
2010-05-30 7:44 ` Paolo Bonzini
2010-05-27 13:06 ` Erik Faye-Lund
2010-05-27 13:29 ` Marko Kreen
2010-05-27 13:46 ` Erik Faye-Lund
2010-05-27 13:58 ` Marko Kreen
2010-05-27 14:06 ` Erik Faye-Lund
2010-05-27 14:11 ` Marko Kreen
2010-05-27 14:15 ` Erik Faye-Lund
2010-05-27 14:32 ` Marko Kreen
2010-05-27 14:44 ` Erik Faye-Lund
2010-05-27 15:17 ` Peter Kjellerstedt
2010-05-27 14:14 ` [msysGit] " Albert Dvornik
2010-05-27 14:05 ` Albert Dvornik
2010-05-30 0:37 ` [PATCH v2] " Jonathan Nieder
2010-05-30 19:19 ` Johannes Sixt
2010-05-30 20:40 ` Jonathan Nieder
2010-05-30 22:39 ` Joshua Juran
2010-05-31 3:19 ` Mac OS 9 (Lamp) port Jonathan Nieder
2010-05-31 4:35 ` Joshua Juran
2010-05-31 5:49 ` Jonathan Nieder
2010-05-31 12:12 ` [PATCH v2] compat: Add another rudimentary poll() emulation Albert Dvornik
2010-05-31 12:46 ` Jonathan Nieder
2010-05-31 13:10 ` Albert Dvornik
2010-05-27 8:19 ` [PATCH 2/3] Support building without inttypes.h Jonathan Callen
2010-05-27 8:19 ` [PATCH 3/3] Add Interix support Jonathan Callen
2010-05-28 2:11 ` [PATCH 0/3] " Jakub Narebski
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20100527101043.GA4390@progeny.tock \
--to=jrnieder@gmail.com \
--cc=abcd@gentoo.org \
--cc=git@drmicha.warpmail.net \
--cc=git@vger.kernel.org \
--cc=j6t@kdbg.org \
--cc=mduft@gentoo.org \
--cc=srabbelier@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).