This is the mail archive of the java-patches@gcc.gnu.org mailing list for the Java project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Patch] java.net and java.nio fixes


Hello list,


I will commit the attached patch and new files to fix some issues in 
java.net and add some exceptions to java.nio.


Michael
-- 
Homepage: http://www.worldforge.org/
GPG-key: http://konqueror.dyndns.org/~mkoch/michael.gpg
/* ClosedSelectorException.java -- 
   Copyright (C) 2002 Free Software Foundation, Inc.

This file is part of GNU Classpath.

GNU Classpath is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2, or (at your option)
any later version.

GNU Classpath is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
General Public License for more details.

You should have received a copy of the GNU General Public License
along with GNU Classpath; see the file COPYING.  If not, write to the
Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
02111-1307 USA.

Linking this library statically or dynamically with other modules is
making a combined work based on this library.  Thus, the terms and
conditions of the GNU General Public License cover the whole
combination.

As a special exception, the copyright holders of this library give you
permission to link this library with independent modules to produce an
executable, regardless of the license terms of these independent
modules, and to copy and distribute the resulting executable under
terms of your choice, provided that you also meet, for each linked
independent module, the terms and conditions of the license of that
module.  An independent module is a module which is not derived from
or based on this library.  If you modify this library, you may extend
this exception to your version of the library, but you are not
obligated to do so.  If you do not wish to do so, delete this
exception statement from your version. */

package java.nio.channels;

/**
 * @author Michael Koch
 * @since 1.4
 */
