commons-commits mailing list archives

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

URL: http://svn.apache.org/viewvc?rev=820547&view=rev
Log:
Use provided errno from wait function

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=820547&r1=820546&r2=820547&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 07:03:12 2009
@@ -550,6 +550,7 @@
 {
     unsigned char c;
     ssize_t rd;
+    int     rc = 0;
     acr_file_t *f = (acr_file_t *)ACR_IOH_FDATA(file);
 
     if (ACR_IOH_FTYPE(file) != ACR_DT_FILE) {
@@ -566,30 +567,29 @@
     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 {
+        if ((rc = wait_for_io_or_timeout(f, 1)) == 0) {
             rd = r_read(f->fd, &c, 1);
         }
     }
     if (rd == -1) {
-        f->err = ACR_GET_OS_ERROR();
-        if (!ACR_STATUS_IS_EAGAIN(f->err)) {
-            /* Throw only if not EAGAIN
-             */
-            ACR_THROW_IO_IF_ERR(f->err);
-        }
+        rc = rc ? rc : ACR_GET_OS_ERROR();
+        if (ACR_STATUS_IS_EAGAIN(rc))
+            rc = ACR_TIMEUP;
     }
-    else if (rd == 0) {
+    if (rd == 0) {
         f->err = 0;
         f->eof = 1;
+        return  -1;
     }
-    else if (rd == 1) {
-        f->err = 0;
-        return c;
+    if (rd > 0)
+        return (jint)rd;
+    switch (f->err = rc) {
+        case 0:
+        case ACR_TIMEUP:
+        break;
+        default:
+            ACR_THROW_IO_IF_ERR(rc);
+        break;
     }
     return -1;
 }
@@ -606,6 +606,7 @@
     size_t  cs = (size_t)len;
     jbyte   onstack[ACR_PBUFF_SIZ];
     ssize_t rd;
+    int     rc = 0;
     acr_file_t *f = (acr_file_t *)ACR_IOH_FDATA(file);
 
     if (ACR_IOH_FTYPE(file) != ACR_DT_FILE) {
@@ -637,32 +638,16 @@
     rd = r_read(f->fd, bb, cs);
     if (rd == -1 && (errno == EAGAIN || errno == EWOULDBLOCK) &&
         f->timeout != 0) {
-        int rc;
-        if ((rc = wait_for_io_or_timeout(f, 1))) {
-            f->err = rc;
-            if (bb != onstack) {
-                if (bc)
-                    (*_E)->ReleaseByteArrayElements(_E, buf, bc, JNI_ABORT);
-                else
-                    x_free(bb);
-            }
-            return rc == ACR_TIMEUP ? 0 : -1;
-        }
-        else {
+        if ((rc = wait_for_io_or_timeout(f, 1)) == 0) {
             rd = r_read(f->fd, bb, cs);
         }
     }
     if (rd == -1) {
-        f->err = ACR_GET_OS_ERROR();
-        if (ACR_STATUS_IS_EAGAIN(f->err))
-            rd = 0;
-    }
-    else if (rd == 0) {
-        f->err = 0;
-        f->eof = 1;
+        rc = rc ? rc : ACR_GET_OS_ERROR();
+        if (ACR_STATUS_IS_EAGAIN(rc))
+            rc = ACR_TIMEUP;
     }
-    else if (rd > 0) {
-        f->err = 0;
+    if (rd > 0) {
         if (bc) {
             (*_E)->ReleaseByteArrayElements(_E, buf, bc, 0);
             return (jint)rd;
@@ -677,7 +662,21 @@
         else
             x_free(bb);
     }
-    return (jint)rd;
+    if (rd > 0)
+        return (jint)rd;
+    switch (f->err = rc) {
+        case 0:
+            f->eof = 1;
+        break;
+        case ACR_TIMEUP:
+            return 0;
+        break;
+        default:
+            ACR_THROW_IO_IF_ERR(rc);
+        break;
+    }
+    return -1;
+
 }
 
 ACR_IO_EXPORT_DECLARE(jint, FileSystem, read2)(ACR_JNISTDARGS,
@@ -691,6 +690,7 @@
     size_t  cs = (size_t)len;
     jbyte  *pb;
     ssize_t rd;
+    int     rc = 0;
     acr_file_t *f = (acr_file_t *)ACR_IOH_FDATA(file);
 
     if (ACR_IOH_FTYPE(file) != ACR_DT_FILE) {
@@ -716,28 +716,30 @@
     rd = r_read(f->fd, pb + po, cs);
     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 {
+        if ((rc = wait_for_io_or_timeout(f, 1)) == 0) {
             rd = r_read(f->fd, pb + po, cs);
         }
     }
     if (rd == -1) {
-        f->err = ACR_GET_OS_ERROR();
-        if (ACR_STATUS_IS_EAGAIN(f->err))
-            rd = 0;
-    }
-    else if (rd == 0) {
-        f->err = 0;
-        f->eof = 1;
+        rc = rc ? rc : ACR_GET_OS_ERROR();
+        if (ACR_STATUS_IS_EAGAIN(rc))
+            rc = ACR_TIMEUP;
     }
-    else if (rd > 0) {
-        f->err = 0;
+    if (rd > 0)
+        return (jint)rd;
+
+    switch (f->err = rc) {
+        case 0:
+            f->eof = 1;
+        break;
+        case ACR_TIMEUP:
+            return 0;
+        break;
+        default:
+            ACR_THROW_IO_IF_ERR(rc);
+        break;
     }
-    return (jint)rd;
+    return -1;
 }
 
 ACR_IO_EXPORT_DECLARE(jint, FileSystem, read3)(ACR_JNISTDARGS,
@@ -753,6 +755,7 @@
     size_t  cs = (size_t)len;
     jbyte  *pb;
     ssize_t rd;
+    int     rc = 0;
     acr_file_t *f = (acr_file_t *)ACR_IOH_FDATA(file);
 
     if (ACR_IOH_FTYPE(file) != ACR_DT_FILE) {
@@ -781,28 +784,30 @@
     rd = r_read(f->fd, pb + po, cs);
     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 {
+        if ((rc = wait_for_io_or_timeout(f, 1)) == 0) {
             rd = r_read(f->fd, pb + po, cs);
         }
     }
     if (rd == -1) {
-        f->err = ACR_GET_OS_ERROR();
-        if (ACR_STATUS_IS_EAGAIN(f->err))
-            rd = 0;
-    }
-    else if (rd == 0) {
-        f->err = 0;
-        f->eof = 1;
+        rc = rc ? rc : ACR_GET_OS_ERROR();
+        if (ACR_STATUS_IS_EAGAIN(rc))
+            rc = ACR_TIMEUP;
     }
-    else if (rd > 0) {
-        f->err = 0;
+    if (rd > 0)
+        return (jint)rd;
+
+    switch (f->err = rc) {
+        case 0:
+            f->eof = 1;
+        break;
+        case ACR_TIMEUP:
+            return 0;
+        break;
+        default:
+            ACR_THROW_IO_IF_ERR(rc);
+        break;
     }
-    return (jint)rd;
+    return -1;
 }
 
 ACR_IO_EXPORT_DECLARE(jint, FileSystem, write0)(ACR_JNISTDARGS,
@@ -830,14 +835,14 @@
         }
     }
     if (wr < 0) {
-        rc = ACR_GET_OS_ERROR();
+        rc = rc ? rc : ACR_GET_OS_ERROR();
         if (ACR_STATUS_IS_EAGAIN(rc))
             rc = ACR_TIMEUP;
     }
+    if (wr > 0)
+        return (jint)wr;
     switch (f->err = rc) {
         case 0:
-            return (jint)wr;
-        break;
         case ACR_TIMEUP:
             return 0;
         break;
@@ -882,15 +887,15 @@
         }
     }
     if (wr < 0) {
-        rc = ACR_GET_OS_ERROR();
+        rc = rc ? rc : ACR_GET_OS_ERROR();
         if (ACR_STATUS_IS_EAGAIN(rc))
             rc = ACR_TIMEUP;
     }
    (*_E)->ReleaseByteArrayElements(_E, buf, bb, JNI_ABORT);
+    if (wr > 0)
+        return (jint)wr;
     switch (f->err = rc) {
         case 0:
-            return (jint)wr;
-        break;
         case ACR_TIMEUP:
             return 0;
         break;
@@ -940,14 +945,14 @@
         }
     }
     if (wr < 0) {
-        rc = ACR_GET_OS_ERROR();
+        rc = rc ? rc : ACR_GET_OS_ERROR();
         if (ACR_STATUS_IS_EAGAIN(rc))
             rc = ACR_TIMEUP;
     }
+    if (wr > 0)
+        return (jint)wr;
     switch (f->err = rc) {
         case 0:
-            return (jint)wr;
-        break;
         case ACR_TIMEUP:
             return 0;
         break;
@@ -1002,14 +1007,14 @@
         }
     }
     if (wr < 0) {
-        rc = ACR_GET_OS_ERROR();
+        rc = rc ? rc : ACR_GET_OS_ERROR();
         if (ACR_STATUS_IS_EAGAIN(rc))
             rc = ACR_TIMEUP;
     }
+    if (wr > 0)
+        return (jint)wr;
     switch (f->err = rc) {
         case 0:
-            return (jint)wr;
-        break;
         case ACR_TIMEUP:
             return 0;
         break;
@@ -1085,7 +1090,7 @@
         }
     }
     if (wr < 0) {
-        rc = ACR_GET_OS_ERROR();
+        rc = rc ? rc : ACR_GET_OS_ERROR();
         if (ACR_STATUS_IS_EAGAIN(rc))
             rc = ACR_TIMEUP;
     }
@@ -1096,10 +1101,10 @@
         x_free(iov);
         x_free(boa);
     }
+    if (wr > 0)
+        return (jint)wr;
     switch (f->err = rc) {
         case 0:
-            return (jint)wr;
-        break;
         case ACR_TIMEUP:
             return 0;
         break;
@@ -1164,16 +1169,16 @@
         }
     }
     if (wr < 0) {
-        rc = ACR_GET_OS_ERROR();
+        rc = rc ? rc : ACR_GET_OS_ERROR();
         if (ACR_STATUS_IS_EAGAIN(rc))
             rc = ACR_TIMEUP;
     }
     if (iov != onstack)
         x_free(iov);
+    if (wr > 0)
+        return (jint)wr;
     switch (f->err = rc) {
         case 0:
-            return (jint)wr;
-        break;
         case ACR_TIMEUP:
             return 0;
         break;
@@ -1229,15 +1234,15 @@
         }
     } while (wr >= 0 && cs > 0);
     if (wt == 0) {
-        rc = ACR_GET_OS_ERROR();
+        rc = rc ? rc : ACR_GET_OS_ERROR();
         if (ACR_STATUS_IS_EAGAIN(rc))
             rc = ACR_TIMEUP;
     }
    (*_E)->ReleaseByteArrayElements(_E, buf, bb, JNI_ABORT);
+    if (wt > 0)
+        return (jint)wt;
     switch (f->err = rc) {
         case 0:
-            return (jint)wt;
-        break;
         case ACR_TIMEUP:
             return 0;
         break;
@@ -1298,14 +1303,14 @@
         }
     } while (wr >= 0 && cs > 0);
     if (wt == 0) {
-        rc = ACR_GET_OS_ERROR();
+        rc = rc ? rc : ACR_GET_OS_ERROR();
         if (ACR_STATUS_IS_EAGAIN(rc))
             rc = ACR_TIMEUP;
     }
+    if (wt > 0)
+        return (jint)wt;
     switch (f->err = rc) {
         case 0:
-            return (jint)wt;
-        break;
         case ACR_TIMEUP:
             return 0;
         break;
@@ -1371,14 +1376,14 @@
         }
     } while (wr >= 0 && cs > 0);
     if (wt == 0) {
-        rc = ACR_GET_OS_ERROR();
+        rc = rc ? rc : ACR_GET_OS_ERROR();
         if (ACR_STATUS_IS_EAGAIN(rc))
             rc = ACR_TIMEUP;
     }
+    if (wt > 0)
+        return (jint)wt;
     switch (f->err = rc) {
         case 0:
-            return (jint)wt;
-        break;
         case ACR_TIMEUP:
             return 0;
         break;



Mime
View raw message