summaryrefslogtreecommitdiff
path: root/gnu
diff options
context:
space:
mode:
authorMichael Koch <konqueror@gmx.de>2003-10-20 14:10:06 +0000
committerMichael Koch <konqueror@gmx.de>2003-10-20 14:10:06 +0000
commita45e544f75afe6631ff7118ddddfccae8629e96e (patch)
treeb5817518a62abc7f42242cb76e2d02283c92da45 /gnu
parentb28641e4a462be11c3f72acbf154ac2bfbcfffc0 (diff)
downloadclasspath-a45e544f75afe6631ff7118ddddfccae8629e96e.tar.gz
2003-10-20 Michael Koch <konqueror@gmx.de>
* gnu/java/net/PlainDatagramSocketImpl.java (native_fd): Made package-private. (finalize): New method. (getTTL): Call getTimeToLive. (setTTL): Call setTimeToLive. * gnu/java/net/PlainSocketImpl.java (native_fd): Made package-private. (finalize): New method.
Diffstat (limited to 'gnu')
-rw-r--r--gnu/java/net/PlainDatagramSocketImpl.java26
-rw-r--r--gnu/java/net/PlainSocketImpl.java18
2 files changed, 31 insertions, 13 deletions
diff --git a/gnu/java/net/PlainDatagramSocketImpl.java b/gnu/java/net/PlainDatagramSocketImpl.java
index ee86182f6..d7f78660b 100644
--- a/gnu/java/net/PlainDatagramSocketImpl.java
+++ b/gnu/java/net/PlainDatagramSocketImpl.java
@@ -73,7 +73,7 @@ public final class PlainDatagramSocketImpl extends DatagramSocketImpl
System.loadLibrary("javanet");
}
}
-
+
/**
* Option id for the IP_TTL (time to live) value.
*/
@@ -82,7 +82,7 @@ public final class PlainDatagramSocketImpl extends DatagramSocketImpl
/**
* This is the actual underlying file descriptor
*/
- protected int native_fd = -1;
+ int native_fd = -1;
/**
* Lock object to serialize threads wanting to receive
@@ -101,6 +101,16 @@ public final class PlainDatagramSocketImpl extends DatagramSocketImpl
{
}
+ protected void finalize() throws Throwable
+ {
+ synchronized (this)
+ {
+ if (native_fd != -1)
+ close();
+ }
+ super.finalize();
+ }
+
public int getNativeFD()
{
return native_fd;
@@ -248,12 +258,7 @@ public final class PlainDatagramSocketImpl extends DatagramSocketImpl
*/
protected synchronized byte getTTL() throws IOException
{
- Object obj = getOption(IP_TTL);
-
- if (!(obj instanceof Integer))
- throw new IOException("Internal Error");
-
- return(((Integer)obj).byteValue());
+ return (byte) getTimeToLive();
}
/**
@@ -267,10 +272,7 @@ public final class PlainDatagramSocketImpl extends DatagramSocketImpl
*/
protected synchronized void setTTL(byte ttl) throws IOException
{
- if (ttl > 0)
- setOption(IP_TTL, new Integer(ttl));
- else
- setOption(IP_TTL, new Integer(ttl + 256));
+ setTimeToLive(((int) ttl) & 0xFF);
}
/**
diff --git a/gnu/java/net/PlainSocketImpl.java b/gnu/java/net/PlainSocketImpl.java
index 5f7924dd0..3656967c9 100644
--- a/gnu/java/net/PlainSocketImpl.java
+++ b/gnu/java/net/PlainSocketImpl.java
@@ -84,7 +84,7 @@ public final class PlainSocketImpl extends SocketImpl
*
* When the socket is closed this is reset to -1.
*/
- protected int native_fd = -1;
+ int native_fd = -1;
/**
* A cached copy of the in stream for reading from the socket.
@@ -102,6 +102,22 @@ public final class PlainSocketImpl extends SocketImpl
public PlainSocketImpl()
{
}
+
+ protected void finalize() throws Throwable
+ {
+ synchronized (this)
+ {
+ if (native_fd != -1)
+ try
+ {
+ close();
+ }
+ catch (IOException ex)
+ {
+ }
+ }
+ super.finalize();
+ }
public int getNativeFD()
{