public class ClosedSelectorException extends IllegalStateException
{
  /**
   * Creates the exception
   */
  public ClosedSelectorException()
  {
  }
}
Index: ChangeLog
===================================================================
RCS file: /cvs/gcc/gcc/libjava/ChangeLog,v
retrieving revision 1.1537
diff -b -u -r1.1537 ChangeLog
--- ChangeLog	17 Nov 2002 16:16:51 -0000	1.1537
+++ ChangeLog	18 Nov 2002 13:15:07 -0000
@@ -1,3 +1,14 @@
+2002-11-18  Michael Koch <konqueror@gmx.de>
+
+	* java/net/PlainSocketImpl.java: Reworked imports.
+	* java/net/ServerSocket.java
+	(ServerSocket): Create socket.
+	* java/net/SocketAddress.java: Documentation added.
+	* java/net/natPlainSocketImpl.cc: Reindented.
+	* java/nio/ReadOnlyBufferException.java: New file
+	* java/nio/channels/ClosedChannelException.java: Documentation added.
+	* java/nio/channels/ClosedSelectorException.java: New file.
+
 2002-11-17  Mark Wielaard  <mark@klomp.org>
 
 	* java/net/HttpURLConnection.java ((getPermission): Take port
Index: java/net/PlainSocketImpl.java
===================================================================
RCS file: /cvs/gcc/gcc/libjava/java/net/PlainSocketImpl.java,v
retrieving revision 1.13
diff -b -u -r1.13 PlainSocketImpl.java
--- java/net/PlainSocketImpl.java	10 Sep 2002 18:02:02 -0000	1.13
+++ java/net/PlainSocketImpl.java	18 Nov 2002 13:15:07 -0000
@@ -9,8 +9,8 @@
 details.  */
 
 package java.net;
-import java.io.*;
 
+import java.io.IOException;
 
 /**
  * The standard GCJ socket implementation.
Index: java/net/ServerSocket.java
===================================================================
RCS file: /cvs/gcc/gcc/libjava/java/net/ServerSocket.java,v
retrieving revision 1.16
diff -b -u -r1.16 ServerSocket.java
--- java/net/ServerSocket.java	3 Oct 2002 14:30:48 -0000	1.16
+++ java/net/ServerSocket.java	18 Nov 2002 13:15:07 -0000
@@ -60,16 +60,11 @@
  */
 public class ServerSocket
 {
-
-  // Class Variables
-
   /**
    * This is the user defined SocketImplFactory, if one is supplied
    */
   private static SocketImplFactory factory;
 
-  // Instance Variables
-
   /**
    * This is the SocketImp object to which most instance methods in this
    * class are redirected
@@ -95,6 +90,8 @@
       impl = factory.createSocketImpl();
     else
       impl = new PlainSocketImpl();
+
+    impl.create(true);
   }
 
   /**
Index: java/net/SocketAddress.java
===================================================================
RCS file: /cvs/gcc/gcc/libjava/java/net/SocketAddress.java,v
retrieving revision 1.2
diff -b -u -r1.2 SocketAddress.java
--- java/net/SocketAddress.java	25 Sep 2002 17:14:09 -0000	1.2
+++ java/net/SocketAddress.java	18 Nov 2002 13:15:07 -0000
@@ -37,20 +37,23 @@
 
 package java.net;
 
-import java.io.*;
+import java.io.Serializable;
 
 /** 
  * Abstract base class for InetSocketAddress.
  * InetSocketAddress is to my knowledge the only derived
  * class. [Ronald]
+ *
+ * @since 1.4
  */
-
 public abstract class SocketAddress implements Serializable
 {
   static final long serialVersionUID = 5215720748342549866L;
 
+  /**
+   * Initializes the socket address.
+   */
   public SocketAddress()
   {
   }
 }
-
Index: java/net/natPlainSocketImpl.cc
===================================================================
RCS file: /cvs/gcc/gcc/libjava/java/net/natPlainSocketImpl.cc,v
retrieving revision 1.49
diff -b -u -r1.49 natPlainSocketImpl.cc
--- java/net/natPlainSocketImpl.cc	21 Sep 2002 06:59:20 -0000	1.49
+++ java/net/natPlainSocketImpl.cc	18 Nov 2002 13:15:07 -0000
@@ -259,6 +259,7 @@
 java::net::PlainSocketImpl::create (jboolean stream)
 {
   int sock = ::socket (AF_INET, stream ? SOCK_STREAM : SOCK_DGRAM, 0);
+
   if (sock < 0)
     {
       char* strerr = strerror (errno);
@@ -285,10 +286,12 @@
   if (len == 4)
     {
       u.address.sin_family = AF_INET;
+
       if (host != NULL)
         memcpy (&u.address.sin_addr, bytes, len);
       else
 	u.address.sin_addr.s_addr = htonl (INADDR_ANY);        
+
       len = sizeof (struct sockaddr_in);
       u.address.sin_port = htons (lport);
     }
@@ -311,14 +314,17 @@
     {
       address = host;
       socklen_t addrlen = sizeof(u);
+
       if (lport != 0)
         localport = lport;
       else if (::getsockname (fnum, (sockaddr*) &u, &addrlen) == 0)
         localport = ntohs (u.address.sin_port);
       else
         goto error;
+
       return;
     }
+
  error:
   char* strerr = strerror (errno);
   throw new java::net::BindException (JvNewStringUTF (strerr));
@@ -378,8 +384,8 @@
       if ((retval = _Jv_select (fnum + 1, &rset, NULL, NULL, &tv)) < 0)
 	goto error;
       else if (retval == 0)
-	throw new java::net::SocketTimeoutException ( 
-	         JvNewStringUTF("Connect timed out"));
+        throw new java::net::SocketTimeoutException
+          (JvNewStringUTF ("Connect timed out"));
     }
   else
 #endif
@@ -390,6 +396,7 @@
 
   address = host;
   port = rport;
+
   // A bind may not have been done on this socket; if so, set localport now.
   if (localport == 0)
     {
@@ -398,7 +405,9 @@
       else
 	goto error;
     }
+
   return;  
+
  error:
   char* strerr = strerror (errno);
   throw new java::net::ConnectException (JvNewStringUTF (strerr));
@@ -442,6 +451,7 @@
 #endif /* WIN32 */
 
   new_socket = _Jv_accept (fnum, (sockaddr*) &u, &addrlen);
+
   if (new_socket < 0)
     goto error;
 
@@ -471,6 +481,7 @@
   s->address = new InetAddress (raddr, NULL);
   s->port = rport;
   return;
+
  error:
   char* strerr = strerror (errno);
   throw new java::io::IOException (JvNewStringUTF (strerr));
@@ -537,9 +548,11 @@
 
   jbyte *bytes = elements (b) + offset;
   int written = 0;
+
   while (len > 0)
     {
       int r = ::write (fnum, bytes, len);
+
       if (r == -1)
         {
 	  if (java::lang::Thread::interrupted())
@@ -555,6 +568,7 @@
 	    throw new java::io::IOException (JvNewStringUTF (strerror (errno)));
 	  break;
 	}
+
       written += r;
       len -= r;
       bytes += r;
@@ -604,6 +618,7 @@
 
   if (r == 0)
     return -1;
+
   if (java::lang::Thread::interrupted())
     {
       java::io::InterruptedIOException *iioe =
@@ -617,9 +632,11 @@
       // Some errors cause us to return end of stream...
       if (errno == ENOTCONN)
 	return -1;
+
       // Other errors need to be signalled.
       throw new java::io::IOException (JvNewStringUTF (strerror (errno)));
     }
+
   return b & 0xFF;
 }
 
@@ -629,9 +646,12 @@
 {
   if (! buffer)
     throw new java::lang::NullPointerException;
+
   jsize bsize = JvGetArrayLength (buffer);
+
   if (offset < 0 || count < 0 || offset + count > bsize)
     throw new java::lang::ArrayIndexOutOfBoundsException;
+
   jbyte *bytes = elements (buffer) + offset;
 
 // FIXME: implement timeout support for Win32
@@ -666,8 +686,10 @@
 
   // Read the socket.
   int r = ::recv (fnum, (char *) bytes, count, 0);
+
   if (r == 0)
     return -1;
+
   if (java::lang::Thread::interrupted())
     {
       java::io::InterruptedIOException *iioe =
@@ -681,9 +703,11 @@
       // Some errors cause us to return end of stream...
       if (errno == ENOTCONN)
 	return -1;
+
       // Other errors need to be signalled.
       throw new java::io::IOException (JvNewStringUTF (strerror (errno)));
     }
+
   return r;
 }
 
@@ -698,6 +722,7 @@
 
 #if defined(FIONREAD)
   r = ::ioctl (fnum, FIONREAD, &num);
+
   if (r == -1 && errno == ENOTTY)
     {
       // If the ioctl doesn't work, we don't care.
@@ -718,7 +743,6 @@
     {
     posix_error:
       throw new java::io::IOException(JvNewStringUTF(strerror(errno)));
-
     }
 
   // If we didn't get anything we can use select.
@@ -744,8 +768,7 @@
 #else
   throw new java::io::IOException (JvNewStringUTF ("unimplemented"));
 #endif
- }
-
+}
 
 void
 java::net::PlainSocketImpl::setOption (jint optID, java::lang::Object *value)
@@ -790,8 +813,8 @@
 	    val_len) != 0)
 	  goto error;
 #else
