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 2011/06/03 07:34:33 UTC
svn commit: r1130897 - in /commons/sandbox/runtime/trunk/src/main:
java/org/apache/commons/runtime/io/ java/org/apache/commons/runtime/net/
native/include/acr/ native/os/unix/ native/shared/
Author: mturk
Date: Fri Jun 3 05:34:33 2011
New Revision: 1130897
URL: http://svn.apache.org/viewvc?rev=1130897&view=rev
Log:
Add two more nonblocking op exceptions
Added:
commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/io/OperationInProgressException.java (with props)
commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/io/OperationWouldBlockException.java (with props)
Modified:
commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/net/Poll.java
commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/net/SelectionKey.java
commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/net/SelectionOps.java
commons/sandbox/runtime/trunk/src/main/native/include/acr/error.h
commons/sandbox/runtime/trunk/src/main/native/include/acr/iodefs.h
commons/sandbox/runtime/trunk/src/main/native/os/unix/poll.c
commons/sandbox/runtime/trunk/src/main/native/os/unix/selector.c
commons/sandbox/runtime/trunk/src/main/native/os/unix/usock.c
commons/sandbox/runtime/trunk/src/main/native/shared/error.c
Added: commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/io/OperationInProgressException.java
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/io/OperationInProgressException.java?rev=1130897&view=auto
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/io/OperationInProgressException.java (added)
+++ commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/io/OperationInProgressException.java Fri Jun 3 05:34:33 2011
@@ -0,0 +1,40 @@
+/* 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.
+ */
+
+package org.apache.commons.runtime.io;
+import java.io.IOException;
+
+/**
+ * OperationInProgressException is thrown when an attempt is made to
+ * invoke an operation on a nonblocking {@code Descriptor} and
+ * the operation cannot be completed immediately.
+ * This class mimics the os {@code EINPROGRESS} error.
+ *
+ * @since Runtime 1.0
+ */
+public class OperationInProgressException extends IOException
+{
+
+ public OperationInProgressException()
+ {
+ super();
+ }
+
+ public OperationInProgressException(String msg)
+ {
+ super(msg);
+ }
+}
Propchange: commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/io/OperationInProgressException.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/io/OperationWouldBlockException.java
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/io/OperationWouldBlockException.java?rev=1130897&view=auto
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/io/OperationWouldBlockException.java (added)
+++ commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/io/OperationWouldBlockException.java Fri Jun 3 05:34:33 2011
@@ -0,0 +1,40 @@
+/* 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.
+ */
+
+package org.apache.commons.runtime.io;
+import java.io.IOException;
+
+/**
+ * OperationWouldBlockException is thrown when an attempt is made to
+ * invoke an operation on a nonblocking {@code Descriptor} and
+ * the operation would block.
+ * This class mimics the os {@code EWOULDBLOCK} or {@code EAGAIN} error.
+ *
+ * @since Runtime 1.0
+ */
+public class OperationWouldBlockException extends IOException
+{
+
+ public OperationWouldBlockException()
+ {
+ super();
+ }
+
+ public OperationWouldBlockException(String msg)
+ {
+ super(msg);
+ }
+}
Propchange: commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/io/OperationWouldBlockException.java
------------------------------------------------------------------------------
svn:eol-style = native
Modified: commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/net/Poll.java
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/net/Poll.java?rev=1130897&r1=1130896&r2=1130897&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/net/Poll.java (original)
+++ commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/net/Poll.java Fri Jun 3 05:34:33 2011
@@ -37,15 +37,15 @@ public final class Poll
*/
public static final short POLLIN = 0x0001;
/**
+ * Writing now will not block.
+ */
+ public static final short POLLOUT = 0x0004;
+ /**
* There is urgent data to read.
* e.g., out-of-band data on TCP socket; pseudo-terminal master in packet mode
* has seen state change in slave.
*/
- public static final short POLLPRI = 0x0008;
- /**
- * Writing now will not block.
- */
- public static final short POLLOUT = 0x0010;
+ public static final short POLLPRI = 0x0010;
/**
* A Stream socket peer closed connection, or shut down writing half of connection.
*/
Modified: commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/net/SelectionKey.java
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/net/SelectionKey.java?rev=1130897&r1=1130896&r2=1130897&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/net/SelectionKey.java (original)
+++ commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/net/SelectionKey.java Fri Jun 3 05:34:33 2011
@@ -32,26 +32,26 @@ public abstract class SelectionKey
private Object attachment;
private int timeout;
- /** Accept operation.
+ /** Read operation.
* <p>
* </p>
*/
- public static final int OP_ACCEPT = 0x0001;
- /** Connect operation.
+ public static final int OP_READ = 0x0001;
+ /** Accept operation.
* <p>
* </p>
*/
- public static final int OP_CONNECT = 0x0002;
- /** Read operation.
+ public static final int OP_ACCEPT = 0x0002;
+ /** Write operation.
* <p>
* </p>
*/
- public static final int OP_READ = 0x0004;
- /** Write operation.
+ public static final int OP_WRITE = 0x0004;
+ /** Connect operation.
* <p>
* </p>
*/
- public static final int OP_WRITE = 0x0008;
+ public static final int OP_CONNECT = 0x0008;
/**
* Constructs a new {@code SelectionKey} for given selector and enpoint
Modified: commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/net/SelectionOps.java
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/net/SelectionOps.java?rev=1130897&r1=1130896&r2=1130897&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/net/SelectionOps.java (original)
+++ commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/net/SelectionOps.java Fri Jun 3 05:34:33 2011
@@ -27,26 +27,26 @@ final class SelectionOps
// No Instance
}
- /** Accept operation.
+ /** Read operation.
* <p>
* </p>
*/
- public static final int ACCEPT = 0x0001;
- /** Connect operation.
+ public static final int READ = 0x0001;
+ /** Accept operation.
* <p>
* </p>
*/
- public static final int CONNECT = 0x0002;
- /** Read operation.
+ public static final int ACCEPT = 0x0002;
+ /** Write operation.
* <p>
* </p>
*/
- public static final int READ = 0x0004;
- /** Write operation.
+ public static final int WRITE = 0x0004;
+ /** Connect operation.
* <p>
* </p>
*/
- public static final int WRITE = 0x0008;
+ public static final int CONNECT = 0x0008;
/** There is urgent data to read.
* <p>
* </p>
Modified: commons/sandbox/runtime/trunk/src/main/native/include/acr/error.h
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/include/acr/error.h?rev=1130897&r1=1130896&r2=1130897&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/include/acr/error.h (original)
+++ commons/sandbox/runtime/trunk/src/main/native/include/acr/error.h Fri Jun 3 05:34:33 2011
@@ -54,6 +54,8 @@ enum {
ACR_EX_ENOENT, /* NoSuchObjectException */
ACR_EX_ENOTIMPL, /* OperationNotImplementedException */
ACR_EX_EPERM, /* OperationNotPermittedException */
+ ACR_EX_EINPROGRESS, /* OperationInProgressException */
+ ACR_EX_EWOULDBLOCK, /* OperationWouldBlockException */
ACR_EX_TIMEOUT, /* TimeoutException */
ACR_EX_ESYS, /* SystemException */
ACR_EX_ENET, /* NetworkException */
Modified: commons/sandbox/runtime/trunk/src/main/native/include/acr/iodefs.h
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/include/acr/iodefs.h?rev=1130897&r1=1130896&r2=1130897&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/include/acr/iodefs.h (original)
+++ commons/sandbox/runtime/trunk/src/main/native/include/acr/iodefs.h Fri Jun 3 05:34:33 2011
@@ -35,11 +35,12 @@
#define ACR_FOPEN_NOINHERIT 0x010000 /**< Do not inherit files on exec */
#define ACR_FOPEN_INFO 0x020000 /**< Open without READ or WRITE access */
-#define ACR_OP_ACCEPT 0x0001
-#define ACR_OP_CONNECT 0x0002
-#define ACR_OP_READ 0x0004
-#define ACR_OP_INP 0x0007 /**< ACCEPT|CONNECT|READ */
-#define ACR_OP_WRITE 0x0008
+#define ACR_OP_READ 0x0001
+#define ACR_OP_ACCEPT 0x0002
+#define ACR_OP_WRITE 0x0004
+#define ACR_OP_CONNECT 0x0008
+#define ACR_OP_INP 0x0003 /**< ACCEPT|READ */
+#define ACR_OP_OUT 0x000C /**< CONNECT|WRITE */
#define ACR_OP_PRI 0x0010
#define ACR_OP_RDHUP 0x0020
#define ACR_OP_HANGUP 0x0040
Modified: commons/sandbox/runtime/trunk/src/main/native/os/unix/poll.c
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/os/unix/poll.c?rev=1130897&r1=1130896&r2=1130897&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/os/unix/poll.c (original)
+++ commons/sandbox/runtime/trunk/src/main/native/os/unix/poll.c Fri Jun 3 05:34:33 2011
@@ -33,10 +33,10 @@ static short ieventt(int event)
if (event & ACR_OP_INP)
rv |= POLLIN;
+ if (event & ACR_OP_OUT)
+ rv |= POLLOUT;
if (event & ACR_OP_PRI)
rv |= POLLPRI;
- if (event & ACR_OP_WRITE)
- rv |= POLLOUT;
/* POLLERR, POLLHUP, and POLLNVAL aren't valid as requested events
*/
return rv;
@@ -48,10 +48,10 @@ static short reventt(short event)
if (event & POLLIN)
rv |= ACR_OP_INP;
+ if (event & POLLOUT)
+ rv |= ACR_OP_OUT;
if (event & POLLPRI)
rv |= ACR_OP_PRI;
- if (event & POLLOUT)
- rv |= ACR_OP_WRITE;
if (event & POLLERR)
rv |= ACR_OP_ERROR;
if (event & POLLHUP)
Modified: commons/sandbox/runtime/trunk/src/main/native/os/unix/selector.c
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/os/unix/selector.c?rev=1130897&r1=1130896&r2=1130897&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/os/unix/selector.c (original)
+++ commons/sandbox/runtime/trunk/src/main/native/os/unix/selector.c Fri Jun 3 05:34:33 2011
@@ -56,7 +56,7 @@ static short ieventt(int event)
if (event & ACR_OP_INP)
rv |= POLLIN;
- if (event & ACR_OP_WRITE)
+ if (event & ACR_OP_OUT)
rv |= POLLOUT;
if (event & ACR_OP_PRI)
rv |= POLLPRI;
@@ -72,7 +72,7 @@ static short reventt(short event)
if (event & POLLIN)
rv |= ACR_OP_INP;
if (event & POLLOUT)
- rv |= ACR_OP_WRITE;
+ rv |= ACR_OP_OUT;
if (event & POLLPRI)
rv |= ACR_OP_PRI;
if (event & POLLERR)
Modified: commons/sandbox/runtime/trunk/src/main/native/os/unix/usock.c
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/os/unix/usock.c?rev=1130897&r1=1130896&r2=1130897&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/os/unix/usock.c (original)
+++ commons/sandbox/runtime/trunk/src/main/native/os/unix/usock.c Fri Jun 3 05:34:33 2011
@@ -54,6 +54,25 @@ ACR_NET_EXPORT(jint, LocalEndpoint, nonb
return AcrNonblock(fd, on);
}
+ACR_NET_EXPORT(jint, LocalEndpoint, connect0)(JNI_STDARGS, jint fd,
+ jbyteArray aa)
+{
+ int sd;
+ acr_sockaddr_t *sa = SOCKADDR_CAST(aa);
+
+ do {
+ /* Restartable connect */
+ sd = connect(fd, (const struct sockaddr *)&sa->sa, sa->salen);
+ } while (sd == -1 && errno == EINTR);
+
+ if (sd == -1) {
+ ACR_THROW_NET_ERRNO();
+ return -1;
+ }
+ SOCKADDR_RELEASE(aa, sa);
+ return sd;
+}
+
ACR_NET_EXPORT(jint, LocalServerEndpoint, bind0)(JNI_STDARGS, jint fd,
jbyteArray aa,
jint backlog)
Modified: commons/sandbox/runtime/trunk/src/main/native/shared/error.c
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/shared/error.c?rev=1130897&r1=1130896&r2=1130897&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/shared/error.c (original)
+++ commons/sandbox/runtime/trunk/src/main/native/shared/error.c Fri Jun 3 05:34:33 2011
@@ -36,8 +36,8 @@ static struct {
{ 0, "java/lang/OutOfMemoryError" }, /* ENOMEM */
{ 0, "java/lang/NullPointerException" }, /* EISNULL */
{ 0, "java/lang/UnsupportedOperationException" }, /* ENOSYS */
- { 0, "java/io/IOException" }, /* I/O Error */
- { 0, "java/net/SocketException" }, /* Net Error */
+ { 0, "java/io/IOException" }, /* EX_EIO */
+ { 0, "java/net/SocketException" }, /* EX_ESOCK */
{ 0, ACR_IO_CP "InvalidDescriptorException" }, /* EBADF */
{ 0, ACR_CLASS_PATH "AccessDeniedException" }, /* EACCESS */
@@ -48,9 +48,11 @@ static struct {
{ 0, ACR_CLASS_PATH "NoSuchObjectException" }, /* ENOENT */
{ 0, ACR_CLASS_PATH "OperationNotImplementedException" }, /* ENOTIMPL */
{ 0, ACR_CLASS_PATH "OperationNotPermittedException" }, /* EPERM */
+ { 0, ACR_IO_CP "OperationInProgressException" }, /* EINPROGRESS */
+ { 0, ACR_IO_CP "OperationWouldBlockException" }, /* EWOULDBLOCK */
{ 0, ACR_CLASS_PATH "TimeoutException" }, /* ETIMEOUT */
- { 0, ACR_CLASS_PATH "SystemException" },
- { 0, ACR_NET_CP "NetworkException" },
+ { 0, ACR_CLASS_PATH "SystemException" }, /* EX_ESYS */
+ { 0, ACR_NET_CP "NetworkException" }, /* EX_ENET */
{ 0, ACR_CLASS_PATH "OverflowException" } /* EOVERFLOW */
};
@@ -760,6 +762,10 @@ AcrThrowByError(JNI_STDENV, int def, int
cls = ACR_EX_ENOMEM;
else if (ACR_STATUS_IS_EINVAL(err))
cls = ACR_EX_EINVAL;
+ else if (ACR_STATUS_IS_EINPROGRESS(err))
+ cls = ACR_EX_EINPROGRESS;
+ else if (ACR_STATUS_IS_EAGAIN(err))
+ cls = ACR_EX_EWOULDBLOCK;
else if (ACR_STATUS_IS_TIMEUP(err))
cls = ACR_EX_TIMEOUT;
else if (err == ACR_EPERM)