commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mt...@apache.org
Subject svn commit: r883810 [1/3] - in /commons/sandbox/runtime/trunk/src/main/native: Makefile.in Makefile.msc.in include/arch/unix/acr_arch.h os/unix/fsysio.c os/unix/fsysrw.c os/win32/fsysio.c os/win32/fsysrw.c
Date Tue, 24 Nov 2009 18:47:16 GMT
Author: mturk
Date: Tue Nov 24 18:47:13 2009
New Revision: 883810

URL: http://svn.apache.org/viewvc?rev=883810&view=rev
Log:
Split fsysrw.c files

Added:
    commons/sandbox/runtime/trunk/src/main/native/os/unix/fsysrw.c   (with props)
    commons/sandbox/runtime/trunk/src/main/native/os/win32/fsysrw.c   (with props)
Modified:
    commons/sandbox/runtime/trunk/src/main/native/Makefile.in
    commons/sandbox/runtime/trunk/src/main/native/Makefile.msc.in
    commons/sandbox/runtime/trunk/src/main/native/include/arch/unix/acr_arch.h
    commons/sandbox/runtime/trunk/src/main/native/os/unix/fsysio.c
    commons/sandbox/runtime/trunk/src/main/native/os/win32/fsysio.c

Modified: commons/sandbox/runtime/trunk/src/main/native/Makefile.in
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/Makefile.in?rev=883810&r1=883809&r2=883810&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/Makefile.in (original)
+++ commons/sandbox/runtime/trunk/src/main/native/Makefile.in Tue Nov 24 18:47:13 2009
@@ -128,6 +128,7 @@
 	$(SRCDIR)/os/unix/file.$(OBJ) \
 	$(SRCDIR)/os/unix/finfo.$(OBJ) \
 	$(SRCDIR)/os/unix/fsysio.$(OBJ) \
+	$(SRCDIR)/os/unix/fsysrw.$(OBJ) \
 	$(SRCDIR)/os/unix/main.$(OBJ) \
 	$(SRCDIR)/os/unix/ios.$(OBJ) \
 	$(SRCDIR)/os/unix/group.$(OBJ) \
@@ -167,6 +168,7 @@
 	$(SRCDIR)/os/unix/file.$(OBJ) \
 	$(SRCDIR)/os/unix/finfo.$(OBJ) \
 	$(SRCDIR)/os/unix/fsysio.$(OBJ) \
+	$(SRCDIR)/os/unix/fsysrw.$(OBJ) \
 	$(SRCDIR)/os/unix/main.$(OBJ) \
 	$(SRCDIR)/os/unix/ios.$(OBJ) \
 	$(SRCDIR)/os/unix/group.$(OBJ) \
@@ -203,6 +205,7 @@
 	$(SRCDIR)/os/unix/file.$(OBJ) \
 	$(SRCDIR)/os/unix/finfo.$(OBJ) \
 	$(SRCDIR)/os/unix/fsysio.$(OBJ) \
+	$(SRCDIR)/os/unix/fsysrw.$(OBJ) \
 	$(SRCDIR)/os/unix/main.$(OBJ) \
 	$(SRCDIR)/os/unix/ios.$(OBJ) \
 	$(SRCDIR)/os/unix/group.$(OBJ) \
@@ -240,6 +243,7 @@
 	$(SRCDIR)/os/unix/file.$(OBJ) \
 	$(SRCDIR)/os/unix/finfo.$(OBJ) \
 	$(SRCDIR)/os/unix/fsysio.$(OBJ) \
+	$(SRCDIR)/os/unix/fsysrw.$(OBJ) \
 	$(SRCDIR)/os/unix/main.$(OBJ) \
 	$(SRCDIR)/os/unix/ios.$(OBJ) \
 	$(SRCDIR)/os/unix/group.$(OBJ) \

Modified: commons/sandbox/runtime/trunk/src/main/native/Makefile.msc.in
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/Makefile.msc.in?rev=883810&r1=883809&r2=883810&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/Makefile.msc.in (original)
+++ commons/sandbox/runtime/trunk/src/main/native/Makefile.msc.in Tue Nov 24 18:47:13 2009
@@ -121,6 +121,7 @@
 	$(SRCDIR)/os/win32/file.$(OBJ) \
 	$(SRCDIR)/os/win32/finfo.$(OBJ) \
 	$(SRCDIR)/os/win32/fsysio.$(OBJ) \
+	$(SRCDIR)/os/win32/fsysrw.$(OBJ) \
 	$(SRCDIR)/os/win32/main.$(OBJ) \
 	$(SRCDIR)/os/win32/platform.$(OBJ) \
 	$(SRCDIR)/os/win32/proc.$(OBJ) \

Modified: commons/sandbox/runtime/trunk/src/main/native/include/arch/unix/acr_arch.h
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/include/arch/unix/acr_arch.h?rev=883810&r1=883809&r2=883810&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/include/arch/unix/acr_arch.h (original)
+++ commons/sandbox/runtime/trunk/src/main/native/include/arch/unix/acr_arch.h Tue Nov 24 18:47:13 2009
@@ -200,7 +200,7 @@
     ssize_t r;
     do {
         r = read(fd, buf, count);
-    } while (r < 0 && errno == EINTR);
+    } while (r == -1 && errno == EINTR);
 
     return r;
 }
@@ -211,7 +211,31 @@
     ssize_t w;
     do {
         w = write(fd, buf, count);
-    } while (w < 0 && errno == EINTR);
+    } while (w == -1 && errno == EINTR);
+
+    return w;
+}
+
+/* restartable pread() */
+static ACR_INLINE ssize_t r_pread(int fd, void *buf, size_t count,
+                                  off_t offset)
+{
+    ssize_t r;
+    do {
+        r = pread(fd, buf, count, offset);
+    } while (r == -1 && errno == EINTR);
+
+    return r;
+}
+
+/* restartable pwrite() */
+static ACR_INLINE ssize_t r_pwrite(int fd, const void *buf, size_t count,
+                                   off_t offset)
+{
+    ssize_t w;
+    do {
+        w = pwrite(fd, buf, count, offset);
+    } while (w == -1 && errno == EINTR);
 
     return w;
 }

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=883810&r1=883809&r2=883810&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 Nov 24 18:47:13 2009
@@ -389,61 +389,6 @@
     return fdo;
 }
 
-static int wait_for_io_or_timeout(acr_file_t *f, int for_read)
-{
-    int rc;
-    acr_time_t     prev, nexttime;
-    struct timeval t;
-    int    timeout  = f->timeout;
-
-    f->ppoll.fd     = f->fd;
-    f->ppoll.events = for_read ? POLLIN : POLLOUT;
-    /* Store the the current time
-     */
-    gettimeofday(&t, NULL);
-    prev = ((acr_time_t)t.tv_sec * 1000) + t.tv_usec / 1000;
-    for (;;) {
-        rc = poll(&f->ppoll, 1, timeout);
-        if (rc == -1 && errno == EINTR) {
-            if (timeout >= 0) {
-                gettimeofday(&t, NULL);
-                nexttime = ((acr_time_t)t.tv_sec * 1000) + t.tv_usec / 1000;
-                timeout -= (int)(nexttime - prev);
-                if (timeout <= 0) {
-                    rc = 0;
-                    break;
-                }
-                prev = nexttime;
-            }
-        }
-        else
-            break;
-    }
-    if (rc == 0)
-        return ACR_TIMEUP;
-    else if (rc > 0)
-        return ACR_SUCCESS;
-    else
-        return errno;
-}
-
-static int wait_for_io(acr_file_t *f, int for_read)
-{
-    int rc;
-    f->ppoll.fd     = f->fd;
-    f->ppoll.events = for_read ? POLLIN : POLLOUT;
-
-    do {
-        rc = poll(&f->ppoll, 1, -1);
-    } 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, FileSystemIo, lock0)(ACR_JNISTDARGS,
                                                  jint file,
                                                  jint type)
@@ -722,913 +667,3 @@
         return 0;
 }
 