-        throw new java::lang::InternalError (
-          JvNewStringUTF ("TCP_NODELAY not supported"));
+        throw new java::lang::InternalError
+          (JvNewStringUTF ("TCP_NODELAY not supported"));
 #endif /* TCP_NODELAY */
         return;
 
@@ -802,8 +825,8 @@
 	break;
       
       case _Jv_SO_BROADCAST_ :
-        throw new java::net::SocketException (
-          JvNewStringUTF ("SO_BROADCAST not valid for TCP"));
+        throw new java::net::SocketException
+          (JvNewStringUTF ("SO_BROADCAST not valid for TCP"));
 	break;
 	
       case _Jv_SO_OOBINLINE_ :
@@ -817,6 +840,7 @@
         struct linger l_val;
         l_val.l_onoff = (val != -1);
         l_val.l_linger = val;
+
         if (::setsockopt (fnum, SOL_SOCKET, SO_LINGER, (char *) &l_val,
 	    sizeof(l_val)) != 0)
 	  goto error;    
@@ -825,6 +849,7 @@
           JvNewStringUTF ("SO_LINGER not supported"));
 #endif /* SO_LINGER */
         return;
+
       case _Jv_SO_SNDBUF_ :
       case _Jv_SO_RCVBUF_ :
 #if defined(SO_SNDBUF) && defined(SO_RCVBUF)
@@ -837,10 +862,12 @@
           JvNewStringUTF ("SO_RCVBUF/SO_SNDBUF not supported"));
 #endif 
         return;
+
       case _Jv_SO_BINDADDR_ :
         throw new java::net::SocketException (
           JvNewStringUTF ("SO_BINDADDR: read only option"));
         return;
+
       case _Jv_IP_MULTICAST_IF_ :
         throw new java::net::SocketException (
           JvNewStringUTF ("IP_MULTICAST_IF: not valid for TCP"));
@@ -866,9 +893,11 @@
         throw new java::net::SocketException (
           JvNewStringUTF ("SO_REUSEADDR: not valid for TCP"));
         return;
+
       case _Jv_SO_TIMEOUT_ :
 	timeout = val;
         return;
+
       default :
         errno = ENOPROTOOPT;
     }
@@ -898,8 +927,8 @@
         else
 	  return new java::lang::Boolean (val != 0);
 #else
-        throw new java::lang::InternalError (
-          JvNewStringUTF ("TCP_NODELAY not supported"));
+      throw new java::lang::InternalError
+        (JvNewStringUTF ("TCP_NODELAY not supported"));
 #endif       
         break;
 
@@ -908,13 +937,14 @@
         if (::getsockopt (fnum, SOL_SOCKET, SO_LINGER, (char *) &l_val,
 	    &l_val_len) != 0)
 	  goto error;    
+ 
         if (l_val.l_onoff)
           return new java::lang::Integer (l_val.l_linger);
         else
 	  return new java::lang::Boolean ((jboolean)false);
 #else
-        throw new java::lang::InternalError (
-          JvNewStringUTF ("SO_LINGER not supported"));
+      throw new java::lang::InternalError
+        (JvNewStringUTF ("SO_LINGER not supported"));
 #endif
         break;    
 
