Return-Path: X-Original-To: apmail-commons-commits-archive@minotaur.apache.org Delivered-To: apmail-commons-commits-archive@minotaur.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 33C203EF3 for ; Wed, 4 May 2011 09:26:38 +0000 (UTC) Received: (qmail 58640 invoked by uid 500); 4 May 2011 09:26:37 -0000 Delivered-To: apmail-commons-commits-archive@commons.apache.org Received: (qmail 58593 invoked by uid 500); 4 May 2011 09:26:37 -0000 Mailing-List: contact commits-help@commons.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@commons.apache.org Delivered-To: mailing list commits@commons.apache.org Received: (qmail 58586 invoked by uid 99); 4 May 2011 09:26:37 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 04 May 2011 09:26:37 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=5.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 04 May 2011 09:26:34 +0000 Received: by eris.apache.org (Postfix, from userid 65534) id B244D23889C5; Wed, 4 May 2011 09:26:12 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r1099380 - in /commons/sandbox/runtime/trunk/src/main: java/org/apache/commons/runtime/io/ java/org/apache/commons/runtime/net/ native/ native/os/unix/ native/os/win32/ Date: Wed, 04 May 2011 09:26:12 -0000 To: commits@commons.apache.org From: mturk@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20110504092612.B244D23889C5@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: mturk Date: Wed May 4 09:26:12 2011 New Revision: 1099380 URL: http://svn.apache.org/viewvc?rev=1099380&view=rev Log: Add SocketDescriptor Added: commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/net/SocketDescriptor.java (with props) commons/sandbox/runtime/trunk/src/main/native/os/unix/inetsock.c (with props) commons/sandbox/runtime/trunk/src/main/native/os/win32/inetsock.c (with props) Modified: commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/io/Descriptor.java commons/sandbox/runtime/trunk/src/main/native/Makefile.msc.in commons/sandbox/runtime/trunk/src/main/native/Makefile.unx.in commons/sandbox/runtime/trunk/src/main/native/os/unix/usock.c Modified: commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/io/Descriptor.java URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/io/Descriptor.java?rev=1099380&r1=1099379&r2=1099380&view=diff ============================================================================== --- commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/io/Descriptor.java (original) +++ commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/io/Descriptor.java Wed May 4 09:26:12 2011 @@ -33,7 +33,7 @@ import java.io.SyncFailedException; *

