changeset 2122:1ac6aed892ee

Migrate some EINTR support from hpi_bsd.hpp. accept(2) and close(2) can return EINTR and need to be restarted on *BSD + OS X. ioctl(2) man pages don't say they can return EINTR, however hpi_bsd.hpp wrapped it as RESTARTABLE in socket_available() so continue to do so.
author kurt
date Mon, 31 Jan 2011 21:09:30 -0500
parents a6225ee372e5
children fb23abdd4636
files src/os/bsd/vm/os_bsd.cpp src/os/bsd/vm/os_bsd.inline.hpp
diffstat 2 files changed, 18 insertions(+), 14 deletions(-) [+]
line wrap: on
line diff
--- a/src/os/bsd/vm/os_bsd.cpp	Mon Jan 31 18:21:38 2011 -0500
+++ b/src/os/bsd/vm/os_bsd.cpp	Mon Jan 31 21:09:30 2011 -0500
@@ -116,14 +116,13 @@
 #endif
 # include <sys/ipc.h>
 # include <sys/shm.h>
+#ifndef __APPLE__
+# include <link.h>
+#endif
 # include <stdint.h>
 # include <inttypes.h>
 # include <sys/ioctl.h>
 
-#ifndef __APPLE__
-# include <link.h>
-#endif
-
 #if defined(__FreeBSD__) || defined(__NetBSD__)
 # include <elf.h>
 #endif
@@ -4720,12 +4719,17 @@
 }
 
 int os::socket_available(int fd, jint *pbytes) {
-  // Bsd doc says EINTR not returned, unlike Solaris
-  int ret = ::ioctl(fd, FIONREAD, pbytes);
-
-  //%% note ioctl can return 0 when successful, JVM_SocketAvailable
-  // is expected to return 0 on failure and 1 on success to the jdk.
-  return (ret < 0) ? 0 : 1;
+   if (fd < 0)
+     return OS_OK;
+
+   int ret;
+
+   RESTARTABLE(::ioctl(fd, FIONREAD, pbytes), ret);
+
+   //%% note ioctl can return 0 when successful, JVM_SocketAvailable
+   // is expected to return 0 on failure and 1 on success to the jdk.
+
+   return (ret == OS_ERR) ? 0 : 1;
 }
 
 // Map a block of memory.
--- a/src/os/bsd/vm/os_bsd.inline.hpp	Mon Jan 31 18:21:38 2011 -0500
+++ b/src/os/bsd/vm/os_bsd.inline.hpp	Mon Jan 31 21:09:30 2011 -0500
@@ -191,11 +191,11 @@
 }
 
 inline int os::close(int fd) {
-  return ::close(fd);
+  RESTARTABLE_RETURN_INT(::close(fd));
 }
 
 inline int os::socket_close(int fd) {
-  return ::close(fd);
+  RESTARTABLE_RETURN_INT(::close(fd));
 }
 
 inline int os::socket(int domain, int type, int protocol) {
@@ -260,9 +260,9 @@
   // fetch it's value, this cast is safe for now. The java.net group
   // may need and want to change this interface someday if socklen_t goes
   // to 64 bits on some platform that we support.
-  // Bsd doc says this can't return EINTR, unlike accept() on Solaris
 
-  return ::accept(fd, him, (socklen_t *)len);
+  // At least OpenBSD and FreeBSD can return EINTR from accept.
+  RESTARTABLE_RETURN_INT(::accept(fd, him, (socklen_t *)len));
 }
 
 inline int os::recvfrom(int fd, char *buf, int nBytes, int flags,