]> git.ipfire.org Git - thirdparty/valgrind.git/commitdiff
Merge patch from JeremyF:
authorJulian Seward <jseward@acm.org>
Sat, 16 Nov 2002 11:04:18 +0000 (11:04 +0000)
committerJulian Seward <jseward@acm.org>
Sat, 16 Nov 2002 11:04:18 +0000 (11:04 +0000)
43-nonblock-readwritev

Nonblocking readv/writev.

git-svn-id: svn://svn.valgrind.org/valgrind/trunk@1319

coregrind/arch/x86-linux/vg_libpthread.c
coregrind/vg_intercept.c
coregrind/vg_libpthread.c

index 600d19842f539e90d2afad24c2a2cf52d496e0c4..cbc8fadb2246ba87f02060c8ac8e1ad0ada32e88 100644 (file)
@@ -1994,6 +1994,21 @@ int VGL_(recv)(int s, void *buf, size_t len, int flags)
    return __libc_recv(s, buf, len, flags);
 }
 
+int VGL_(readv)(int fd, const struct iovec *iov, int count)
+{
+   __my_pthread_testcancel();
+   wait_for_fd_to_be_readable_or_erring(fd);
+   __my_pthread_testcancel();
+   return my_do_syscall3(__NR_readv, fd, (unsigned)iov, count);
+}
+
+int VGL_(writev)(int fd, struct iovec *iov, int count)
+{
+   __my_pthread_testcancel();
+   wait_for_fd_to_be_writable_or_erring(fd);
+   __my_pthread_testcancel();
+   return my_do_syscall3(__NR_writev, fd, (unsigned)iov, count);
+}
 
 extern
 pid_t __libc_waitpid(pid_t pid, int *status, int options);
@@ -2666,6 +2681,25 @@ static void wait_for_fd_to_be_readable_or_erring ( int fd )
    (void)poll(&pfd, 1, -1 /* forever */);
 }
 
+static void wait_for_fd_to_be_writable_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 = POLLOUT | POLLERR | POLLHUP | POLLNVAL;
+   pfd.revents = 0;
+   (void)poll(&pfd, 1, -1 /* forever */);
+}
 
 /* ---------------------------------------------------------------------
    Hacky implementation of semaphores.
index 402a17b6b45e2532ef3b4bda4d3815447d9f9404..f97ad3710b7b784b87a1f96012a50ff6c2a10305 100644 (file)
@@ -211,3 +211,33 @@ int select ( int n,
 }
 
 strong_alias(select, __select)
+
+/* -------------------------------- readv -------------------------------- */
+
+#include <sys/uio.h>
+
+WEAK int VGL_(readv)(int fd, const struct iovec *iov, int count)
+{
+   return my_do_syscall3(__NR_readv, fd, (unsigned)iov, count);
+}
+
+int readv (int fd, const struct iovec *iov, int count)
+{
+   return VGL_(readv)(fd, iov, count);
+}
+
+strong_alias(readv, __readv)
+
+/* -------------------------------- writev -------------------------------- */
+
+WEAK int VGL_(writev)(int fd, const struct iovec *iov, int count)
+{
+   return my_do_syscall3(__NR_writev, fd, (unsigned)iov, count);
+}
+
+int writev (int fd, const struct iovec *iov, int count)
+{
+   return VGL_(writev)(fd, iov, count);
+}
+
+strong_alias(writev, __writev)
index 600d19842f539e90d2afad24c2a2cf52d496e0c4..cbc8fadb2246ba87f02060c8ac8e1ad0ada32e88 100644 (file)
@@ -1994,6 +1994,21 @@ int VGL_(recv)(int s, void *buf, size_t len, int flags)
    return __libc_recv(s, buf, len, flags);
 }
 
+int VGL_(readv)(int fd, const struct iovec *iov, int count)
+{
+   __my_pthread_testcancel();
+   wait_for_fd_to_be_readable_or_erring(fd);
+   __my_pthread_testcancel();
+   return my_do_syscall3(__NR_readv, fd, (unsigned)iov, count);
+}
+
+int VGL_(writev)(int fd, struct iovec *iov, int count)
+{
+   __my_pthread_testcancel();
+   wait_for_fd_to_be_writable_or_erring(fd);
+   __my_pthread_testcancel();
+   return my_do_syscall3(__NR_writev, fd, (unsigned)iov, count);
+}
 
 extern
 pid_t __libc_waitpid(pid_t pid, int *status, int options);
@@ -2666,6 +2681,25 @@ static void wait_for_fd_to_be_readable_or_erring ( int fd )
    (void)poll(&pfd, 1, -1 /* forever */);
 }
 
+static void wait_for_fd_to_be_writable_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 = POLLOUT | POLLERR | POLLHUP | POLLNVAL;
+   pfd.revents = 0;
+   (void)poll(&pfd, 1, -1 /* forever */);
+}
 
 /* ---------------------------------------------------------------------
    Hacky implementation of semaphores.