You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by mt...@apache.org on 2009/11/25 14:17:26 UTC

svn commit: r884087 - in /commons/sandbox/runtime/trunk: src/main/java/org/apache/commons/runtime/io/Pipe.java src/main/native/include/acr_pipe.h src/main/native/os/unix/pipe.c src/main/native/os/win32/pipe.c xdocs/index.xml

Author: mturk
Date: Wed Nov 25 13:17:25 2009
New Revision: 884087

URL: http://svn.apache.org/viewvc?rev=884087&view=rev
Log:
Change the Pipe so it contains both descriptors

Added:
    commons/sandbox/runtime/trunk/xdocs/index.xml   (with props)
Modified:
    commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/io/Pipe.java
    commons/sandbox/runtime/trunk/src/main/native/include/acr_pipe.h
    commons/sandbox/runtime/trunk/src/main/native/os/unix/pipe.c
    commons/sandbox/runtime/trunk/src/main/native/os/win32/pipe.c

Modified: commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/io/Pipe.java
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/io/Pipe.java?rev=884087&r1=884086&r2=884087&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/io/Pipe.java (original)
+++ commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/io/Pipe.java Wed Nov 25 13:17:25 2009
@@ -44,13 +44,10 @@
 public final class Pipe implements Device, Syncable
 {
 
-    static private final int RD = 0x0100;
-    static private final int WR = 0x0200;
-
-    private Descriptor fd;
-    private String     name;
-    private PipeIoMode mode;
-    private int        type;
+    private Descriptor   rd;
+    private Descriptor   wr;
+    private String       name;
+    private PipeIoMode   mode;
     private Pipe()
     {
         // No instance
@@ -60,13 +57,12 @@
      * Create new Pipe instance.
      * This constructor is called only from native.
      */
-    private Pipe(Descriptor fd, String name, int type)
+    private Pipe(Descriptor rd, Descriptor wr, String name, int mode)
     {
-        this.fd   = fd;
+        this.rd   = rd;
+        this.wr   = wr;
         this.name = name;
-        this.type = type;
-
-        mode = PipeIoMode.valueOf(type & 0xff);
+        this.mode = PipeIoMode.valueOf(mode & 0xFF);
     }
 
     synchronized PipeIoMode getMode()
@@ -92,10 +88,10 @@
      */
     public Descriptor fd()
     {
-        return fd;
+        return rd;
     }
 
-    public static native Pipe[] create0(int mode)
+    public static native Pipe create0(int mode)
         throws IOException;
     /**
      * Creates a pipe, a unidirectional data channel that can be used
@@ -110,7 +106,7 @@
      * read end of the pipe.
      * </p>
      */
-    public Pipe[] create(PipeIoMode mode)
+    public Pipe create(PipeIoMode mode)
         throws IOException
     {
         return create0(mode.valueOf());
@@ -134,28 +130,14 @@
     {
         if (!valid())
             throw new ClosedDescriptorException();
-        return blocking0(fd.fd());
+        return blocking0(rd.fd());
     }
 
     @Override
     public boolean valid()
     {
-        if (fd != null)
-            return fd.valid();
-        else
-            return false;
-    }
-
-    /**
-     * Test if this {@code Pipe} is write end of this pipe
-     * channel.
-     * @return {@code true} if {@code this} pipe instance is write end
-     *                      of the pipe channel.
-     */
-    public final boolean isWriteEnd()
-    {
-        if ((type & WR) == WR)
-            return true;
+        if (rd != null && wr != null)
+            return rd.valid() && wr.valid();
         else
             return false;
     }
@@ -169,7 +151,8 @@
     public final void close()
         throws IOException
     {
-        fd.close();
+        rd.close();
+        wr.close();
     }
 
     /**
@@ -190,7 +173,7 @@
     public final void flush()
         throws SyncFailedException, IOException
     {
-        fd.flush();
+        wr.flush();
     }
 
     /**
@@ -211,7 +194,7 @@
     public final void sync()
         throws SyncFailedException, IOException
     {
-        fd.sync();
+        wr.sync();
     }
 
     private static native int tmget0(int fd)
@@ -224,7 +207,7 @@
     {
         if (!valid())
             throw new ClosedDescriptorException();
-        return tmget0(fd.fd());
+        return tmget0(rd.fd());
     }
 
     private static native int tmset0(int fd, int timeout)
@@ -237,8 +220,9 @@
     {
         if (!valid())
             throw new ClosedDescriptorException();
-        int rc = tmset0(fd.fd(), timeout);
-        return rc == 0 ? true : false;
+        int rc = tmset0(rd.fd(), timeout);
+        int wc = tmset0(wr.fd(), timeout);
+        return rc + wc == 0 ? true : false;
     }
 
 }

Modified: commons/sandbox/runtime/trunk/src/main/native/include/acr_pipe.h
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/include/acr_pipe.h?rev=884087&r1=884086&r2=884087&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/include/acr_pipe.h (original)
+++ commons/sandbox/runtime/trunk/src/main/native/include/acr_pipe.h Wed Nov 25 13:17:25 2009
@@ -45,7 +45,7 @@
  * Create new Pipe object.
  */
 ACR_DECLARE(jobject) ACR_NewPipeObject(JNIEnv *env, int type,
-                                       jobject desc,
+                                       jobject rd, jobject wr,
                                        const acr_pchar_t *name);
 
 /**

Modified: commons/sandbox/runtime/trunk/src/main/native/os/unix/pipe.c
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/os/unix/pipe.c?rev=884087&r1=884086&r2=884087&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/os/unix/pipe.c (original)
+++ commons/sandbox/runtime/trunk/src/main/native/os/unix/pipe.c Wed Nov 25 13:17:25 2009
@@ -44,7 +44,7 @@
 J_DECLARE_M_ID(0000) = {
     NULL,
     "<init>",
-    "(L" ACR_CLASS_PATH "Descriptor;Ljava/lang/String;I)V"
+    "(L" ACR_CLASS_PATH "Descriptor;L" ACR_CLASS_PATH "Descriptor;Ljava/lang/String;I)V"
 };
 
 ACR_CLASS_LDEF(io_Pipe)
@@ -63,20 +63,13 @@
     ACR_UnloadClass(_E, &_clazzn);
 }
 
-ACR_DECLARE(jobject) ACR_NewPipeObject(JNIEnv *_E, int type, jobject desc,
+ACR_DECLARE(jobject) ACR_NewPipeObject(JNIEnv *_E, int type,
+                                       jobject rd, jobject wr,
                                        const char *pname)
 {
     jstring name;
     if ((name = ACR_NewJavaStringA(_E, pname)))
-        return (*_E)->NewObject(_E, _clazzn.i, J4MID(0000), desc, name, type);
-    else
-        return NULL;
-}
-
-ACR_DECLARE(jobjectArray) ACR_NewPipeArray(JNIEnv *_E, jsize len)
-{
-    if (_clazzn.i)
-        return (*_E)->NewObjectArray(_E, len, _clazzn.i, NULL);
+        return (*_E)->NewObject(_E, _clazzn.i, J4MID(0000), rd, wr, name, type);
     else
         return NULL;
 }
@@ -163,7 +156,6 @@
     int rc =  0;
     int fo;
     int ff = flags & 0xFF;
-    jobject od;
     acr_file_t *fp = NULL;
 
     if (ff == ACR_PIPE_FULL_NONBLOCK ||
@@ -197,19 +189,15 @@
         goto finally;
     }
     /* Create File Descriptor Object */
-    od = ACR_DescriptorCreate(_E, ACR_DT_FILE, fo, NULL,
-                              descriptor_cleanup);
-    if (!od) {
+    *fdo = ACR_DescriptorCreate(_E, ACR_DT_FILE, fo, NULL,
+                                descriptor_cleanup);
+    if (!*fdo) {
         rc = ACR_GET_OS_ERROR();
         goto finally;
     }
     /* Create Pipe object */
     fp->descriptor = (*_E)->NewWeakGlobalRef(_E, *fdo);
-    *fdo = ACR_NewPipeObject(_E, flags, od, NULL);
-    if (!*fdo) {
-        rc = ACR_GET_OS_ERROR();
-        goto finally;
-    }
+
 finally:
     if (rc) {
         if (fp && fp->descriptor)
@@ -222,11 +210,10 @@
     return rc;
 }
 
-ACR_IO_EXPORT_DECLARE(jobjectArray, Pipe, create0)(ACR_JNISTDARGS,
-                                                   jint flags)
+ACR_IO_EXPORT_DECLARE(jobject, Pipe, create0)(ACR_JNISTDARGS,
+                                              jint flags)
 {
     int rc = 0;
-    jobjectArray pa = NULL;
     jobject fd[2];
     int     pd[2] = { -1, -1 };
 
@@ -234,11 +221,6 @@
         ACR_THROW_IO_ERRNO();
         return NULL;
     }
-    pa = ACR_NewPipeArray(_E, 2);
-    if (pa == NULL) {
-        close(pd[0]);
-        close(pd[1]);
-    }
     rc = do_popen(_E, pd[0], flags & ACR_PIPE_RD,  &fd[0]);
     if (rc) {
         goto cleanup;
@@ -250,9 +232,7 @@
         pd[0] = -1;
         goto cleanup;
     }
-    (*_E)->SetObjectArrayElement(_E, pa, 0, fd[0]);
-    (*_E)->SetObjectArrayElement(_E, pa, 1, fd[1]);
-    return pa;
+    return ACR_NewPipeObject(_E, flags, fd[0], fd[1], NULL);
 
 cleanup:
     if (pd[0] != -1)

Modified: commons/sandbox/runtime/trunk/src/main/native/os/win32/pipe.c
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/os/win32/pipe.c?rev=884087&r1=884086&r2=884087&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/os/win32/pipe.c (original)
+++ commons/sandbox/runtime/trunk/src/main/native/os/win32/pipe.c Wed Nov 25 13:17:25 2009
@@ -41,7 +41,7 @@
 J_DECLARE_M_ID(0000) = {
     NULL,
     "<init>",
-    "(L" ACR_CLASS_PATH "Descriptor;Ljava/lang/String;I)V"
+    "(L" ACR_CLASS_PATH "Descriptor;L" ACR_CLASS_PATH "Descriptor;Ljava/lang/String;I)V"
 };
 
 ACR_CLASS_LDEF(io_Pipe)
@@ -429,41 +429,28 @@
     ACR_UnloadClass(_E, &_clazzn);
 }
 
-ACR_DECLARE(jobject) ACR_NewPipeObject(JNIEnv *_E, int type, jobject desc,
+ACR_DECLARE(jobject) ACR_NewPipeObject(JNIEnv *_E, int type,
+                                       jobject rd, jobject wr,
                                        const wchar_t *pname)
 {
     jstring name;
     if ((name = ACR_NewJavaStringW(_E, pname)))
-        return (*_E)->NewObject(_E, _clazzn.i, J4MID(0000), desc, name, type);
+        return (*_E)->NewObject(_E, _clazzn.i, J4MID(0000), rd, wr, name, type);
     else
         return NULL;
 }
 
-ACR_DECLARE(jobjectArray) ACR_NewPipeArray(JNIEnv *_E, jsize len)
-{
-    if (_clazzn.i)
-        return (*_E)->NewObjectArray(_E, len, _clazzn.i, NULL);
-    else
-        return NULL;
-}
-
-ACR_IO_EXPORT_DECLARE(jobjectArray, Pipe, create0)(ACR_JNISTDARGS,
-                                                   jint flags)
+ACR_IO_EXPORT_DECLARE(jobject, Pipe, create0)(ACR_JNISTDARGS,
+                                              jint flags)
 {
     int rc = 0;
-    jobjectArray pa = NULL;
-    jobject      fd[2];
-    acr_file_t  *pd[2] = { NULL, NULL };
+    jobject     fd[2];
+    acr_file_t *pd[2] = { NULL, NULL };
 
     if ((rc = create_pipepair(_E, &pd[0], &pd[1], flags))) {
         ACR_THROW_IO_IF_ERR(rc);
         return NULL;
     }
-    pa = ACR_NewPipeArray(_E, 2);
-    if (pa == NULL) {
-        file_cleanup(pd[0], ACR_DT_FILE, ACR_IOH_CLEAR);
-        file_cleanup(pd[1], ACR_DT_FILE, ACR_IOH_CLEAR);
-    }
     rc = do_popen(_E, pd[0], flags & ACR_PIPE_RD,  &fd[0]);
     if (rc) {
         goto cleanup;
@@ -475,9 +462,7 @@
         pd[0] = NULL;
         goto cleanup;
     }
-    (*_E)->SetObjectArrayElement(_E, pa, 0, fd[0]);
-    (*_E)->SetObjectArrayElement(_E, pa, 1, fd[1]);
-    return pa;
+    return ACR_NewPipeObject(_E, flags, fd[0], fd[1], NULL);
 
 cleanup:
     if (pd[0])

Added: commons/sandbox/runtime/trunk/xdocs/index.xml
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/xdocs/index.xml?rev=884087&view=auto
==============================================================================
--- commons/sandbox/runtime/trunk/xdocs/index.xml (added)
+++ commons/sandbox/runtime/trunk/xdocs/index.xml Wed Nov 25 13:17:25 2009
@@ -0,0 +1,37 @@
+<?xml version="1.0"?>
+<!--
+  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.
+-->
+<document>
+
+<properties>
+  <title>Home</title>
+  <author email="mturk@apache.org">Mladen Turk</author>
+</properties>
+
+<body>
+<section name="Apache Commons Runtime">
+<p>In today's world Java&trade; is used mainly to develop server based
+application. On the other hand Java&trade; doesn't offer API that
+can fully benefit from the features most modern operating systems provide.
+</p>
+
+</section>
+
+</body>
+</document>

Propchange: commons/sandbox/runtime/trunk/xdocs/index.xml
------------------------------------------------------------------------------
    svn:eol-style = native