commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mt...@apache.org
Subject svn commit: r819851 - /commons/sandbox/runtime/trunk/src/main/native/os/unix/fsysio.c
Date Tue, 29 Sep 2009 07:50:31 GMT
Author: mturk
Date: Tue Sep 29 07:50:31 2009
New Revision: 819851

URL: http://svn.apache.org/viewvc?rev=819851&view=rev
Log:
Implement full write methods

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=819851&r1=819850&r2=819851&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 Tue Sep 29 07:50:31 2009
@@ -838,6 +838,8 @@
                                                         jint len)
 {
     jbyte  *bb;
+    size_t  po = (size_t)off;
+    size_t  cs = (size_t)len;
     ssize_t wr;
     acr_file_t *f = (acr_file_t *)ACR_IOH_FDATA(file);
 
@@ -853,7 +855,7 @@
     if (!bb) {
         return -1;
     }
-    wr = r_write(f->fd, bb + (size_t)off, (size_t)len);
+    wr = r_write(f->fd, bb + po, cs);
     if (wr == -1 && (errno == EAGAIN || errno == EWOULDBLOCK) &&
         f->timeout != 0) {
         int rc;
@@ -863,7 +865,7 @@
             return rc == ACR_TIMEUP ? 0 : -1;
         }
         else {
-            wr = r_write(f->fd, bb + (size_t)off, (size_t)len);
+            wr = r_write(f->fd, bb + po, cs);
         }
     }
     if (wr == -1) {
@@ -871,7 +873,7 @@
         if (ACR_STATUS_IS_EAGAIN(f->err))
             wr = 0;
     }
-    else if (wr == 1)
+    else if (wr > 0)
         f->err = 0;
    (*_E)->ReleaseByteArrayElements(_E, buf, bb, JNI_ABORT);
     return (jint)wr;
@@ -924,7 +926,7 @@
         if (ACR_STATUS_IS_EAGAIN(f->err))
             wr = 0;
     }
-    else if (wr == 1)
+    else if (wr > 0)
         f->err = 0;
     return (jint)wr;
 }
@@ -981,7 +983,7 @@
         if (ACR_STATUS_IS_EAGAIN(f->err))
             wr = 0;
     }
-    else if (wr == 1)
+    else if (wr > 0)
         f->err = 0;
     return (jint)wr;
 }
@@ -1067,7 +1069,7 @@
         if (ACR_STATUS_IS_EAGAIN(f->err))
             wr = 0;
     }
-    else if (wr == 1)
+    else if (wr > 0)
         f->err = 0;
     for (i = 0; i < cs; i++) {
         (*_E)->ReleaseByteArrayElements(_E, boa[i], iov[i].iov_base, JNI_ABORT);
@@ -1143,9 +1145,185 @@
         if (ACR_STATUS_IS_EAGAIN(f->err))
             wr = 0;
     }
-    else if (wr == 1)
+    else if (wr > 0)
         f->err = 0;
     if (iov != onstack)
         x_free(iov);
     return (jint)wr;
 }
