commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mt...@apache.org
Subject svn commit: r820327 - in /commons/sandbox/runtime/trunk/src/main/native: include/acr_file.h include/arch/windows/acr_arch.h os/unix/fsysio.c os/win32/fsysio.c
Date Wed, 30 Sep 2009 16:03:16 GMT
Author: mturk
Date: Wed Sep 30 16:03:15 2009
New Revision: 820327

URL: http://svn.apache.org/viewvc?rev=820327&view=rev
Log:
Implement more read methods

Modified:
    commons/sandbox/runtime/trunk/src/main/native/include/acr_file.h
    commons/sandbox/runtime/trunk/src/main/native/include/arch/windows/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/include/acr_file.h
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/include/acr_file.h?rev=820327&r1=820326&r2=820327&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/include/acr_file.h (original)
+++ commons/sandbox/runtime/trunk/src/main/native/include/acr_file.h Wed Sep 30 16:03:15 2009
@@ -184,6 +184,7 @@
     int          err;                   /**< Last error value           */
     acr_uint32_t flags;                 /**< File flags                 */
     acr_time_t   timeout;               /**< I/O timeout                */
+    acr_off_t    pos;                   /**< Current file pointer       */
     enum {
         BLK_UNKNOWN,
         BLK_OFF,
@@ -193,9 +194,9 @@
     /* The rest of the structure is platform specific.
      */
 #if defined(WIN32)
-    LARGE_INTEGER   pos;
+    CRITICAL_SECTION lock;
 #else
-    acr_off_t       pos;
+    pthread_mutex_t  lock;
 #endif
 
 } acr_file_t;

Modified: commons/sandbox/runtime/trunk/src/main/native/include/arch/windows/acr_arch.h
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/include/arch/windows/acr_arch.h?rev=820327&r1=820326&r2=820327&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/include/arch/windows/acr_arch.h (original)
+++ commons/sandbox/runtime/trunk/src/main/native/include/arch/windows/acr_arch.h Wed Sep
30 16:03:15 2009
@@ -642,6 +642,28 @@
 #undef  IsWow64Process
 #define IsWow64Process acr_winapi_IsWow64Process
 
