From: Julian Seward Date: Wed, 26 Jun 2002 00:13:36 +0000 (+0000) Subject: wait_for_fd_to_be_readable_or_erring: return immediately if fd is X-Git-Tag: svn/VALGRIND_1_0_3~35 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=52f9eb2462e851b1a11a7a7e0e6967e8ac3c1f32;p=thirdparty%2Fvalgrind.git wait_for_fd_to_be_readable_or_erring: return immediately if fd is nonblocking anyway. git-svn-id: svn://svn.valgrind.org/valgrind/trunk@465 --- diff --git a/coregrind/arch/x86-linux/vg_libpthread.c b/coregrind/arch/x86-linux/vg_libpthread.c index 3510ed3767..d736558f03 100644 --- a/coregrind/arch/x86-linux/vg_libpthread.c +++ b/coregrind/arch/x86-linux/vg_libpthread.c @@ -2097,10 +2097,27 @@ int poll (struct pollfd *__fds, nfds_t __nfds, int __timeout) /* Helper function used to make accept() non-blocking. Idea is to use the above nonblocking poll() to make this thread ONLY wait for the specified fd to become ready, and then return. */ + +/* Sigh -- a hack. We're not supposed to include this file directly; + should do it via /usr/include/fcntl.h, but that introduces a + varargs prototype for fcntl itself, which we can't mimic. */ +#define _FCNTL_H +#include + static void wait_for_fd_to_be_readable_or_erring ( int fd ) { struct pollfd pfd; + int res; + /* fprintf(stderr, "wait_for_fd_to_be_readable_or_erring %d\n", fd); */ + + /* First check to see if the fd is nonblocking, and/or invalid. In + either case return immediately. */ + res = __libc_fcntl(fd, F_GETFL, 0); + if (res == -1) return; /* fd is invalid somehow */ + if (res & O_NONBLOCK) return; /* fd is nonblocking */ + + /* Ok, we'd better wait with poll. */ pfd.fd = fd; pfd.events = POLLIN | POLLPRI | POLLERR | POLLHUP | POLLNVAL; /* ... but not POLLOUT, you may notice. */ diff --git a/coregrind/vg_libpthread.c b/coregrind/vg_libpthread.c index 3510ed3767..d736558f03 100644 --- a/coregrind/vg_libpthread.c +++ b/coregrind/vg_libpthread.c @@ -2097,10 +2097,27 @@ int poll (struct pollfd *__fds, nfds_t __nfds, int __timeout) /* Helper function used to make accept() non-blocking. Idea is to use the above nonblocking poll() to make this thread ONLY wait for the specified fd to become ready, and then return. */ + +/* Sigh -- a hack. We're not supposed to include this file directly; + should do it via /usr/include/fcntl.h, but that introduces a + varargs prototype for fcntl itself, which we can't mimic. */ +#define _FCNTL_H +#include + static void wait_for_fd_to_be_readable_or_erring ( int fd ) { struct pollfd pfd; + int res; + /* fprintf(stderr, "wait_for_fd_to_be_readable_or_erring %d\n", fd); */ + + /* First check to see if the fd is nonblocking, and/or invalid. In + either case return immediately. */ + res = __libc_fcntl(fd, F_GETFL, 0); + if (res == -1) return; /* fd is invalid somehow */ + if (res & O_NONBLOCK) return; /* fd is nonblocking */ + + /* Ok, we'd better wait with poll. */ pfd.fd = fd; pfd.events = POLLIN | POLLPRI | POLLERR | POLLHUP | POLLNVAL; /* ... but not POLLOUT, you may notice. */ diff --git a/vg_libpthread.c b/vg_libpthread.c index 3510ed3767..d736558f03 100644 --- a/vg_libpthread.c +++ b/vg_libpthread.c @@ -2097,10 +2097,27 @@ int poll (struct pollfd *__fds, nfds_t __nfds, int __timeout) /* Helper function used to make accept() non-blocking. Idea is to use the above nonblocking poll() to make this thread ONLY wait for the specified fd to become ready, and then return. */ + +/* Sigh -- a hack. We're not supposed to include this file directly; + should do it via /usr/include/fcntl.h, but that introduces a + varargs prototype for fcntl itself, which we can't mimic. */ +#define _FCNTL_H +#include + static void wait_for_fd_to_be_readable_or_erring ( int fd ) { struct pollfd pfd; + int res; + /* fprintf(stderr, "wait_for_fd_to_be_readable_or_erring %d\n", fd); */ + + /* First check to see if the fd is nonblocking, and/or invalid. In + either case return immediately. */ + res = __libc_fcntl(fd, F_GETFL, 0); + if (res == -1) return; /* fd is invalid somehow */ + if (res & O_NONBLOCK) return; /* fd is nonblocking */ + + /* Ok, we'd better wait with poll. */ pfd.fd = fd; pfd.events = POLLIN | POLLPRI | POLLERR | POLLHUP | POLLNVAL; /* ... but not POLLOUT, you may notice. */