* @since Runtime 1.0 */ -public abstract class Descriptor implements Closeable, Syncable +public abstract class Descriptor implements Device, Syncable { /** Operating system descriptor. @@ -113,7 +113,7 @@ public abstract class Descriptor impleme * @return {@code true} if descriptor is valid and not closed * {@code false} otherwise. */ - public boolean valid() + public final boolean valid() { // true if both int is negative or zero // Descriptor is always assured to be above the stderr (#3) @@ -124,10 +124,29 @@ public abstract class Descriptor impleme } /** + * Test wather or not every I/O operation on {@code this} descriptor will + * block until it completes. + * + * @return {@code true} if, and only if, this device + * is in blocking mode. + * + * @throws IOException if an I/O error occurs while determining the + * blocking state. + */ + public boolean isBlocking() + throws IOException + { + // Default implementation presumes that any OS descriptor + // is in blocking state when created. + // This is true both for files and sockets. + return true; + } + + /** * Get underlying Operating system descriptor. * @return operating system descriptor. */ - public int fd() + public final int fd() { return fd; } Added: commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/net/SocketDescriptor.java URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/net/SocketDescriptor.java?rev=1099380&view=auto ============================================================================== --- commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/net/SocketDescriptor.java (added) +++ commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/net/SocketDescriptor.java Wed May 4 09:26:12 2011 @@ -0,0 +1,103 @@ +/* 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.io.Closeable; +import java.io.Flushable; +import java.io.IOException; +import java.io.SyncFailedException; +import java.net.SocketException; +import org.apache.commons.runtime.Status; +import org.apache.commons.runtime.io.ClosedDescriptorException; +import org.apache.commons.runtime.io.Descriptor; + +/** + * Package private Socket Descriptor + * @since Runtime 1.0 + */ +final class SocketDescriptor extends Descriptor +{ + + private boolean blocking = false; + + private static native int close0(int fd); + private static native int sendz0(int fd); + + public SocketDescriptor() + { + } + + public SocketDescriptor(int fd) + { + this.fd = fd; + } + + public void close() + throws IOException + { + if (fd == -1) + throw new ClosedDescriptorException("Socket is already closed"); + int rc = close0(fd); + if (rc != 0) + throw new SocketException(Status.describe(fd)); + } + + public void sync() + throws SyncFailedException, IOException + { + if (fd == -1) + throw new ClosedDescriptorException(); + int rc = sendz0(fd); + if (rc != 0) + throw new SocketException(Status.describe(fd)); + } + + public void flush() + throws SyncFailedException, IOException + { + } + + public boolean isBlocking() + throws IOException + { + return blocking; + } + + /** + * Called by the garbage collector when the object is destroyed. + * The class will free internal resources allocated by the Operating system. + * @see Object#finalize() + * @throws Throwable the {@code Exception} raised by this method. + */ + @Override + protected final void finalize() + throws Throwable + { + if (valid()) { + try { + close(); + } catch (Exception e) { + // Ignore exceptions during close + } + finally { + fd = -1; + } + } + } + + +} Propchange: commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/net/SocketDescriptor.java ------------------------------------------------------------------------------ svn:eol-style = native 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=1099380&r1=1099379&r2=1099380&view=diff ============================================================================== --- commons/sandbox/runtime/trunk/src/main/native/Makefile.msc.in (original) +++ commons/sandbox/runtime/trunk/src/main/native/Makefile.msc.in Wed May 4 09:26:12 2011 @@ -79,6 +79,7 @@ WIN32_SOURCES=\ $(TOPDIR)\os\win32\dso.c \ $(TOPDIR)\os\win32\exec.c \ $(TOPDIR)\os\win32\execmem.c \ + $(TOPDIR)\os\win32\inetsock.c \ $(TOPDIR)\os\win32\init.c \ $(TOPDIR)\os\win32\os.c \ $(TOPDIR)\os\win32\path.c \ Modified: commons/sandbox/runtime/trunk/src/main/native/Makefile.unx.in URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/Makefile.unx.in?rev=1099380&r1=1099379&r2=1099380&view=diff ============================================================================== --- commons/sandbox/runtime/trunk/src/main/native/Makefile.unx.in (original) +++ commons/sandbox/runtime/trunk/src/main/native/Makefile.unx.in Wed May 4 09:26:12 2011 @@ -63,6 +63,7 @@ UNIX_SOURCES=\ $(TOPDIR)/os/unix/dso.c \ $(TOPDIR)/os/unix/exec.c \ $(TOPDIR)/os/unix/execmem.c \ + $(TOPDIR)/os/unix/inetsock.c \ $(TOPDIR)/os/unix/init.c \ $(TOPDIR)/os/unix/platform.c \ $(TOPDIR)/os/unix/posixapi.c \ Added: commons/sandbox/runtime/trunk/src/main/native/os/unix/inetsock.c URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/os/unix/inetsock.c?rev=1099380&view=auto ============================================================================== --- commons/sandbox/runtime/trunk/src/main/native/os/unix/inetsock.c (added) +++ commons/sandbox/runtime/trunk/src/main/native/os/unix/inetsock.c Wed May 4 09:26:12 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. + */ + +#include "acr/jnitypes.h" +#include "acr/error.h" +#include "acr/memory.h" +#include "acr/unsafe.h" +#include "acr/port.h" +#include "arch_opts.h" +#include +#include + +ACR_NET_EXPORT(jint, SocketDescriptor, close0)(JNI_STDARGS, jint fd) +{ + if (r_close(fd) == -1) + return ACR_GET_OS_ERROR(); + else + return 0; +} + +ACR_NET_EXPORT(jint, SocketDescriptor, sync0)(JNI_STDARGS, jint fd) +{ + if (r_write(fd, &fd, 0) == -1) + return ACR_GET_OS_ERROR(); + else + return 0; +} Propchange: commons/sandbox/runtime/trunk/src/main/native/os/unix/inetsock.c ------------------------------------------------------------------------------ svn:eol-style = native 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=1099380&r1=1099379&r2=1099380&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 Wed May 4 09:26:12 2011 @@ -27,10 +27,6 @@ #include #include -#if !HAVE_SYS_UN_H -# error Missing sys/un.h header -#endif - ACR_NET_EXPORT(jstring, LocalSocketAddress, prefix0)(JNI_STDARGS) { return CSTR_TO_JSTRING(VAR_RUN_PATH "/"); Added: commons/sandbox/runtime/trunk/src/main/native/os/win32/inetsock.c URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/os/win32/inetsock.c?rev=1099380&view=auto ============================================================================== --- commons/sandbox/runtime/trunk/src/main/native/os/win32/inetsock.c (added) +++ commons/sandbox/runtime/trunk/src/main/native/os/win32/inetsock.c Wed May 4 09:26:12 2011 @@ -0,0 +1,38 @@ +/* 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/jnitypes.h" +#include "acr/error.h" +#include "acr/memory.h" +#include "acr/unsafe.h" +#include "acr/port.h" +#include "arch_opts.h" + +ACR_NET_EXPORT(jint, SocketDescriptor, close0)(JNI_STDARGS, jint fd) +{ + if (closesocket((SOCKET)fd) == -1) + return ACR_GET_OS_ERROR(); + else + return 0; +} + +ACR_NET_EXPORT(jint, SocketDescriptor, sync0)(JNI_STDARGS, jint fd) +{ + if (send((SOCKET)fd, &fd, 0, 0) == -1) + return ACR_GET_OS_ERROR(); + else + return 0; +} Propchange: commons/sandbox/runtime/trunk/src/main/native/os/win32/inetsock.c ------------------------------------------------------------------------------ svn:eol-style = native