+
+ACR_IO_EXPORT_DECLARE(jint, FileSystemProvider, fullw0)(ACR_JNISTDARGS,
+                                                        jint file,
+                                                        jbyteArray buf,
+                                                        jint off,
+                                                        jint len)
+{
+    jbyte  *bb;
+    jbyte  *wb;
+    size_t  po = (size_t)off;
+    ssize_t cs = (ssize_t)len;
+    ssize_t wt = 0;
+    ssize_t wr;
+    acr_file_t *f = (acr_file_t *)ACR_IOH_FDATA(file);
+
+    if (ACR_IOH_FTYPE(file) != ACR_DT_FILE) {
+        ACR_THROW_IO_IF_ERR(ACR_EFTYPE);
+        return -1;
+    }
+    if (IS_INVALID_HANDLE(f)) {
+        ACR_THROW_IO_IF_ERR(ACR_EBADF);
+        return -1;
+    }
+    bb = (*_E)->GetByteArrayElements(_E, buf, NULL);
+    if (!bb) {
+        return -1;
+    }
+    wb = bb + po;
+    f->err = 0;
+    do {
+        wr = r_write(f->fd, wb, cs);
+        if (wr == -1 && (errno == EAGAIN || errno == EWOULDBLOCK) &&
+            f->timeout != 0) {
+            int rc;
+            if ((rc = wait_for_io_or_timeout(f, 0))) {
+                f->err = rc;
+                if (rc != ACR_TIMEUP) {
+                    break;
+                }
+            }
+            else {
+                wr = r_write(f->fd, wb, cs);
+            }
+        }
+        if (wr > 0) {
+            wb += wr;
+            cs -= wr;
+            wt += wr;
+        }
+    } while (wr >= 0 && cs > 0);
+    if (wt == 0)
+        f->err = ACR_GET_OS_ERROR();
+   (*_E)->ReleaseByteArrayElements(_E, buf, bb, JNI_ABORT);
+    return (jint)wt;
+}
+
+ACR_IO_EXPORT_DECLARE(jint, FileSystemProvider, fullw1)(ACR_JNISTDARGS,
+                                                        jint file,
+                                                        jobject ptr,
+                                                        jlong off,
+                                                        jlong len)
+{
+    size_t  pl;
+    size_t  po = (size_t)off;
+    ssize_t cs = (ssize_t)len;
+    jbyte  *pb;
+    ssize_t wr;
+    ssize_t wt = 0;
+    acr_file_t *f = (acr_file_t *)ACR_IOH_FDATA(file);
+
+    if (ACR_IOH_FTYPE(file) != ACR_DT_FILE) {
+        ACR_THROW_IO_IF_ERR(ACR_EFTYPE);
+        return -1;
+    }
+    if (IS_INVALID_HANDLE(f)) {
+        ACR_THROW_IO_IF_ERR(ACR_EBADF);
+        return -1;
+    }
+    pb = (jbyte *)ACR_PointerGet(_E, ptr, &pl);
+    if (!pb) {
+        ACR_ThrowException(_E, THROW_NMARK, ACR_EX_ENULL, 0);
+        return -1;
+    }
+    if ((po + cs) > pl) {
+        ACR_ThrowException(_E, THROW_NMARK, ACR_EX_EINDEX, 0);
+        return -1;
+    }
+    pb = pb + po;
+    f->err = 0;
+    do {
+        wr = r_write(f->fd, pb, cs);
+        if (wr == -1 && (errno == EAGAIN || errno == EWOULDBLOCK) &&
+            f->timeout != 0) {
+            int rc;
+            if ((rc = wait_for_io_or_timeout(f, 0))) {
+                f->err = rc;
+                if (rc != ACR_TIMEUP)
+                    break;
+            }
+            else {
+                wr = r_write(f->fd, pb, cs);
+            }
+        }
+        if (wr > 0) {
+            pb += wr;
+            cs -= wr;
+            wt += wr;
+        }
+    } while (wr >= 0 && cs > 0);
+    if (wt == 0)
+        f->err = ACR_GET_OS_ERROR();
+    return (jint)wr;
+}
+
+ACR_IO_EXPORT_DECLARE(jint, FileSystemProvider, fullw2)(ACR_JNISTDARGS,
+                                                        jint file,
+                                                        jobject dbb,
+                                                        jlong off,
+                                                        jlong len)
+{
+#if defined(_DEBUG)
+    size_t  pl;
+#endif
+    size_t  po = (size_t)off;
+    ssize_t cs = (ssize_t)len;
+    jbyte  *pb;
+    ssize_t wr;
+    ssize_t wt = 0;
+    acr_file_t *f = (acr_file_t *)ACR_IOH_FDATA(file);
+
+    if (ACR_IOH_FTYPE(file) != ACR_DT_FILE) {
+        ACR_THROW_IO_IF_ERR(ACR_EFTYPE);
+        return -1;
+    }
+    if (IS_INVALID_HANDLE(f)) {
+        ACR_THROW_IO_IF_ERR(ACR_EBADF);
+        return -1;
+    }
+    pb = (jbyte *)(*_E)->GetDirectBufferAddress(_E, dbb);
+    if (!pb) {
+        ACR_ThrowException(_E, THROW_NMARK, ACR_EX_ENULL, 0);
+        return -1;
+    }
+#if defined(_DEBUG)
+    pl = (size_t)(*_E)->GetDirectBufferCapacity(_E, dbb);
+    if ((po + cs) > pl) {
+        ACR_ThrowException(_E, THROW_NMARK, ACR_EX_EINDEX, 0);
+        return -1;
+    }
+#endif
+    pb = pb + po;
+    f->err = 0;
+    do {
+        wr = r_write(f->fd, pb, cs);
+        if (wr == -1 && (errno == EAGAIN || errno == EWOULDBLOCK) &&
+            f->timeout != 0) {
+            int rc;
+            if ((rc = wait_for_io_or_timeout(f, 0))) {
+                f->err = rc;
+                if (rc != ACR_TIMEUP)
+                    break;
+            }
+            else {
+                wr = r_write(f->fd, pb, cs);
+            }
+        }
+        if (wr > 0) {
+            pb += wr;
+            cs -= wr;
+            wt += wr;
+        }
+    } while (wr >= 0 && cs > 0);
+    if (wt == 0)
+        f->err = ACR_GET_OS_ERROR();
+    return (jint)wr;
+}



Mime
View raw message