[PATCH]: java.net.DatagramSocket implementation
Warren Levy
warrenl@cygnus.com
Tue Jul 20 13:32:00 GMT 1999
Folks,
I've checked into the main libgcj trunk in Sourceware (i.e. *not* the
2.95 branch), the following patch. It more properly deals with exception
handling and will be necessary for an upcoming patch to the compiler.
--warrenl
1999-07-20 Warren Levy <warrenl@cygnus.com>
* java/net/DatagramSocket.java (DatagramSocket(int, InetAddress)):
Default to using PlainDatagramSocketImpl.
* java/net/PlainDatagramSocketImpl.java (close): Catch IOException.
Index: java/net/DatagramSocket.java
===================================================================
RCS file: /cvs/java/libgcj/libjava/java/net/DatagramSocket.java,v
retrieving revision 1.3
diff -u -p -r1.3 DatagramSocket.java
--- DatagramSocket.java 1999/05/28 19:29:46 1.3
+++ DatagramSocket.java 1999/07/20 20:20:28
@@ -47,9 +47,19 @@ public class DatagramSocket
String propVal = System.getProperty("impl.prefix");
if (propVal == null || propVal.equals(""))
- propVal = "Plain";
- impl = (DatagramSocketImpl) Class.forName("java.net." + propVal +
+ impl = new PlainDatagramSocketImpl();
+ else
+ try
+ {
+ impl = (DatagramSocketImpl) Class.forName("java.net." + propVal +
"DatagramSocketImpl").newInstance();
+ }
+ catch (Exception e)
+ {
+ System.err.println("Could not instantiate class: java.net." +
+ propVal + "DatagramSocketImpl");
+ impl = new PlainDatagramSocketImpl();
+ }
impl.create();
// For multicasting, set the socket to be reused (Stevens pp. 195-6).
Index: java/net/PlainDatagramSocketImpl.java
===================================================================
RCS file: /cvs/java/libgcj/libjava/java/net/PlainDatagramSocketImpl.java,v
retrieving revision 1.5
diff -u -p -r1.5 PlainDatagramSocketImpl.java
--- PlainDatagramSocketImpl.java 1999/07/02 04:25:04 1.5
+++ PlainDatagramSocketImpl.java 1999/07/20 20:20:28
@@ -68,9 +68,24 @@ class PlainDatagramSocketImpl extends Da
private native void mcastGrp(InetAddress inetaddr, boolean join)
throws IOException;
- protected void close() throws IOException
+ protected void close()
{
- fd.close();
+ // FIXME: The close method in each of the DatagramSocket* classes does
+ // not throw an IOException. The issue is that FileDescriptor.close()
+ // in natFileDescriptorPosix.cc can throw one, so we have to catch
+ // it here. It seems that FileDescriptor.close is properly throwing
+ // the IOException on errors since many of the java.io classes depend
+ // on that. This probably requires a bit more research but for now,
+ // we'll catch the IOException here.
+ try
+ {
+ fd.close();
+ }
+ catch (IOException e)
+ {
+ System.err.println("PlainDatagramSocketImpl.close: Error closing - " +
+ e.getMessage());
+ }
}
// Deprecated in JDK 1.2.
More information about the Java-patches
mailing list