@@ -947,8 +977,8 @@
         else
 	  return new java::lang::Integer (val);
 #else
-        throw new java::lang::InternalError (
-          JvNewStringUTF ("SO_RCVBUF/SO_SNDBUF not supported"));
+      throw new java::lang::InternalError
+        (JvNewStringUTF ("SO_RCVBUF/SO_SNDBUF not supported"));
 #endif    
 	break;
       case _Jv_SO_BINDADDR_:
@@ -956,8 +986,10 @@
 	if (localAddress == NULL)
 	  {
 	    jbyteArray laddr;
+
 	    if (::getsockname (fnum, (sockaddr*) &u, &addrlen) != 0)
 	      goto error;
+
 	    if (u.address.sin_family == AF_INET)
 	      {
 		laddr = JvNewByteArray (4);
@@ -971,25 +1003,26 @@
 	      }
 #endif
 	    else
-	      throw new java::net::SocketException (
-			      JvNewStringUTF ("invalid family"));
+            throw new java::net::SocketException
+              (JvNewStringUTF ("invalid family"));
 	    localAddress = new java::net::InetAddress (laddr, NULL);
 	  }
+
 	return localAddress;
 	break;
       case _Jv_IP_MULTICAST_IF_ :
-	throw new java::net::SocketException (
-	  JvNewStringUTF ("IP_MULTICAST_IF: not valid for TCP"));
+      throw new java::net::SocketException
+        (JvNewStringUTF ("IP_MULTICAST_IF: not valid for TCP"));
 	break;
 	
       case _Jv_IP_MULTICAST_IF2_ :
-	throw new java::net::SocketException (
-	  JvNewStringUTF ("IP_MULTICAST_IF2: not valid for TCP"));
+      throw new java::net::SocketException
+        (JvNewStringUTF ("IP_MULTICAST_IF2: not valid for TCP"));
 	break;
 	
       case _Jv_IP_MULTICAST_LOOP_ :
-	throw new java::net::SocketException(
-          JvNewStringUTF ("IP_MULTICAST_LOOP: not valid for TCP"));
+      throw new java::net::SocketException
+        (JvNewStringUTF ("IP_MULTICAST_LOOP: not valid for TCP"));
 	break;
 	
       case _Jv_IP_TOS_ :
@@ -1000,12 +1033,14 @@
 	break;
 	
       case _Jv_SO_REUSEADDR_ :
-	throw new java::net::SocketException (
-	  JvNewStringUTF ("SO_REUSEADDR: not valid for TCP"));
+      throw new java::net::SocketException
+        (JvNewStringUTF ("SO_REUSEADDR: not valid for TCP"));
 	break;
+
       case _Jv_SO_TIMEOUT_ :
 	return new java::lang::Integer (timeout);
 	break;
+
       default :
 	errno = ENOPROTOOPT;
     }
Index: java/nio/channels/ClosedChannelException.java
===================================================================
RCS file: /cvs/gcc/gcc/libjava/java/nio/channels/ClosedChannelException.java,v
retrieving revision 1.1
diff -b -u -r1.1 ClosedChannelException.java
--- java/nio/channels/ClosedChannelException.java	7 Oct 2002 07:59:12 -0000	1.1
+++ java/nio/channels/ClosedChannelException.java	18 Nov 2002 13:15:07 -0000
@@ -39,6 +39,10 @@
 
 import java.io.IOException;
 
+/**
+ * @author Michael Koch
+ * @since 1.4
+ */
 public class ClosedChannelException extends IOException
 {
   /**
/* ReadOnlyBufferException.java -- 
   Copyright (C) 2002 Free Software Foundation, Inc.

This file is part of GNU Classpath.

GNU Classpath is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2, or (at your option)
any later version.

GNU Classpath is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
General Public License for more details.

You should have received a copy of the GNU General Public License
along with GNU Classpath; see the file COPYING.  If not, write to the
Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
02111-1307 USA.

Linking this library statically or dynamically with other modules is
making a combined work based on this library.  Thus, the terms and
conditions of the GNU General Public License cover the whole
combination.

As a special exception, the copyright holders of this library give you
permission to link this library with independent modules to produce an
executable, regardless of the license terms of these independent
modules, and to copy and distribute the resulting executable under
terms of your choice, provided that you also meet, for each linked
independent module, the terms and conditions of the license of that
module.  An independent module is a module which is not derived from
or based on this library.  If you modify this library, you may extend
this exception to your version of the library, but you are not
obligated to do so.  If you do not wish to do so, delete this
exception statement from your version. */

package java.nio;

/**
 * @author Michael Koch
 * @since 1.4
 */
public class ReadOnlyBufferException extends UnsupportedOperationException
{
  /**
   * Creates the exception
   */
  public ReadOnlyBufferException ()
  {
  }
}

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]