commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mt...@apache.org
Subject svn commit: r819640 - /commons/sandbox/runtime/trunk/src/main/native/os/unix/fsysio.c
Date Mon, 28 Sep 2009 16:50:27 GMT
Author: mturk
Date: Mon Sep 28 16:50:26 2009
New Revision: 819640

URL: http://svn.apache.org/viewvc?rev=819640&view=rev
Log:
Port APR wait_for_io_or_timeout

Modified:
    commons/sandbox/runtime/trunk/src/main/native/os/unix/fsysio.c

Modified: commons/sandbox/runtime/trunk/src/main/native/os/unix/fsysio.c
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/os/unix/fsysio.c?rev=819640&r1=819639&r2=819640&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/os/unix/fsysio.c (original)
+++ commons/sandbox/runtime/trunk/src/main/native/os/unix/fsysio.c Mon Sep 28 16:50:26 2009
@@ -240,6 +240,23 @@
     return fdo;
 }
 
+static int wait_for_io_or_timeout(acr_file_t *f, int for_read)
+{
+    int rc, timeout = (int)(f->timeout / 1000);
+    f->ppoll.fd     = f->fd;
+    f->ppoll.events = for_read ? POLLIN : POLLOUT;
+
+    do {
+        rc = poll(&f->ppoll, 1, timeout);
+    } while (rc == -1 && errno == EINTR);
+    if (rc == 0)
+        return ACR_TIMEUP;
+    else if (rc > 0)
+        return ACR_SUCCESS;
+    else
+        return errno;
+}
+
 ACR_IO_EXPORT_DECLARE(jint, FileSystemProvider, read0)(ACR_JNISTDARGS,
                                                        jint file)
 {
@@ -258,7 +275,14 @@
     rd = r_read(f->fd, &c, 1);
     if (rd == -1 && (errno == EAGAIN || errno == EWOULDBLOCK) &&
         f->timeout != 0) {
-
+        int rc;
+        if ((rc = wait_for_io_or_timeout(f, 1))) {
+            f->err = rc;
+            return rc == ACR_TIMEUP ? 0 : -1;
+        }
+        else {
+            rd = r_read(f->fd, &c, 1);
+        }
     }
     if (rd == -1)
         f->err = ACR_GET_OS_ERROR();



Mime
View raw message