+ACR_DECLARE_LATE_DLL_FUNC(SYSDLL_KERNEL32, BOOL, FALSE,
+                          WINAPI, GetPerformanceInfo, 0, (
+    PPERFORMACE_INFORMATION pPerformanceInformation,
+    DWORD cb),
+    (pPerformanceInformation, cb));
+#undef  GetPerformanceInfo
+#define GetPerformanceInfo acr_winapi_GetPerformanceInfo
+
+#if !defined(FILE_NAME_NORMALIZED)
+#define FILE_NAME_NORMALIZED 0
+#endif
+ACR_DECLARE_LATE_DLL_FUNC(SYSDLL_KERNEL32, DWORD, 0,
+                          WINAPI, GetFinalPathNameByHandleW, 0, (
+  IN  HANDLE hFile,
+  OUT LPWSTR lpszFilePath,
+  IN  DWORD  cchFilePath,
+  IN  DWORD  dwFlags),
+    (hFile, lpszFilePath, cchFilePath, dwFlags));
+#undef  GetFinalPathNameByHandleW
+#define GetFinalPathNameByHandleW acr_winapi_GetFinalPathNameByHandleW
+
+
 ACR_DECLARE_LATE_DLL_FUNC(SYSDLL_NTDLL, NTSTATUS, 1,
                           WINAPI, NtQuerySystemInformation, 0, (
     IN SYSTEM_INFORMATION_CLASS SystemInformationClass,
@@ -663,14 +685,6 @@
 #undef  NtQueryInformationProcess
 #define NtQueryInformationProcess acr_winapi_NtQueryInformationProcess
 
-ACR_DECLARE_LATE_DLL_FUNC(SYSDLL_KERNEL32, BOOL, FALSE,
-                          WINAPI, GetPerformanceInfo, 0, (
-    PPERFORMACE_INFORMATION pPerformanceInformation,
-    DWORD cb),
-    (pPerformanceInformation, cb));
-#undef  GetPerformanceInfo
-#define GetPerformanceInfo acr_winapi_GetPerformanceInfo
-
 ACR_DECLARE_LATE_DLL_FUNC(SYSDLL_IPHLPAPI, DWORD, ERROR_INVALID_FUNCTION,
                           WINAPI, GetExtendedTcpTable, 0, (
     PVOID pTcpTable,

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=820327&r1=820326&r2=820327&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 Wed Sep 30 16:03:15 2009
@@ -108,6 +108,9 @@
     if ((flags & ACR_FOPEN_EXCL) && !(flags & ACR_FOPEN_CREATE)) {
         return ACR_EINVAL;
     }
+    if ((flags & ACR_FOPEN_APPEND) && !(flags & ACR_FOPEN_WRITE)) {
+        return ACR_EINVAL;
+    }
     if (flags & ACR_FOPEN_APPEND)
         oflags |= O_APPEND;
     if (flags & ACR_FOPEN_TRUNCATE)

Modified: commons/sandbox/runtime/trunk/src/main/native/os/win32/fsysio.c
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/os/win32/fsysio.c?rev=820327&r1=820326&r2=820327&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/os/win32/fsysio.c (original)
+++ commons/sandbox/runtime/trunk/src/main/native/os/win32/fsysio.c Wed Sep 30 16:03:15 2009
@@ -121,6 +121,9 @@
     if ((flags & ACR_FOPEN_EXCL) && !(flags & ACR_FOPEN_CREATE)) {
         return ACR_EINVAL;
     }
+    if ((flags & ACR_FOPEN_APPEND) && !(flags & ACR_FOPEN_WRITE)) {
+        return ACR_EINVAL;
+    }
     if (flags & ACR_FOPEN_DELONCLOSE)
         aflags |= FILE_FLAG_DELETE_ON_CLOSE;
     if (flags & ACR_FOPEN_SENDFILE_ENABLED) {
@@ -166,7 +169,6 @@
         goto finally;
     }
     fp->fd    = fh;
-    fp->name  = ACR_StrdupW(_E, THROW_NMARK, fname);
     fp->flags = flags;
     fp->type  = ACR_FT_REG; /* Presume it's a regular file */
     if (flags & ACR_FOPEN_NONBLOCK)
@@ -181,6 +183,49 @@
         rc = ACR_GET_OS_ERROR();
         goto finally;
     }
+    if (ACR_HAVE_LATE_DLL_FUNC(GetFinalPathNameByHandleW)) {
+        DWORD nl;
+        nl = GetFinalPathNameByHandleW(fh, NULL, 0, FILE_NAME_NORMALIZED);
+        if (nl == 0) {
+            rc = ACR_GET_OS_ERROR();
+            goto finally;
+        }
+        fp->name = ACR_MALLOC(wchar_t, nl + 1);
+        if (!fp->name) {
+            rc = ACR_ENOMEM;
+            goto finally;
+        }
+        GetFinalPathNameByHandleW(fh, fp->name, nl, FILE_NAME_NORMALIZED);
+    }
+    else {
+        DWORD nl;
+
+        nl = GetFullPathNameW(fname, 0, NULL, NULL);
+        if (nl == 0) {
+            rc = ACR_GET_OS_ERROR();
+            goto finally;
+        }
+        fp->name = ACR_MALLOC(wchar_t, nl + 1);
+        if (!fp->name) {
+            rc = ACR_ENOMEM;
+            goto finally;
+        }
+        GetFullPathNameW(fname, nl, fp->name, NULL);
+    }
+    if (flags & ACR_FOPEN_APPEND) {
+        __try {
+            /* On Vista+ exception is no longer thrown
+             */
+            InitializeCriticalSection(&fp->lock);
+        }
+        __except(EXCEPTION_EXECUTE_HANDLER) {
+            rc = ACR_ENOMEM;
+            goto finally;
+        }
+        /* Position to the file end
+         */
+        SetFilePointer(fh, 0, NULL, FILE_END);
+    }
     /* Create File Descriptor Object */
     *fdo = ACR_DescriptorCreate(_E, ACR_DT_FILE, fo, NULL,
                                 descriptor_cleanup);
@@ -188,11 +233,7 @@
         rc = ACR_GET_OS_ERROR();
         goto finally;
     }
-    if (flags & ACR_FOPEN_APPEND) {
-        /* Position to the file end
-         */
-        SetFilePointer(fh, 0, NULL, FILE_END);
-    }
+
 finally:
     if (rc) {
         if (IS_VALID_HANDLE(fh))
@@ -457,7 +498,8 @@
         ACR_THROW_IO_ERRNO();
         return -1;
     }
-    return (jlong)op.QuadPart;
+    f->pos = op.QuadPart;
+    return (jlong)f->pos;
 }
 
 ACR_IO_EXPORT_DECLARE(jint, FileSystem, trunc0)(ACR_JNISTDARGS,
@@ -475,6 +517,8 @@
     os.QuadPart = off;
     if (!SetFilePointerEx(f->fd, os, NULL, FILE_BEGIN))
         return ACR_GET_OS_ERROR();
+    else
+        f->pos = off;
     if (!SetEndOfFile(f->fd))
         return ACR_GET_OS_ERROR();
     else
@@ -613,7 +657,7 @@
     }
 
     if (f->blocking == BLK_OFF) {
-        if (f->timeout == 0 && f->type == ACR_DT_PIPE) {
+        if (f->timeout == 0 && f->type == ACR_FT_PIPE) {
             if (!PeekNamedPipe(f->fd, NULL, 0, NULL, &rd, NULL)) {
                 rc = GetLastError();
                 if (rc == ERROR_BROKEN_PIPE) {
@@ -637,15 +681,15 @@
             lpo->hEvent = CreateEvent(NULL, TRUE, TRUE, NULL);
         if (IS_INVALID_HANDLE(lpo->hEvent))
             return ACR_GET_OS_ERROR();
-        lpo->Offset     = f->pos.LowPart;
-        lpo->OffsetHigh = f->pos.HighPart;
+        lpo->Offset     = (DWORD)(f->pos);
+        lpo->OffsetHigh = (DWORD)(f->pos >> 32);
     }
     f->err = 0;
     if (ReadFile(f->fd, &c, 1, &rd, lpo)) {
         /* All done. Update the position and return
          */
         if (rd) {
-            f->pos.QuadPart += rd;
+            f->pos += rd;
             return c;
         }
         else {
@@ -664,7 +708,7 @@
                 case 0:
                     f->err = 0;
                     if (rd) {
-                        f->pos.QuadPart += rd;
+                        f->pos += rd;
                         return c;
                     }
                     else
@@ -722,7 +766,7 @@
         return -1;
     }
     if (f->blocking == BLK_OFF) {
-        if (f->timeout == 0 && f->type == ACR_DT_PIPE) {
+        if (f->timeout == 0 && f->type == ACR_FT_PIPE) {
             if (!PeekNamedPipe(f->fd, NULL, 0, NULL, &rd, NULL)) {
                 rc = GetLastError();
                 if (rc == ERROR_BROKEN_PIPE) {
@@ -755,8 +799,8 @@
             ACR_THROW_IO_ERRNO();
             return -1;
         }
-        lpo->Offset     = f->pos.LowPart;
-        lpo->OffsetHigh = f->pos.HighPart;
+        lpo->Offset     = (DWORD)(f->pos);
+        lpo->OffsetHigh = (DWORD)(f->pos >> 32);
     }
     if (cs > (DWORD)sizeof(onstack)) {
         if (cs > (1024 * 1024)) {
@@ -778,7 +822,7 @@
         /* All done. Update the position and return
          */
         if (rd)
-            f->pos.QuadPart += rd;
+            f->pos += rd;
         else
             f->eof = 1;
         goto finally;
@@ -794,7 +838,7 @@
                 case 0:
                     f->err = 0;
                     if (rd) {
-                        f->pos.QuadPart += rd;
+                        f->pos += rd;
                         goto finally;
                     }
                     else
@@ -840,3 +884,256 @@
     }
     return (jint)rd;
 }
+
+ACR_IO_EXPORT_DECLARE(jint, FileSystem, read2)(ACR_JNISTDARGS,
+                                               jint file,
+                                               jobject ptr,
+                                               jlong off,
+                                               jlong len)
+{
+    size_t  pl;
+    DWORD   po = (DWORD)off;
+    DWORD   cs = (DWORD)len;
+    DWORD   rd = 0;
+    DWORD   rc;
+    LPOVERLAPPED lpo = NULL;
+    jbyte  *pb;
+    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;
+    }
+    if (f->eof) {
+        return -1;
+    }
+    if (f->blocking == BLK_OFF) {
+        if (f->timeout == 0 && f->type == ACR_FT_PIPE) {
+            if (!PeekNamedPipe(f->fd, NULL, 0, NULL, &rd, NULL)) {
+                rc = GetLastError();
+                if (rc == ERROR_BROKEN_PIPE) {
+                    f->eof = 1;
+                    return -1;
+                }
+                else {
+                    ACR_THROW_IO_IF_ERR(rc);
+                    return -1;
+                }
+            }
+            else {
+                if (rd == 0) {
+                    f->err = ACR_TIMEUP;
+                    return 0;
+                }
+                else {
+                    /* Update read size that can be done
+                     * without blocking
+                     */
+                    if (cs > rd)
+                        cs = rd;
+                }
+            }
+        }
+        lpo = &f->overlap;
+        if (IS_INVALID_HANDLE(lpo->hEvent))
+            lpo->hEvent = CreateEvent(NULL, TRUE, TRUE, NULL);
+        if (IS_INVALID_HANDLE(lpo->hEvent)) {
+            ACR_THROW_IO_ERRNO();
+            return -1;
+        }
+        lpo->Offset     = (DWORD)(f->pos);
+        lpo->OffsetHigh = (DWORD)(f->pos >> 32);
+    }
+    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;
+    }
+    f->err = 0;
+    if (ReadFile(f->fd, pb + po, cs, &rd, lpo)) {
+        /* All done. Update the position and return
+         */
+        if (rd)
+            f->pos += rd;
+        else
+            f->eof = 1;
+        goto finally;
+    }
+    switch (f->err = GetLastError()) {
+        case ERROR_HANDLE_EOF:
+        case ERROR_BROKEN_PIPE:
+            f->err = 0;
+            f->eof = 1;
+        break;
+        case ERROR_IO_PENDING:
+            switch (rc = overlapped_wait(f, &rd)) {
+                case 0:
+                    f->err = 0;
+                    if (rd) {
+                        f->pos += rd;
+                        goto finally;
+                    }
+                    else
+                        f->eof = 1;
+                break;
+                case ERROR_HANDLE_EOF:
+                case ERROR_BROKEN_PIPE:
+                    f->err = 0;
+                    f->eof = 1;
+                break;
+                case ACR_TIMEUP:
+                    f->err = ACR_TIMEUP;
+                break;
+                default:
+                    f->err = rc;
+                break;
+            }
+        break;
+        default:
+        break;
+    }
+
+finally:
+    if (rd)
+        return (jint)rd;
+    if (f->err)
+        return f->err == ACR_TIMEUP ? 0 : -1;
+    return -1;
+}
+
+ACR_IO_EXPORT_DECLARE(jint, FileSystem, read3)(ACR_JNISTDARGS,
+                                               jint file,
+                                               jobject dbb,
+                                               jlong off,
+                                               jlong len)
+{
+#if defined(_DEBUG)
+    DWORD   pl;
+#endif
+    DWORD   po = (DWORD)off;
+    DWORD   cs = (DWORD)len;
+    DWORD   rd = 0;
+    DWORD   rc;
+    LPOVERLAPPED lpo = NULL;
+    jbyte  *pb;
+    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;
+    }
+    if (f->eof) {
+        return -1;
+    }
+    if (f->blocking == BLK_OFF) {
+        if (f->timeout == 0 && f->type == ACR_FT_PIPE) {
+            if (!PeekNamedPipe(f->fd, NULL, 0, NULL, &rd, NULL)) {
+                rc = GetLastError();
+                if (rc == ERROR_BROKEN_PIPE) {
+                    f->eof = 1;
+                    return -1;
+                }
+                else {
+                    ACR_THROW_IO_IF_ERR(rc);
+                    return -1;
+                }
+            }
+            else {
+                if (rd == 0) {
+                    f->err = ACR_TIMEUP;
+                    return 0;
+                }
+                else {
+                    /* Update read size that can be done
+                     * without blocking
+                     */
+                    if (cs > rd)
+                        cs = rd;
+                }
+            }
+        }
+        lpo = &f->overlap;
+        if (IS_INVALID_HANDLE(lpo->hEvent))
+            lpo->hEvent = CreateEvent(NULL, TRUE, TRUE, NULL);
+        if (IS_INVALID_HANDLE(lpo->hEvent)) {
+            ACR_THROW_IO_ERRNO();
+            return -1;
+        }
+        lpo->Offset     = (DWORD)(f->pos);
+        lpo->OffsetHigh = (DWORD)(f->pos >> 32);
+    }
+    pb = (jbyte *)(*_E)->GetDirectBufferAddress(_E, dbb);
+    if (!pb) {
+        ACR_ThrowException(_E, THROW_NMARK, ACR_EX_ENULL, 0);
+        return -1;
+    }
+#if defined(_DEBUG)
+    pl = (DWORD)(*_E)->GetDirectBufferCapacity(_E, dbb);
+    if ((po + cs) > pl) {
+        ACR_ThrowException(_E, THROW_NMARK, ACR_EX_EINDEX, 0);
+        return -1;
+    }
+#endif
+    f->err = 0;
+    if (ReadFile(f->fd, pb + po, cs, &rd, lpo)) {
+        /* All done. Update the position and return
+         */
+        if (rd)
+            f->pos += rd;
+        else
+            f->eof = 1;
+        goto finally;
+    }
+    switch (f->err = GetLastError()) {
+        case ERROR_HANDLE_EOF:
+        case ERROR_BROKEN_PIPE:
+            f->err = 0;
+            f->eof = 1;
+        break;
+        case ERROR_IO_PENDING:
+            switch (rc = overlapped_wait(f, &rd)) {
+                case 0:
+                    f->err = 0;
+                    if (rd) {
+                        f->pos += rd;
+                        goto finally;
+                    }
+                    else
+                        f->eof = 1;
+                break;
+                case ERROR_HANDLE_EOF:
+                case ERROR_BROKEN_PIPE:
+                    f->err = 0;
+                    f->eof = 1;
+                break;
+                case ACR_TIMEUP:
+                    f->err = ACR_TIMEUP;
+                break;
+                default:
+                    f->err = rc;
+                break;
+            }
+        break;
+        default:
+        break;
+    }
+
+finally:
+    if (rd)
+        return (jint)rd;
+    if (f->err)
+        return f->err == ACR_TIMEUP ? 0 : -1;
+    return -1;
+}



Mime
View raw message