commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mt...@apache.org
Subject svn commit: r820696 - /commons/sandbox/runtime/trunk/src/main/native/os/unix/fsysio.c
Date Thu, 01 Oct 2009 15:52:54 GMT
Author: mturk
Date: Thu Oct  1 15:52:54 2009
New Revision: 820696

URL: http://svn.apache.org/viewvc?rev=820696&view=rev
Log:
Use infinite timeout if not set for full-write routines

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=820696&r1=820695&r2=820696&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 Thu Oct  1 15:52:54 2009
@@ -277,6 +277,23 @@
         return errno;
 }
 
+static int wait_for_io(acr_file_t *f, int for_read)
+{
+    int rc, timeout = f->timeout ? (int)(f->timeout / 1000) : -1;
+    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, FileSystem, lock0)(ACR_JNISTDARGS,
                                                jint file,
                                                jint type)
@@ -1260,9 +1277,8 @@
     wb = bb + po;
     do {
         wr = r_write(f->fd, wb, cs);
-        if (wr == -1 && (errno == EAGAIN || errno == EWOULDBLOCK) &&
-            f->timeout != 0) {
-            if ((rc = wait_for_io_or_timeout(f, 0)) == 0) {
+        if (wr == -1 && (errno == EAGAIN || errno == EWOULDBLOCK)) {
+            if ((rc = wait_for_io(f, 0)) == 0) {
                 wr = r_write(f->fd, wb, cs);
             }
             else if (rc != ACR_TIMEUP)
@@ -1332,9 +1348,8 @@
     pb = pb + po;
     do {
         wr = r_write(f->fd, pb, cs);
-        if (wr == -1 && (errno == EAGAIN || errno == EWOULDBLOCK) &&
-            f->timeout != 0) {
-            if ((rc = wait_for_io_or_timeout(f, 0)) == 0) {
+        if (wr == -1 && (errno == EAGAIN || errno == EWOULDBLOCK)) {
+            if ((rc = wait_for_io(f, 0)) == 0) {
                 wr = r_write(f->fd, pb, cs);
             }
             else if (rc != ACR_TIMEUP)
@@ -1408,9 +1423,8 @@
     pb = pb + po;
     do {
         wr = r_write(f->fd, pb, cs);
-        if (wr == -1 && (errno == EAGAIN || errno == EWOULDBLOCK) &&
-            f->timeout != 0) {
-            if ((rc = wait_for_io_or_timeout(f, 0)) == 0) {
+        if (wr == -1 && (errno == EAGAIN || errno == EWOULDBLOCK)) {
+            if ((rc = wait_for_io(f, 0)) == 0) {
                 wr = r_write(f->fd, pb, cs);
             }
             else if (rc != ACR_TIMEUP)



Mime
View raw message