-ACR_IO_EXPORT_DECLARE(jint, FileSystemIo, read0)(ACR_JNISTDARGS,
-                                                 jint file)
-{
-    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) {
-        ACR_THROW_EX_IF_ERR(ACR_EX_INVALID_DESC, ACR_EFTYPE);
-        return -1;
-    }
-    if (IS_INVALID_HANDLE(f)) {
-        ACR_THROW_EX_IF_ERR(ACR_EX_CLOSED_DESC, ACR_EBADF);
-        return -1;
-    }
-    if (f->eof) {
-        return -1;
-    }
-    rd = r_read(f->fd, &c, 1);
-    if (rd == -1 && (errno == EAGAIN || errno == EWOULDBLOCK) &&
-        f->timeout != 0) {
-        if ((rc = wait_for_io_or_timeout(f, 1)) == 0) {
-            rd = r_read(f->fd, &c, 1);
-        }
-    }
-    if (rd == -1) {
-        rc = rc ? rc : ACR_GET_OS_ERROR();
-        if (ACR_STATUS_IS_EAGAIN(rc))
-            rc = ACR_TIMEUP;
-    }
-    if (rd == 0) {
-        ACR_DescriptorSetErrEx(_E, f->descriptor, ACR_EOF);
-        f->eof = 1;
-        return  -1;
-    }
-    if (rd > 0)
-        return (jint)rd;
-
-    ACR_DescriptorSetErrEx(_E, f->descriptor, rc);
-    switch (rc) {
-        case 0:
-        case ACR_TIMEUP:
-            ACR_THROW_EX_IF_ERR(ACR_EX_ETIMEOUT, rc);
-        break;
-        case EBADF:
-            ACR_THROW_EX_IF_ERR(ACR_EX_ACLOSED_DESC, rc);
-        break;
-        default:
-            ACR_THROW_IO_IF_ERR(rc);
-        break;
-    }
-    return -1;
-}
-
-ACR_IO_EXPORT_DECLARE(jint, FileSystemIo, read1)(ACR_JNISTDARGS,
-                                                 jint file,
-                                                 jbyteArray buf,
-                                                 jint off,
-                                                 jint len)
-{
-    jbyte  *bb = NULL;
-    jbyte  *bc = NULL;
-    size_t  po = (size_t)off;
-    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) {
-        ACR_THROW_EX_IF_ERR(ACR_EX_INVALID_DESC, ACR_EFTYPE);
-        return -1;
-    }
-    if (IS_INVALID_HANDLE(f)) {
-        ACR_THROW_EX_IF_ERR(ACR_EX_CLOSED_DESC, ACR_EBADF);
-        return -1;
-    }
-    if (f->eof) {
-        return -1;
-    }
-    if (cs > sizeof(onstack)) {
-        if (cs > (1024 * 1024)) {
-            bc = (*_E)->GetByteArrayElements(_E, buf, NULL);
-            if (bc)
-                bb = bc + po;
-        }
-        else
-            bb = ACR_Malloc(_E, THROW_FMARK, cs);
-    }
-    else
-        bb = onstack;
-    if (!bb) {
-        /* Exception was already thrown */
-        return -1;
-    }
-    rd = r_read(f->fd, bb, cs);
-    if (rd == -1 && (errno == EAGAIN || errno == EWOULDBLOCK) &&
-        f->timeout != 0) {
-        if ((rc = wait_for_io_or_timeout(f, 1)) == 0) {
-            rd = r_read(f->fd, bb, cs);
-        }
-    }
-    if (rd == -1) {
-        rc = rc ? rc : ACR_GET_OS_ERROR();
-        if (ACR_STATUS_IS_EAGAIN(rc))
-            rc = ACR_TIMEUP;
-    }
-    if (rd > 0) {
-        if (bc) {
-            (*_E)->ReleaseByteArrayElements(_E, buf, bc, 0);
-            return (jint)rd;
-        }
-        else {
-            (*_E)->SetByteArrayRegion(_E, buf, (jsize)po, (jsize)rd, bb);
-        }
-    }
-    if (bb != onstack) {
-        if (bc)
-            (*_E)->ReleaseByteArrayElements(_E, buf, bc, JNI_ABORT);
-        else
-            x_free(bb);
-    }
-    if (rd > 0)
-        return (jint)rd;
-
-    ACR_DescriptorSetErrEx(_E, f->descriptor, rc);
-    switch (rc) {
-        case 0:
-            f->eof = 1;
-        break;
-        case ACR_TIMEUP:
-            return 0;
-        break;
-        case EBADF:
-            ACR_THROW_EX_IF_ERR(ACR_EX_ACLOSED_DESC, rc);
-        break;
-        default:
-            ACR_THROW_IO_IF_ERR(rc);
-        break;
-    }
-    return -1;
-
-}
-
-ACR_IO_EXPORT_DECLARE(jlong, FileSystemIo, read2)(ACR_JNISTDARGS,
-                                                  jint file,
-                                                  jobject ptr,
-                                                  jlong off,
-                                                  jlong len)
-{
-    size_t  pl;
-    size_t  po = (size_t)off;
-    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) {
-        ACR_THROW_EX_IF_ERR(ACR_EX_INVALID_DESC, ACR_EFTYPE);
-        return -1;
-    }
-    if (IS_INVALID_HANDLE(f)) {
-        ACR_THROW_EX_IF_ERR(ACR_EX_CLOSED_DESC, ACR_EBADF);
-        return -1;
-    }
-    if (f->eof) {
-        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;
-    }
-    rd = r_read(f->fd, pb + po, cs);
-    if (rd == -1 && (errno == EAGAIN || errno == EWOULDBLOCK) &&
-        f->timeout != 0) {
-        if ((rc = wait_for_io_or_timeout(f, 1)) == 0) {
-            rd = r_read(f->fd, pb + po, cs);
-        }
-    }
-    if (rd == -1) {
-        rc = rc ? rc : ACR_GET_OS_ERROR();
-        if (ACR_STATUS_IS_EAGAIN(rc))
-            rc = ACR_TIMEUP;
-    }
-    if (rd > 0)
-        return (jlong)rd;
-
-    ACR_DescriptorSetErrEx(_E, f->descriptor, rc);
-    switch (rc) {
-        case 0:
-            f->eof = 1;
-        break;
-        case ACR_TIMEUP:
-            return 0;
-        break;
-        case EBADF:
-            ACR_THROW_EX_IF_ERR(ACR_EX_ACLOSED_DESC, rc);
-        break;
-        default:
-            ACR_THROW_IO_IF_ERR(rc);
-        break;
-    }
-    return -1;
-}
-
-ACR_IO_EXPORT_DECLARE(jint, FileSystemIo, read3)(ACR_JNISTDARGS,
-                                                 jint file,
-                                                 jobject dbb,
-                                                 jint off,
-                                                 jint len)
-{
-#if defined(_DEBUG)
-    size_t  pl;
-#endif
-    size_t  po = (size_t)off;
-    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) {
-        ACR_THROW_EX_IF_ERR(ACR_EX_INVALID_DESC, ACR_EFTYPE);
-        return -1;
-    }
-    if (IS_INVALID_HANDLE(f)) {
-        ACR_THROW_EX_IF_ERR(ACR_EX_CLOSED_DESC, ACR_EBADF);
-        return -1;
-    }
-    if (f->eof) {
-        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
-    rd = r_read(f->fd, pb + po, cs);
-    if (rd == -1 && (errno == EAGAIN || errno == EWOULDBLOCK) &&
-        f->timeout != 0) {
-        if ((rc = wait_for_io_or_timeout(f, 1)) == 0) {
-            rd = r_read(f->fd, pb + po, cs);
-        }
-    }
-    if (rd == -1) {
-        rc = rc ? rc : ACR_GET_OS_ERROR();
-        if (ACR_STATUS_IS_EAGAIN(rc))
-            rc = ACR_TIMEUP;
-    }
-    if (rd > 0)
-        return (jint)rd;
-
-    ACR_DescriptorSetErrEx(_E, f->descriptor, rc);
-    switch (rc) {
-        case 0:
-            f->eof = 1;
-        break;
-        case ACR_TIMEUP:
-            return 0;
-        break;
-        case EBADF:
-            ACR_THROW_EX_IF_ERR(ACR_EX_ACLOSED_DESC, rc);
-        break;
-        default:
-            ACR_THROW_IO_IF_ERR(rc);
-        break;
-    }
-    return -1;
-}
-
-ACR_IO_EXPORT_DECLARE(jint, FileSystemIo, write0)(ACR_JNISTDARGS,
-                                                  jint file,
-                                                  jint b)
-{
-    unsigned char c = (unsigned char)(b & 0xFF);
-    ssize_t wr;
-    int     rc = 0;
-    acr_file_t *f = (acr_file_t *)ACR_IOH_FDATA(file);
-
-    if (ACR_IOH_FTYPE(file) != ACR_DT_FILE) {
-        ACR_THROW_EX_IF_ERR(ACR_EX_INVALID_DESC, ACR_EFTYPE);
-        return -1;
-    }
-    if (IS_INVALID_HANDLE(f)) {
-        ACR_THROW_EX_IF_ERR(ACR_EX_CLOSED_DESC, ACR_EBADF);
-        return -1;
-    }
-    wr = r_write(f->fd, &c, 1);
-    if (wr == -1 && (errno == EAGAIN || errno == EWOULDBLOCK) &&
-        f->timeout != 0) {
-        if ((rc = wait_for_io_or_timeout(f, 0)) == 0) {
-            wr = r_write(f->fd, &c, 1);
-        }
-    }
-    if (wr < 0) {
-        rc = rc ? rc : ACR_GET_OS_ERROR();
-        if (ACR_STATUS_IS_EAGAIN(rc))
-            rc = ACR_TIMEUP;
-    }
-    if (wr > 0)
-        return (jint)wr;
-
-    ACR_DescriptorSetErrEx(_E, f->descriptor, rc);
-    switch (rc) {
-        case 0:
-        case ACR_TIMEUP:
-            return 0;
-        break;
-        case EBADF:
-            ACR_THROW_EX_IF_ERR(ACR_EX_ACLOSED_DESC, rc);
-        break;
-        default:
-            ACR_THROW_IO_IF_ERR(rc);
-        break;
-    }
-    return -1;
-}
-
-ACR_IO_EXPORT_DECLARE(jint, FileSystemIo, write1)(ACR_JNISTDARGS,
-                                                  jint file,
-                                                  jbyteArray buf,
-                                                  jint off,
-                                                  jint len)
-{
-    jbyte  *bb;
-    size_t  po = (size_t)off;
-    size_t  cs = (size_t)len;
-    ssize_t wr;
-    int     rc = 0;
-    acr_file_t *f = (acr_file_t *)ACR_IOH_FDATA(file);
-
-    if (ACR_IOH_FTYPE(file) != ACR_DT_FILE) {
-        ACR_THROW_EX_IF_ERR(ACR_EX_INVALID_DESC, ACR_EFTYPE);
-        return -1;
-    }
-    if (IS_INVALID_HANDLE(f)) {
-        ACR_THROW_EX_IF_ERR(ACR_EX_CLOSED_DESC, ACR_EBADF);
-        return -1;
-    }
-    bb = (*_E)->GetByteArrayElements(_E, buf, NULL);
-    if (!bb) {
-        return -1;
-    }
-
-    wr = r_write(f->fd, bb + po, cs);
-    if (wr == -1 && (errno == EAGAIN || errno == EWOULDBLOCK) &&
-        f->timeout != 0) {
-        if ((rc = wait_for_io_or_timeout(f, 0)) == 0) {
-            wr = r_write(f->fd, bb + po, cs);
-        }
-    }
-    if (wr < 0) {
-        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;
-
-    ACR_DescriptorSetErrEx(_E, f->descriptor, rc);
-    switch (rc) {
-        case 0:
-        case ACR_TIMEUP:
-            return 0;
-        break;
-        case EBADF:
-            ACR_THROW_EX_IF_ERR(ACR_EX_ACLOSED_DESC, rc);
-        break;
-        default:
-            ACR_THROW_IO_IF_ERR(rc);
-        break;
-    }
-    return -1;
-}
-
-ACR_IO_EXPORT_DECLARE(jlong, FileSystemIo, write2)(ACR_JNISTDARGS,
-                                                   jint file,
-                                                   jobject ptr,
-                                                   jlong off,
-                                                   jlong len)
-{
-    size_t  pl;
-    size_t  po = (size_t)off;
-    size_t  cs = (size_t)len;
-    jbyte  *pb;
-    ssize_t wr;
-    int     rc = 0;
-    acr_file_t *f = (acr_file_t *)ACR_IOH_FDATA(file);
-
-    if (ACR_IOH_FTYPE(file) != ACR_DT_FILE) {
-        ACR_THROW_EX_IF_ERR(ACR_EX_INVALID_DESC, ACR_EFTYPE);
-        return -1;
-    }
-    if (IS_INVALID_HANDLE(f)) {
-        ACR_THROW_EX_IF_ERR(ACR_EX_CLOSED_DESC, 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;
-    }
-    wr = r_write(f->fd, pb + po, cs);
-    if (wr == -1 && (errno == EAGAIN || errno == EWOULDBLOCK) &&
-        f->timeout != 0) {
-        if ((rc = wait_for_io_or_timeout(f, 0)) == 0) {
-            wr = r_write(f->fd, pb + po, cs);
-        }
-    }
-    if (wr < 0) {
-        rc = rc ? rc : ACR_GET_OS_ERROR();
-        if (ACR_STATUS_IS_EAGAIN(rc))
-            rc = ACR_TIMEUP;
-    }
-    if (wr > 0)
-        return (jlong)wr;
-
-    ACR_DescriptorSetErrEx(_E, f->descriptor, rc);
-    switch (rc) {
-        case 0:
-        case ACR_TIMEUP:
-            return 0;
-        break;
-        case EBADF:
-            ACR_THROW_EX_IF_ERR(ACR_EX_ACLOSED_DESC, rc);
-        break;
-        default:
-            ACR_THROW_IO_IF_ERR(rc);
-        break;
-    }
-    return -1;
-}
-
-ACR_IO_EXPORT_DECLARE(jint, FileSystemIo, write3)(ACR_JNISTDARGS,
-                                                  jint file,
-                                                  jobject dbb,
-                                                  jlong off,
-                                                  jlong len)
-{
-#if defined(_DEBUG)
-    size_t  pl;
-#endif
-    size_t  po = (size_t)off;
-    size_t  cs = (size_t)len;
-    jbyte  *pb;
-    ssize_t wr;
-    int     rc = 0;
-    acr_file_t *f = (acr_file_t *)ACR_IOH_FDATA(file);
-
-    if (ACR_IOH_FTYPE(file) != ACR_DT_FILE) {
-        ACR_THROW_EX_IF_ERR(ACR_EX_INVALID_DESC, ACR_EFTYPE);
-        return -1;
-    }
-    if (IS_INVALID_HANDLE(f)) {
-        ACR_THROW_EX_IF_ERR(ACR_EX_CLOSED_DESC, 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
-    wr = r_write(f->fd, pb + po, cs);
-    if (wr == -1 && (errno == EAGAIN || errno == EWOULDBLOCK) &&
-        f->timeout != 0) {
-        if ((rc = wait_for_io_or_timeout(f, 0)) == 0) {
-            wr = r_write(f->fd, pb + po, cs);
-        }
-    }
-    if (wr < 0) {
-        rc = rc ? rc : ACR_GET_OS_ERROR();
-        if (ACR_STATUS_IS_EAGAIN(rc))
-            rc = ACR_TIMEUP;
-    }
-    if (wr > 0)
-        return (jint)wr;
-
-    ACR_DescriptorSetErrEx(_E, f->descriptor, rc);
-    switch (rc) {
-        case 0:
-        case ACR_TIMEUP:
-            return 0;
-        break;
-        case EBADF:
-            ACR_THROW_EX_IF_ERR(ACR_EX_ACLOSED_DESC, rc);
-        break;
-        default:
-            ACR_THROW_IO_IF_ERR(rc);
-        break;
-    }
-    return -1;
-}
-
-#define ACR_IOVEC_ON_STACK 32
-ACR_IO_EXPORT_DECLARE(jlong, FileSystemIo, write4)(ACR_JNISTDARGS,
-                                                   jint file,
-                                                   jobjectArray vec,
-                                                   jint off,
-                                                   jint len)
-{
-    size_t   i;
-    size_t  pl;
-    size_t  po = (size_t)off;
-    size_t  cs = (size_t)len;
-    ssize_t wr;
-    int     rc = 0;
-    struct iovec *iov;
-    struct iovec  onstack[ACR_IOVEC_ON_STACK];
-    jbyteArray    bastack[ACR_IOVEC_ON_STACK];
-    jbyteArray   *boa;
-    acr_file_t *f = (acr_file_t *)ACR_IOH_FDATA(file);
-
-    if (ACR_IOH_FTYPE(file) != ACR_DT_FILE) {
-        ACR_THROW_EX_IF_ERR(ACR_EX_INVALID_DESC, ACR_EFTYPE);
-        return -1;
-    }
-    if (IS_INVALID_HANDLE(f)) {
-        ACR_THROW_EX_IF_ERR(ACR_EX_CLOSED_DESC, ACR_EBADF);
-        return -1;
-    }
-    pl = (size_t)(*_E)->GetArrayLength(_E, vec);
-    if ((po + cs) > pl) {
-        ACR_ThrowException(_E, THROW_NMARK, ACR_EX_EINDEX, 0);
-        return -1;
-    }
-    if ((*_E)->EnsureLocalCapacity(_E, (jint)(cs * 2)))
-        return -1;
-    if (cs > ACR_IOVEC_ON_STACK) {
-        iov = ACR_MALLOC(struct iovec, cs);
-        boa = ACR_MALLOC(jbyteArray, cs);
-    }
-    else {
-        iov = onstack;
-        boa = bastack;
-    }
-    if (!iov || !boa) {
-        x_free(iov);
-        x_free(boa);
-        return -1;
-    }
-
-    for (i = 0; i < cs; i++) {
-        boa[i] = (*_E)->GetObjectArrayElement(_E, vec, (jsize)(i + po));
-        iov[i].iov_len  = (size_t)(*_E)->GetArrayLength(_E, boa[i]);
-        iov[i].iov_base = (void *)(*_E)->GetByteArrayElements(_E, boa[i], NULL);
-    }
-    do {
-        wr = writev(f->fd, iov, pl);
-    } while (wr == -1 && errno == EAGAIN);
-    if (wr == -1 && (errno == EAGAIN || errno == EWOULDBLOCK) &&
-        f->timeout != 0) {
-        if ((rc = wait_for_io_or_timeout(f, 0)) == 0) {
-            do {
-                wr = writev(f->fd, iov, pl);
-            } while (wr == -1 && errno == EAGAIN);
-        }
-    }
-    if (wr < 0) {
-        rc = rc ? rc : ACR_GET_OS_ERROR();
-        if (ACR_STATUS_IS_EAGAIN(rc))
-            rc = ACR_TIMEUP;
-    }
-    for (i = 0; i < cs; i++) {
-        (*_E)->ReleaseByteArrayElements(_E, boa[i], (jbyte *)iov[i].iov_base,
-                                        JNI_ABORT);
-    }
-    if (iov != onstack) {
-        x_free(iov);
-        x_free(boa);
-    }
-    if (wr > 0)
-        return (jlong)wr;
-
-    ACR_DescriptorSetErrEx(_E, f->descriptor, rc);
-    switch (rc) {
-        case 0:
-        case ACR_TIMEUP:
-            return 0;
-        break;
-        case EBADF:
-            ACR_THROW_EX_IF_ERR(ACR_EX_ACLOSED_DESC, rc);
-        break;
-        default:
-            ACR_THROW_IO_IF_ERR(rc);
-        break;
-    }
-    return -1;
-}
-
-ACR_IO_EXPORT_DECLARE(jlong, FileSystemIo, write5)(ACR_JNISTDARGS,
-                                                   jint file,
-                                                   jobjectArray vec,
-                                                   jint off,
-                                                   jint len)
-{
-    size_t   i;
-    size_t  pl;
-    size_t  po = (size_t)off;
-    size_t  cs = (size_t)len;
-    ssize_t wr;
-    int     rc = 0;
-    struct iovec *iov;
-    struct iovec  onstack[ACR_IOVEC_ON_STACK];
-    acr_file_t *f = (acr_file_t *)ACR_IOH_FDATA(file);
-
-    if (ACR_IOH_FTYPE(file) != ACR_DT_FILE) {
-        ACR_THROW_EX_IF_ERR(ACR_EX_INVALID_DESC, ACR_EFTYPE);
-        return -1;
-    }
-    if (IS_INVALID_HANDLE(f)) {
-        ACR_THROW_EX_IF_ERR(ACR_EX_CLOSED_DESC, ACR_EBADF);
-        return -1;
-    }
-    pl = (size_t)(*_E)->GetArrayLength(_E, vec);
-    if ((po + cs) > pl) {
-        ACR_ThrowException(_E, THROW_NMARK, ACR_EX_EINDEX, 0);
-        return -1;
-    }
-    if (cs > ACR_IOVEC_ON_STACK)
-        iov = ACR_MALLOC(struct iovec, cs);
-    else
-        iov = onstack;
-    if (!iov)
-        return -1;
-
-    for (i = 0; i < cs; i++) {
-        jobject bb = (*_E)->GetObjectArrayElement(_E, vec, (jsize)(i + po));
-        iov[i].iov_len  = (size_t)(*_E)->GetDirectBufferCapacity(_E, bb);
-        iov[i].iov_base = (*_E)->GetDirectBufferAddress(_E, bb);
-        (*_E)->DeleteLocalRef(_E, bb);
-    }
-    do {
-        wr = writev(f->fd, iov, pl);
-    } while (wr == -1 && errno == EAGAIN);
-    if (wr == -1 && (errno == EAGAIN || errno == EWOULDBLOCK) &&
-        f->timeout != 0) {
-        if ((rc = wait_for_io_or_timeout(f, 0)) == 0) {
-            do {
-                wr = writev(f->fd, iov, pl);
-            } while (wr == -1 && errno == EAGAIN);
-        }
-    }
-    if (wr < 0) {
-        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 (jlong)wr;
-
-    ACR_DescriptorSetErrEx(_E, f->descriptor, rc);
-    switch (rc) {
-        case 0:
-        case ACR_TIMEUP:
-            return 0;
-        break;
-        case EBADF:
-            ACR_THROW_EX_IF_ERR(ACR_EX_ACLOSED_DESC, rc);
-        break;
-        default:
-            ACR_THROW_IO_IF_ERR(rc);
-        break;
-    }
-    return -1;
-}
-
-ACR_IO_EXPORT_DECLARE(jint, FileSystemIo, 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;
-    int     rc = 0;
-    acr_file_t *f = (acr_file_t *)ACR_IOH_FDATA(file);
-
-    if (ACR_IOH_FTYPE(file) != ACR_DT_FILE) {
-        ACR_THROW_EX_IF_ERR(ACR_EX_INVALID_DESC, ACR_EFTYPE);
-        return -1;
-    }
-    if (IS_INVALID_HANDLE(f)) {
-        ACR_THROW_EX_IF_ERR(ACR_EX_CLOSED_DESC, ACR_EBADF);
-        return -1;
-    }
-    bb = (*_E)->GetByteArrayElements(_E, buf, NULL);
-    if (!bb) {
-        return -1;
-    }
-    wb = bb + po;
-    do {
-        wr = r_write(f->fd, wb, cs);
-        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)
-                break;
-        }
-        if (wr > 0) {
-            wb += wr;
-            cs -= wr;
-            wt += wr;
-        }
-    } while (wr >= 0 && cs > 0);
-    if (wt == 0) {
-        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;
-
-    ACR_DescriptorSetErrEx(_E, f->descriptor, rc);
-    switch (rc) {
-        case 0:
-        case ACR_TIMEUP:
-            return 0;
-        break;
-        case EBADF:
-            ACR_THROW_EX_IF_ERR(ACR_EX_ACLOSED_DESC, rc);
-        break;
-        default:
-            ACR_THROW_IO_IF_ERR(rc);
-        break;
-    }
-    return -1;
-}
-
-ACR_IO_EXPORT_DECLARE(jlong, FileSystemIo, 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;
-    int     rc = 0;
-    acr_file_t *f = (acr_file_t *)ACR_IOH_FDATA(file);
-
-    if (ACR_IOH_FTYPE(file) != ACR_DT_FILE) {
-        ACR_THROW_EX_IF_ERR(ACR_EX_INVALID_DESC, ACR_EFTYPE);
-        return -1;
-    }
-    if (IS_INVALID_HANDLE(f)) {
-        ACR_THROW_EX_IF_ERR(ACR_EX_CLOSED_DESC, 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;
-    do {
-        wr = r_write(f->fd, pb, cs);
-        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)
-                break;
-        }
-        if (wr > 0) {
-            pb += wr;
-            cs -= wr;
-            wt += wr;
-        }
-    } while (wr >= 0 && cs > 0);
-    if (wt == 0) {
-        rc = rc ? rc : ACR_GET_OS_ERROR();
-        if (ACR_STATUS_IS_EAGAIN(rc))
-            rc = ACR_TIMEUP;
-    }
-    if (wt > 0)
-        return (jlong)wt;
-
-    ACR_DescriptorSetErrEx(_E, f->descriptor, rc);
-    switch (rc) {
-        case 0:
-        case ACR_TIMEUP:
-            return 0;
-        break;
-        case EBADF:
-            ACR_THROW_EX_IF_ERR(ACR_EX_ACLOSED_DESC, rc);
-        break;
-        default:
-            ACR_THROW_IO_IF_ERR(rc);
-        break;
-    }
-    return -1;
-}
-
-ACR_IO_EXPORT_DECLARE(jint, FileSystemIo, fullw2)(ACR_JNISTDARGS,
-                                                  jint file,
-                                                  jobject dbb,
-                                                  jint off,
-                                                  jint 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;
-    int     rc = 0;
-    acr_file_t *f = (acr_file_t *)ACR_IOH_FDATA(file);
-
-    if (ACR_IOH_FTYPE(file) != ACR_DT_FILE) {
-        ACR_THROW_EX_IF_ERR(ACR_EX_INVALID_DESC, ACR_EFTYPE);
-        return -1;
-    }
-    if (IS_INVALID_HANDLE(f)) {
-        ACR_THROW_EX_IF_ERR(ACR_EX_CLOSED_DESC, 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;
-    do {
-        wr = r_write(f->fd, pb, cs);
-        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)
-                break;
-        }
-        if (wr > 0) {
-            pb += wr;
-            cs -= wr;
-            wt += wr;
-        }
-    } while (wr >= 0 && cs > 0);
-    if (wt == 0) {
-        rc = rc ? rc : ACR_GET_OS_ERROR();
-        if (ACR_STATUS_IS_EAGAIN(rc))
-            rc = ACR_TIMEUP;
-    }
-    if (wt > 0)
-        return (jint)wt;
-
-    ACR_DescriptorSetErrEx(_E, f->descriptor, rc);
-    switch (rc) {
-        case 0:
-        case ACR_TIMEUP:
-            return 0;
-        break;
-        case EBADF:
-            ACR_THROW_EX_IF_ERR(ACR_EX_ACLOSED_DESC, rc);
-        break;
-        default:
-            ACR_THROW_IO_IF_ERR(rc);
-        break;
-    }
-    return -1;
-}

Added: commons/sandbox/runtime/trunk/src/main/native/os/unix/fsysrw.c
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/os/unix/fsysrw.c?rev=883810&view=auto
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/os/unix/fsysrw.c (added)
+++ commons/sandbox/runtime/trunk/src/main/native/os/unix/fsysrw.c Tue Nov 24 18:47:13 2009
@@ -0,0 +1,998 @@
+/* Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "acr.h"
+#include "acr_private.h"
+#include "acr_arch.h"
+#include "acr_port.h"
+#include "acr_error.h"
+#include "acr_string.h"
+#include "acr_memory.h"
+#include "acr_descriptor.h"
+#include "acr_pointer.h"
+#include "acr_file.h"
+#include "acr_fileio.h"
+
+/* Platform includes
+ */
+#include <sys/time.h>
+
+
+static int wait_for_io_or_timeout(acr_file_t *f, int for_read)
+{
+    int rc;
+    acr_time_t     prev, nexttime;
+    struct timeval t;
+    int    timeout  = f->timeout;
+
+    f->ppoll.fd     = f->fd;
+    f->ppoll.events = for_read ? POLLIN : POLLOUT;
+    /* Store the the current time
+     */
+    gettimeofday(&t, NULL);
+    prev = ((acr_time_t)t.tv_sec * 1000) + t.tv_usec / 1000;
+    for (;;) {
+        rc = poll(&f->ppoll, 1, timeout);
+        if (rc == -1 && errno == EINTR) {
+            if (timeout >= 0) {
+                gettimeofday(&t, NULL);
+                nexttime = ((acr_time_t)t.tv_sec * 1000) + t.tv_usec / 1000;
+                timeout -= (int)(nexttime - prev);
+                if (timeout <= 0) {
+                    rc = 0;
+                    break;
+                }
+                prev = nexttime;
+            }
+        }
+        else
+            break;
+    }
+    if (rc == 0)
+        return ACR_TIMEUP;
+    else if (rc > 0)
+        return ACR_SUCCESS;
+    else
+        return errno;
+}
+
+static int wait_for_io(acr_file_t *f, int for_read)
+{
+    int rc;
+    f->ppoll.fd     = f->fd;
+    f->ppoll.events = for_read ? POLLIN : POLLOUT;
+
+    do {
+        rc = poll(&f->ppoll, 1, -1);
+    } 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, FileSystemIo, read0)(ACR_JNISTDARGS,
+                                                 jint file)
+{
+    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) {
+        ACR_THROW_EX_IF_ERR(ACR_EX_INVALID_DESC, ACR_EFTYPE);
+        return -1;
+    }
+    if (IS_INVALID_HANDLE(f)) {
+        ACR_THROW_EX_IF_ERR(ACR_EX_CLOSED_DESC, ACR_EBADF);
+        return -1;
+    }
+    if (f->eof) {
+        return -1;
+    }
+    rd = r_read(f->fd, &c, 1);
+    if (rd == -1 && (errno == EAGAIN || errno == EWOULDBLOCK) &&
+        f->timeout != 0) {
+        if ((rc = wait_for_io_or_timeout(f, 1)) == 0) {
+            rd = r_read(f->fd, &c, 1);
+        }
+    }
+    if (rd == -1) {
+        rc = rc ? rc : ACR_GET_OS_ERROR();
+        if (ACR_STATUS_IS_EAGAIN(rc))
+            rc = ACR_TIMEUP;
+    }
+    if (rd == 0) {
+        ACR_DescriptorSetErrEx(_E, f->descriptor, ACR_EOF);
+        f->eof = 1;
+        return  -1;
+    }
+    if (rd > 0)
+        return (jint)rd;
+
+    ACR_DescriptorSetErrEx(_E, f->descriptor, rc);
+    switch (rc) {
+        case 0:
+        case ACR_TIMEUP:
+            ACR_THROW_EX_IF_ERR(ACR_EX_ETIMEOUT, rc);
+        break;
+        case EBADF:
+            ACR_THROW_EX_IF_ERR(ACR_EX_ACLOSED_DESC, rc);
+        break;
+        default:
+            ACR_THROW_IO_IF_ERR(rc);
+        break;
+    }
+    return -1;
+}
+
+ACR_IO_EXPORT_DECLARE(jint, FileSystemIo, read1)(ACR_JNISTDARGS,
+                                                 jint file,
+                                                 jbyteArray buf,
+                                                 jint off,
+                                                 jint len)
+{
+    jbyte  *bb = NULL;
+    jbyte  *bc = NULL;
+    size_t  po = (size_t)off;
+    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) {
+        ACR_THROW_EX_IF_ERR(ACR_EX_INVALID_DESC, ACR_EFTYPE);
+        return -1;
+    }
+    if (IS_INVALID_HANDLE(f)) {
+        ACR_THROW_EX_IF_ERR(ACR_EX_CLOSED_DESC, ACR_EBADF);
+        return -1;
+    }
+    if (f->eof) {
+        return -1;
+    }
+    if (cs > sizeof(onstack)) {
+        if (cs > (1024 * 1024)) {
+            bc = (*_E)->GetByteArrayElements(_E, buf, NULL);
+            if (bc)
+                bb = bc + po;
+        }
+        else
+            bb = ACR_Malloc(_E, THROW_FMARK, cs);
+    }
+    else
+        bb = onstack;
+    if (!bb) {
+        /* Exception was already thrown */
+        return -1;
+    }
+    rd = r_read(f->fd, bb, cs);
+    if (rd == -1 && (errno == EAGAIN || errno == EWOULDBLOCK) &&
+        f->timeout != 0) {
+        if ((rc = wait_for_io_or_timeout(f, 1)) == 0) {
+            rd = r_read(f->fd, bb, cs);
+        }
+    }
+    if (rd == -1) {
+        rc = rc ? rc : ACR_GET_OS_ERROR();
+        if (ACR_STATUS_IS_EAGAIN(rc))
+            rc = ACR_TIMEUP;
+    }
+    if (rd > 0) {
+        if (bc) {
+            (*_E)->ReleaseByteArrayElements(_E, buf, bc, 0);
+            return (jint)rd;
+        }
+        else {
+            (*_E)->SetByteArrayRegion(_E, buf, (jsize)po, (jsize)rd, bb);
+        }
+    }
+    if (bb != onstack) {
+        if (bc)
+            (*_E)->ReleaseByteArrayElements(_E, buf, bc, JNI_ABORT);
+        else
+            x_free(bb);
+    }
+    if (rd > 0)
+        return (jint)rd;
+
+    ACR_DescriptorSetErrEx(_E, f->descriptor, rc);
+    switch (rc) {
+        case 0:
+            f->eof = 1;
+        break;
+        case ACR_TIMEUP:
+            return 0;
+        break;
+        case EBADF:
+            ACR_THROW_EX_IF_ERR(ACR_EX_ACLOSED_DESC, rc);
+        break;
+        default:
+            ACR_THROW_IO_IF_ERR(rc);
+        break;
+    }
+    return -1;
+
+}
+
+ACR_IO_EXPORT_DECLARE(jlong, FileSystemIo, read2)(ACR_JNISTDARGS,
+                                                  jint file,
+                                                  jobject ptr,
+                                                  jlong off,
+                                                  jlong len)
+{
+    size_t  pl;
+    size_t  po = (size_t)off;
+    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) {
+        ACR_THROW_EX_IF_ERR(ACR_EX_INVALID_DESC, ACR_EFTYPE);
+        return -1;
+    }
+    if (IS_INVALID_HANDLE(f)) {
+        ACR_THROW_EX_IF_ERR(ACR_EX_CLOSED_DESC, ACR_EBADF);
+        return -1;
+    }
+    if (f->eof) {
+        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;
+    }
+    rd = r_read(f->fd, pb + po, cs);
+    if (rd == -1 && (errno == EAGAIN || errno == EWOULDBLOCK) &&
+        f->timeout != 0) {
+        if ((rc = wait_for_io_or_timeout(f, 1)) == 0) {
+            rd = r_read(f->fd, pb + po, cs);
+        }
+    }
+    if (rd == -1) {
+        rc = rc ? rc : ACR_GET_OS_ERROR();
+        if (ACR_STATUS_IS_EAGAIN(rc))
+            rc = ACR_TIMEUP;
+    }
+    if (rd > 0)
+        return (jlong)rd;
+
+    ACR_DescriptorSetErrEx(_E, f->descriptor, rc);
+    switch (rc) {
+        case 0:
+            f->eof = 1;
+        break;
+        case ACR_TIMEUP:
+            return 0;
+        break;
+        case EBADF:
+            ACR_THROW_EX_IF_ERR(ACR_EX_ACLOSED_DESC, rc);
+        break;
+        default:
+            ACR_THROW_IO_IF_ERR(rc);
+        break;
+    }
+    return -1;
+}
+
+ACR_IO_EXPORT_DECLARE(jint, FileSystemIo, read3)(ACR_JNISTDARGS,
+                                                 jint file,
+                                                 jobject dbb,
+                                                 jint off,
+                                                 jint len)
+{
+#if defined(_DEBUG)
+    size_t  pl;
+#endif
+    size_t  po = (size_t)off;
+    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) {
+        ACR_THROW_EX_IF_ERR(ACR_EX_INVALID_DESC, ACR_EFTYPE);
+        return -1;
+    }
+    if (IS_INVALID_HANDLE(f)) {
+        ACR_THROW_EX_IF_ERR(ACR_EX_CLOSED_DESC, ACR_EBADF);
+        return -1;
+    }
+    if (f->eof) {
+        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
+    rd = r_read(f->fd, pb + po, cs);
+    if (rd == -1 && (errno == EAGAIN || errno == EWOULDBLOCK) &&
+        f->timeout != 0) {
+        if ((rc = wait_for_io_or_timeout(f, 1)) == 0) {
+            rd = r_read(f->fd, pb + po, cs);
+        }
+    }
+    if (rd == -1) {
+        rc = rc ? rc : ACR_GET_OS_ERROR();
+        if (ACR_STATUS_IS_EAGAIN(rc))
+            rc = ACR_TIMEUP;
+    }
+    if (rd > 0)
+        return (jint)rd;
+
+    ACR_DescriptorSetErrEx(_E, f->descriptor, rc);
+    switch (rc) {
+        case 0:
+            f->eof = 1;
+        break;
+        case ACR_TIMEUP:
+            return 0;
+        break;
+        case EBADF:
+            ACR_THROW_EX_IF_ERR(ACR_EX_ACLOSED_DESC, rc);
+        break;
+        default:
+            ACR_THROW_IO_IF_ERR(rc);
+        break;
+    }
+    return -1;
+}
+
+ACR_IO_EXPORT_DECLARE(jint, FileSystemIo, write0)(ACR_JNISTDARGS,
+                                                  jint file,
+                                                  jint b)
+{
+    unsigned char c = (unsigned char)(b & 0xFF);
+    ssize_t wr;
+    int     rc = 0;
+    acr_file_t *f = (acr_file_t *)ACR_IOH_FDATA(file);
+
+    if (ACR_IOH_FTYPE(file) != ACR_DT_FILE) {
+        ACR_THROW_EX_IF_ERR(ACR_EX_INVALID_DESC, ACR_EFTYPE);
+        return -1;
+    }
+    if (IS_INVALID_HANDLE(f)) {
+        ACR_THROW_EX_IF_ERR(ACR_EX_CLOSED_DESC, ACR_EBADF);
+        return -1;
+    }
+    wr = r_write(f->fd, &c, 1);
+    if (wr == -1 && (errno == EAGAIN || errno == EWOULDBLOCK) &&
+        f->timeout != 0) {
+        if ((rc = wait_for_io_or_timeout(f, 0)) == 0) {
+            wr = r_write(f->fd, &c, 1);
+        }
+    }
+    if (wr < 0) {
+        rc = rc ? rc : ACR_GET_OS_ERROR();
+        if (ACR_STATUS_IS_EAGAIN(rc))
+            rc = ACR_TIMEUP;
+    }
+    if (wr > 0)
+        return (jint)wr;
+
+    ACR_DescriptorSetErrEx(_E, f->descriptor, rc);
+    switch (rc) {
+        case 0:
+        case ACR_TIMEUP:
+            return 0;
+        break;
+        case EBADF:
+            ACR_THROW_EX_IF_ERR(ACR_EX_ACLOSED_DESC, rc);
+        break;
+        default:
+            ACR_THROW_IO_IF_ERR(rc);
+        break;
+    }
+    return -1;
+}
+
+ACR_IO_EXPORT_DECLARE(jint, FileSystemIo, write1)(ACR_JNISTDARGS,
+                                                  jint file,
+                                                  jbyteArray buf,
+                                                  jint off,
+                                                  jint len)
+{
+    jbyte  *bb;
+    size_t  po = (size_t)off;
+    size_t  cs = (size_t)len;
+    ssize_t wr;
+    int     rc = 0;
+    acr_file_t *f = (acr_file_t *)ACR_IOH_FDATA(file);
+
+    if (ACR_IOH_FTYPE(file) != ACR_DT_FILE) {
+        ACR_THROW_EX_IF_ERR(ACR_EX_INVALID_DESC, ACR_EFTYPE);
+        return -1;
+    }
+    if (IS_INVALID_HANDLE(f)) {
+        ACR_THROW_EX_IF_ERR(ACR_EX_CLOSED_DESC, ACR_EBADF);
+        return -1;
+    }
+    bb = (*_E)->GetByteArrayElements(_E, buf, NULL);
+    if (!bb) {
+        return -1;
+    }
+
+    wr = r_write(f->fd, bb + po, cs);
+    if (wr == -1 && (errno == EAGAIN || errno == EWOULDBLOCK) &&
+        f->timeout != 0) {
+        if ((rc = wait_for_io_or_timeout(f, 0)) == 0) {
+            wr = r_write(f->fd, bb + po, cs);
+        }
+    }
+    if (wr < 0) {
+        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;
+
+    ACR_DescriptorSetErrEx(_E, f->descriptor, rc);
+    switch (rc) {
+        case 0:
+        case ACR_TIMEUP:
+            return 0;
+        break;
+        case EBADF:
+            ACR_THROW_EX_IF_ERR(ACR_EX_ACLOSED_DESC, rc);
+        break;
+        default:
+            ACR_THROW_IO_IF_ERR(rc);
+        break;
+    }
+    return -1;
+}
+
+ACR_IO_EXPORT_DECLARE(jlong, FileSystemIo, write2)(ACR_JNISTDARGS,
+                                                   jint file,
+                                                   jobject ptr,
+                                                   jlong off,
+                                                   jlong len)
+{
+    size_t  pl;
+    size_t  po = (size_t)off;
+    size_t  cs = (size_t)len;
+    jbyte  *pb;
+    ssize_t wr;
+    int     rc = 0;
+    acr_file_t *f = (acr_file_t *)ACR_IOH_FDATA(file);
+
+    if (ACR_IOH_FTYPE(file) != ACR_DT_FILE) {
+        ACR_THROW_EX_IF_ERR(ACR_EX_INVALID_DESC, ACR_EFTYPE);
+        return -1;
+    }
+    if (IS_INVALID_HANDLE(f)) {
+        ACR_THROW_EX_IF_ERR(ACR_EX_CLOSED_DESC, 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;
+    }
+    wr = r_write(f->fd, pb + po, cs);
+    if (wr == -1 && (errno == EAGAIN || errno == EWOULDBLOCK) &&
+        f->timeout != 0) {
+        if ((rc = wait_for_io_or_timeout(f, 0)) == 0) {
+            wr = r_write(f->fd, pb + po, cs);
+        }
+    }
+    if (wr < 0) {
+        rc = rc ? rc : ACR_GET_OS_ERROR();
+        if (ACR_STATUS_IS_EAGAIN(rc))
+            rc = ACR_TIMEUP;
+    }
+    if (wr > 0)
+        return (jlong)wr;
+
+    ACR_DescriptorSetErrEx(_E, f->descriptor, rc);
+    switch (rc) {
+        case 0:
+        case ACR_TIMEUP:
+            return 0;
+        break;
+        case EBADF:
+            ACR_THROW_EX_IF_ERR(ACR_EX_ACLOSED_DESC, rc);
+        break;
+        default:
+            ACR_THROW_IO_IF_ERR(rc);
+        break;
+    }
+    return -1;
+}
+
+ACR_IO_EXPORT_DECLARE(jint, FileSystemIo, write3)(ACR_JNISTDARGS,
+                                                  jint file,
+                                                  jobject dbb,
+                                                  jlong off,
+                                                  jlong len)
+{
+#if defined(_DEBUG)
+    size_t  pl;
+#endif
+    size_t  po = (size_t)off;
+    size_t  cs = (size_t)len;
+    jbyte  *pb;
+    ssize_t wr;
+    int     rc = 0;
+    acr_file_t *f = (acr_file_t *)ACR_IOH_FDATA(file);
+
+    if (ACR_IOH_FTYPE(file) != ACR_DT_FILE) {
+        ACR_THROW_EX_IF_ERR(ACR_EX_INVALID_DESC, ACR_EFTYPE);
+        return -1;
+    }
+    if (IS_INVALID_HANDLE(f)) {
+        ACR_THROW_EX_IF_ERR(ACR_EX_CLOSED_DESC, 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
+    wr = r_write(f->fd, pb + po, cs);
+    if (wr == -1 && (errno == EAGAIN || errno == EWOULDBLOCK) &&
+        f->timeout != 0) {
+        if ((rc = wait_for_io_or_timeout(f, 0)) == 0) {
+            wr = r_write(f->fd, pb + po, cs);
+        }
+    }
+    if (wr < 0) {
+        rc = rc ? rc : ACR_GET_OS_ERROR();
+        if (ACR_STATUS_IS_EAGAIN(rc))
+            rc = ACR_TIMEUP;
+    }
+    if (wr > 0)
+        return (jint)wr;
+
+    ACR_DescriptorSetErrEx(_E, f->descriptor, rc);
+    switch (rc) {
+        case 0:
+        case ACR_TIMEUP:
+            return 0;
+        break;
+        case EBADF:
+            ACR_THROW_EX_IF_ERR(ACR_EX_ACLOSED_DESC, rc);
+        break;
+        default:
+            ACR_THROW_IO_IF_ERR(rc);
+        break;
+    }
+    return -1;
+}
+
+#define ACR_IOVEC_ON_STACK 32
+ACR_IO_EXPORT_DECLARE(jlong, FileSystemIo, write4)(ACR_JNISTDARGS,
+                                                   jint file,
+                                                   jobjectArray vec,
+                                                   jint off,
+                                                   jint len)
+{
+    size_t   i;
+    size_t  pl;
+    size_t  po = (size_t)off;
+    size_t  cs = (size_t)len;
+    ssize_t wr;
+    int     rc = 0;
+    struct iovec *iov;
+    struct iovec  onstack[ACR_IOVEC_ON_STACK];
+    jbyteArray    bastack[ACR_IOVEC_ON_STACK];
+    jbyteArray   *boa;
+    acr_file_t *f = (acr_file_t *)ACR_IOH_FDATA(file);
+
+    if (ACR_IOH_FTYPE(file) != ACR_DT_FILE) {
+        ACR_THROW_EX_IF_ERR(ACR_EX_INVALID_DESC, ACR_EFTYPE);
+        return -1;
+    }
+    if (IS_INVALID_HANDLE(f)) {
+        ACR_THROW_EX_IF_ERR(ACR_EX_CLOSED_DESC, ACR_EBADF);
+        return -1;
+    }
+    pl = (size_t)(*_E)->GetArrayLength(_E, vec);
+    if ((po + cs) > pl) {
+        ACR_ThrowException(_E, THROW_NMARK, ACR_EX_EINDEX, 0);
+        return -1;
+    }
+    if ((*_E)->EnsureLocalCapacity(_E, (jint)(cs * 2)))
+        return -1;
+    if (cs > ACR_IOVEC_ON_STACK) {
+        iov = ACR_MALLOC(struct iovec, cs);
+        boa = ACR_MALLOC(jbyteArray, cs);
+    }
+    else {
+        iov = onstack;
+        boa = bastack;
+    }
+    if (!iov || !boa) {
+        x_free(iov);
+        x_free(boa);
+        return -1;
+    }
+
+    for (i = 0; i < cs; i++) {
+        boa[i] = (*_E)->GetObjectArrayElement(_E, vec, (jsize)(i + po));
+        iov[i].iov_len  = (size_t)(*_E)->GetArrayLength(_E, boa[i]);
+        iov[i].iov_base = (void *)(*_E)->GetByteArrayElements(_E, boa[i], NULL);
+    }
+    do {
+        wr = writev(f->fd, iov, pl);
+    } while (wr == -1 && errno == EAGAIN);
+    if (wr == -1 && (errno == EAGAIN || errno == EWOULDBLOCK) &&
+        f->timeout != 0) {
+        if ((rc = wait_for_io_or_timeout(f, 0)) == 0) {
+            do {
+                wr = writev(f->fd, iov, pl);
+            } while (wr == -1 && errno == EAGAIN);
+        }
+    }
+    if (wr < 0) {
+        rc = rc ? rc : ACR_GET_OS_ERROR();
+        if (ACR_STATUS_IS_EAGAIN(rc))
+            rc = ACR_TIMEUP;
+    }
+    for (i = 0; i < cs; i++) {
+        (*_E)->ReleaseByteArrayElements(_E, boa[i], (jbyte *)iov[i].iov_base,
+                                        JNI_ABORT);
+    }
+    if (iov != onstack) {
+        x_free(iov);
+        x_free(boa);
+    }
+    if (wr > 0)
+        return (jlong)wr;
+
+    ACR_DescriptorSetErrEx(_E, f->descriptor, rc);
+    switch (rc) {
+        case 0:
+        case ACR_TIMEUP:
+            return 0;
+        break;
+        case EBADF:
+            ACR_THROW_EX_IF_ERR(ACR_EX_ACLOSED_DESC, rc);
+        break;
+        default:
+            ACR_THROW_IO_IF_ERR(rc);
+        break;
+    }
+    return -1;
+}
+
+ACR_IO_EXPORT_DECLARE(jlong, FileSystemIo, write5)(ACR_JNISTDARGS,
+                                                   jint file,
+                                                   jobjectArray vec,
+                                                   jint off,
+                                                   jint len)
+{
+    size_t   i;
+    size_t  pl;
+    size_t  po = (size_t)off;
+    size_t  cs = (size_t)len;
+    ssize_t wr;
+    int     rc = 0;
+    struct iovec *iov;
+    struct iovec  onstack[ACR_IOVEC_ON_STACK];
+    acr_file_t *f = (acr_file_t *)ACR_IOH_FDATA(file);
+
+    if (ACR_IOH_FTYPE(file) != ACR_DT_FILE) {
+        ACR_THROW_EX_IF_ERR(ACR_EX_INVALID_DESC, ACR_EFTYPE);
+        return -1;
+    }
+    if (IS_INVALID_HANDLE(f)) {
+        ACR_THROW_EX_IF_ERR(ACR_EX_CLOSED_DESC, ACR_EBADF);
+        return -1;
+    }
+    pl = (size_t)(*_E)->GetArrayLength(_E, vec);
+    if ((po + cs) > pl) {
+        ACR_ThrowException(_E, THROW_NMARK, ACR_EX_EINDEX, 0);
+        return -1;
+    }
+    if (cs > ACR_IOVEC_ON_STACK)
+        iov = ACR_MALLOC(struct iovec, cs);
+    else
+        iov = onstack;
+    if (!iov)
+        return -1;
+
+    for (i = 0; i < cs; i++) {
+        jobject bb = (*_E)->GetObjectArrayElement(_E, vec, (jsize)(i + po));
+        iov[i].iov_len  = (size_t)(*_E)->GetDirectBufferCapacity(_E, bb);
+        iov[i].iov_base = (*_E)->GetDirectBufferAddress(_E, bb);
+        (*_E)->DeleteLocalRef(_E, bb);
+    }
+    do {
+        wr = writev(f->fd, iov, pl);
+    } while (wr == -1 && errno == EAGAIN);
+    if (wr == -1 && (errno == EAGAIN || errno == EWOULDBLOCK) &&
+        f->timeout != 0) {
+        if ((rc = wait_for_io_or_timeout(f, 0)) == 0) {
+            do {
+                wr = writev(f->fd, iov, pl);
+            } while (wr == -1 && errno == EAGAIN);
+        }
+    }
+    if (wr < 0) {
+        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 (jlong)wr;
+
+    ACR_DescriptorSetErrEx(_E, f->descriptor, rc);
+    switch (rc) {
+        case 0:
+        case ACR_TIMEUP:
+            return 0;
+        break;
+        case EBADF:
+            ACR_THROW_EX_IF_ERR(ACR_EX_ACLOSED_DESC, rc);
+        break;
+        default:
+            ACR_THROW_IO_IF_ERR(rc);
+        break;
+    }
+    return -1;
+}
+
+ACR_IO_EXPORT_DECLARE(jint, FileSystemIo, 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;
+    int     rc = 0;
+    acr_file_t *f = (acr_file_t *)ACR_IOH_FDATA(file);
+
+    if (ACR_IOH_FTYPE(file) != ACR_DT_FILE) {
+        ACR_THROW_EX_IF_ERR(ACR_EX_INVALID_DESC, ACR_EFTYPE);
+        return -1;
+    }
+    if (IS_INVALID_HANDLE(f)) {
+        ACR_THROW_EX_IF_ERR(ACR_EX_CLOSED_DESC, ACR_EBADF);
+        return -1;
+    }
+    bb = (*_E)->GetByteArrayElements(_E, buf, NULL);
+    if (!bb) {
+        return -1;
+    }
+    wb = bb + po;
+    do {
+        wr = r_write(f->fd, wb, cs);
+        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)
+                break;
+        }
+        if (wr > 0) {
+            wb += wr;
+            cs -= wr;
+            wt += wr;
+        }
+    } while (wr >= 0 && cs > 0);
+    if (wt == 0) {
+        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;
+
+    ACR_DescriptorSetErrEx(_E, f->descriptor, rc);
+    switch (rc) {
+        case 0:
+        case ACR_TIMEUP:
+            return 0;
+        break;
+        case EBADF:
+            ACR_THROW_EX_IF_ERR(ACR_EX_ACLOSED_DESC, rc);
+        break;
+        default:
+            ACR_THROW_IO_IF_ERR(rc);
+        break;
+    }
+    return -1;
+}
+
+ACR_IO_EXPORT_DECLARE(jlong, FileSystemIo, 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;
+    int     rc = 0;
+    acr_file_t *f = (acr_file_t *)ACR_IOH_FDATA(file);
+
+    if (ACR_IOH_FTYPE(file) != ACR_DT_FILE) {
+        ACR_THROW_EX_IF_ERR(ACR_EX_INVALID_DESC, ACR_EFTYPE);
+        return -1;
+    }
+    if (IS_INVALID_HANDLE(f)) {
+        ACR_THROW_EX_IF_ERR(ACR_EX_CLOSED_DESC, 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;
+    do {
+        wr = r_write(f->fd, pb, cs);
+        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)
+                break;
+        }
+        if (wr > 0) {
+            pb += wr;
+            cs -= wr;
+            wt += wr;
+        }
+    } while (wr >= 0 && cs > 0);
+    if (wt == 0) {
+        rc = rc ? rc : ACR_GET_OS_ERROR();
+        if (ACR_STATUS_IS_EAGAIN(rc))
+            rc = ACR_TIMEUP;
+    }
+    if (wt > 0)
+        return (jlong)wt;
+
+    ACR_DescriptorSetErrEx(_E, f->descriptor, rc);
+    switch (rc) {
+        case 0:
+        case ACR_TIMEUP:
+            return 0;
+        break;
+        case EBADF:
+            ACR_THROW_EX_IF_ERR(ACR_EX_ACLOSED_DESC, rc);
+        break;
+        default:
+            ACR_THROW_IO_IF_ERR(rc);
+        break;
+    }
+    return -1;
+}
+
+ACR_IO_EXPORT_DECLARE(jint, FileSystemIo, fullw2)(ACR_JNISTDARGS,
+                                                  jint file,
+                                                  jobject dbb,
+                                                  jint off,
+                                                  jint 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;
+    int     rc = 0;
+    acr_file_t *f = (acr_file_t *)ACR_IOH_FDATA(file);
+
+    if (ACR_IOH_FTYPE(file) != ACR_DT_FILE) {
+        ACR_THROW_EX_IF_ERR(ACR_EX_INVALID_DESC, ACR_EFTYPE);
+        return -1;
+    }
+    if (IS_INVALID_HANDLE(f)) {
+        ACR_THROW_EX_IF_ERR(ACR_EX_CLOSED_DESC, 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;
+    do {
+        wr = r_write(f->fd, pb, cs);
+        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)
+                break;
+        }
+        if (wr > 0) {
+            pb += wr;
+            cs -= wr;
+            wt += wr;
+        }
+    } while (wr >= 0 && cs > 0);
+    if (wt == 0) {
+        rc = rc ? rc : ACR_GET_OS_ERROR();
+        if (ACR_STATUS_IS_EAGAIN(rc))
+            rc = ACR_TIMEUP;
+    }
+    if (wt > 0)
+        return (jint)wt;
+
+    ACR_DescriptorSetErrEx(_E, f->descriptor, rc);
+    switch (rc) {
+        case 0:
+        case ACR_TIMEUP:
+            return 0;
+        break;
+        case EBADF:
+            ACR_THROW_EX_IF_ERR(ACR_EX_ACLOSED_DESC, rc);
+        break;
+        default:
+            ACR_THROW_IO_IF_ERR(rc);
+        break;
+    }
+    return -1;
+}

Propchange: commons/sandbox/runtime/trunk/src/main/native/os/unix/fsysrw.c
------------------------------------------------------------------------------
    svn:eol-style = native



Mime
View raw message