Author: mturk
Date: Sat Jul 16 12:15:27 2011
New Revision: 1147414
URL: http://svn.apache.org/viewvc?rev=1147414&view=rev
Log:
Add accept and connect specific exceptions that users can use to continue the
normal operation. Still has to be reviewed fully
Added:
commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/OutOfResourcesException.java
(with props)
commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/net/ConnectionAbortedException.java
(with props)
commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/net/ConnectionResetException.java
(with props)
Modified:
commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/net/ClosedSelectorException.java
commons/sandbox/runtime/trunk/src/main/native/include/acr/error.h
commons/sandbox/runtime/trunk/src/main/native/os/win32/localsock.c
commons/sandbox/runtime/trunk/src/main/native/os/win32/sockopts.c
commons/sandbox/runtime/trunk/src/main/native/shared/error.c
Added:
commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/OutOfResourcesException.java
URL:
http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/OutOfResourcesException.java?rev=1147414&view=auto
==============================================================================
---
commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/OutOfResourcesException.java
(added)
+++
commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/OutOfResourcesException.java
Sat Jul 16 12:15:27 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;
+
+/**
+ * OutOfResourcesException thrown when operating system has reached
+ * resource allocation limit.
+ * This class mimics the os {@code EMFILE} or {@code ENOBUFS} error.
+ * Application should usually retry the operation after some sleep.
+ *
+ * @since Runtime 1.0
+ */
+
+public class OutOfResourcesException extends SystemException
+{
+
+ public OutOfResourcesException()
+ {
+ super();
+ }
+
+ public OutOfResourcesException(String msg)
+ {
+ super(msg);
+ }
+}
Propchange:
commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/OutOfResourcesException.java
------------------------------------------------------------------------------
svn:eol-style = native
Modified:
commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/net/ClosedSelectorException.java
URL:
http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/net/ClosedSelectorException.java?rev=1147414&r1=1147413&r2=1147414&view=diff
==============================================================================
---
commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/net/ClosedSelectorException.java
(original)
+++
commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/net/ClosedSelectorException.java
Sat Jul 16 12:15:27 2011
@@ -16,15 +16,13 @@
package org.apache.commons.runtime.net;
-import java.io.IOException;
-
/**
* An {@code ClosedSelectorException} is thrown when an operation is invoked
* on a closed selector.
*
* @since Runtime 1.0
*/
-public class ClosedSelectorException extends IOException
+public class ClosedSelectorException extends NetworkException
{
public ClosedSelectorException()
Added:
commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/net/ConnectionAbortedException.java
URL:
http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/net/ConnectionAbortedException.java?rev=1147414&view=auto
==============================================================================
---
commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/net/ConnectionAbortedException.java
(added)
+++
commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/net/ConnectionAbortedException.java
Sat Jul 16 12:15:27 2011
@@ -0,0 +1,41 @@
+/* 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.net;
+
+import java.net.SocketException;
+
+/**
+ * ConnectionAbortedException is thrown when the connection
+ * has been aborted.
+ * This class mimics the os {@code ECONNABORTED} error.
+ *
+ * @since Runtime 1.0
+ */
+
+public class ConnectionAbortedException extends SocketException
+{
+
+ public ConnectionAbortedException()
+ {
+ super();
+ }
+
+ public ConnectionAbortedException(String msg)
+ {
+ super(msg);
+ }
+}
Propchange:
commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/net/ConnectionAbortedException.java
------------------------------------------------------------------------------
svn:eol-style = native
Added:
commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/net/ConnectionResetException.java
URL:
http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/net/ConnectionResetException.java?rev=1147414&view=auto
==============================================================================
---
commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/net/ConnectionResetException.java
(added)
+++
commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/net/ConnectionResetException.java
Sat Jul 16 12:15:27 2011
@@ -0,0 +1,41 @@
+/* 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.net;
+
+import java.net.SocketException;
+
+/**
+ * An incomming connection was indicated, but was subsequently
+ * terminated by the remote peer prior to accepting the call.
+ * This class mimics the os {@code ECONNRESET} error.
+ *
+ * @since Runtime 1.0
+ */
+
+public class ConnectionResetException extends SocketException
+{
+
+ public ConnectionResetException()
+ {
+ super();
+ }
+
+ public ConnectionResetException(String msg)
+ {
+ super(msg);
+ }
+}
Propchange:
commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/net/ConnectionResetException.java
------------------------------------------------------------------------------
svn:eol-style = native
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=1147414&r1=1147413&r2=1147414&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 Sat Jul
16 12:15:27 2011
@@ -61,6 +61,9 @@ enum {
ACR_EX_ESYS, /* SystemException */
ACR_EX_ENET, /* NetworkException */
ACR_EX_EOVERFLOW, /* OverflowException */
+ ACR_EX_ENOBUFS, /* OutOfResourcesException */
+ ACR_EX_ECONNABORTED, /* ConnectionAbortedException */
+ ACR_EX_ECONNRESET, /* ConnectionResetException */
ACR_EX_LEN
};
@@ -1429,7 +1432,9 @@ ACR_INLINE(DWORD) AcrNetOsError()
|| (s) == ERROR_NOT_ENOUGH_QUOTA \
|| (s) == ERROR_OUTOFMEMORY)
#define ACR_STATUS_IS_EMFILE(s) ((s) == ACR_EMFILE \
- || (s) == ERROR_TOO_MANY_OPEN_FILES)
+ || (s) == ERROR_TOO_MANY_OPEN_FILES \
+ || (s) == WSAENOBUFS \
+ || (s) == WSAEMFILE)
#define ACR_STATUS_IS_ENFILE(s) ((s) == ACR_ENFILE)
#define ACR_STATUS_IS_EBADF(s) ((s) == ACR_EBADF \
|| (s) == ERROR_INVALID_HANDLE \
Modified: commons/sandbox/runtime/trunk/src/main/native/os/win32/localsock.c
URL:
http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/os/win32/localsock.c?rev=1147414&r1=1147413&r2=1147414&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/os/win32/localsock.c
(original)
+++ commons/sandbox/runtime/trunk/src/main/native/os/win32/localsock.c Sat Jul
16 12:15:27 2011
@@ -207,14 +207,17 @@ ACR_NET_EXPORT(jlong, LocalServerEndpoin
memset(&sa, 0, sizeof(sa));
ad = AcrSdRetain(fd);
- sd = accept(ad, 0, 0);
+ sd = accept(ad, 0, 0);
if (AcrSdRelease(fd) == 0 && sd != INVALID_SOCKET) {
/* XXX: Can this happen ? */
sd = INVALID_SOCKET;
WSASetLastError(WSAENOTSOCK);
}
if (sd == INVALID_SOCKET) {
- ACR_THROW_NET_ERRNO();
+ int rc = ACR_GET_NETOS_ERROR();
+ if (rc == WSAEMFILE || rc == WSAENOBUFS)
+ rc = ACR_ENOBUFS;
+ ACR_THROW_NET_ERROR(rc);
return 0;
}
if (block == JNI_FALSE) {
Modified: commons/sandbox/runtime/trunk/src/main/native/os/win32/sockopts.c
URL:
http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/os/win32/sockopts.c?rev=1147414&r1=1147413&r2=1147414&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/os/win32/sockopts.c (original)
+++ commons/sandbox/runtime/trunk/src/main/native/os/win32/sockopts.c Sat Jul
16 12:15:27 2011
@@ -61,8 +61,10 @@ ACR_NET_EXPORT(jint, SocketDescriptor, o
case ACR_OPT_SO_LINGER:
{
struct linger li;
+ if (opt > USHRT_MAX)
+ opt = USHRT_MAX;
li.l_onoff = opt == 0 ? 0 : 1;
- li.l_linger = opt;
+ li.l_linger = (u_short)opt;
if (setsockopt(fd->s, SOL_SOCKET, SO_LINGER, (char *)&li,
SSIZEOF(struct linger)) != 0)
return ACR_GET_NETOS_ERROR();
ACR_PUTFLAG(fd, ACR_SO_LINGER, opt);
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=1147414&r1=1147413&r2=1147414&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/shared/error.c (original)
+++ commons/sandbox/runtime/trunk/src/main/native/shared/error.c Sat Jul 16
12:15:27 2011
@@ -54,7 +54,10 @@ static struct {
{ 0, ACR_CLASS_PATH "TimeoutException" }, /* ETIMEOUT
*/
{ 0, ACR_CLASS_PATH "SystemException" }, /* EX_ESYS
*/
{ 0, ACR_NET_CP "NetworkException" }, /* EX_ENET
*/
- { 0, ACR_CLASS_PATH "OverflowException" } /*
EOVERFLOW */
+ { 0, ACR_CLASS_PATH "OverflowException" }, /*
EOVERFLOW */
+ { 0, ACR_CLASS_PATH "OutOfResourcesException" }, /* ENOBUFS
*/
+ { 0, ACR_NET_CP "ConnectionAbortedException" }, /*
ECONNABORTED */
+ { 0, ACR_NET_CP "ConnectionResetException" } /*
ECONNRESET */
};
static const char *const _canon_errors[] = {
@@ -771,6 +774,12 @@ AcrThrowByError(JNI_STDENV, int def, int
cls = ACR_EX_EWOULDBLOCK;
else if (ACR_STATUS_IS_TIMEUP(err))
cls = ACR_EX_TIMEOUT;
+ else if (ACR_STATUS_IS_ECONNRESET(err))
+ cls = ACR_EX_ECONNRESET;
+ else if (ACR_STATUS_IS_ECONNABORTED(err))
+ cls = ACR_EX_ECONNABORTED;
+ else if (err == ACR_EMFILE || err == ACR_ENOBUFS)
+ cls = ACR_EX_ENOBUFS;
else if (err == ACR_EPERM)
cls = ACR_EX_EPERM;
else if (err == ACR_ENOSYS)