diff options
author | jsturm <jsturm@138bc75d-0d04-0410-961f-82ee72b054a4> | 2002-03-28 02:08:36 +0000 |
---|---|---|
committer | jsturm <jsturm@138bc75d-0d04-0410-961f-82ee72b054a4> | 2002-03-28 02:08:36 +0000 |
commit | 8b4d077733d443942fa4026ce262a276845c3b81 (patch) | |
tree | 51916c05d0f82e2a643314cf640e5e7582d021d9 | |
parent | f11b17f00017922b3f821cb0f73b2b6f918702b2 (diff) | |
download | gcc-8b4d077733d443942fa4026ce262a276845c3b81.tar.gz |
* java/net/PlainDatagramSocketImpl.java
(close): Use native implementation.
(finalize): New method.
* java/net/PlainSocketImpl.java (finalize): New method.
* java/net/natPlainDatagramSocketImpl.cc
(java/io/FileDescriptor.h): Don't include.
(close): Implement method here.
(create): Don't assign fd.
* java/net/natPlainSocketImpl.cc
(java/io/FileDescriptor.h): Don't include.
(create): Don't assign fd.
(accept): Likewise.
(close): Synchronize.
git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@51492 138bc75d-0d04-0410-961f-82ee72b054a4
-rw-r--r-- | libjava/ChangeLog | 19 | ||||
-rw-r--r-- | libjava/java/net/PlainDatagramSocketImpl.java | 32 | ||||
-rw-r--r-- | libjava/java/net/PlainSocketImpl.java | 21 | ||||
-rw-r--r-- | libjava/java/net/natPlainDatagramSocketImpl.cc | 24 | ||||
-rw-r--r-- | libjava/java/net/natPlainSocketImpl.cc | 8 |
5 files changed, 73 insertions, 31 deletions
diff --git a/libjava/ChangeLog b/libjava/ChangeLog index 71c899fa1f3..fb9476da9cb 100644 --- a/libjava/ChangeLog +++ b/libjava/ChangeLog @@ -1,3 +1,22 @@ +2002-03-27 Jeff Sturm <jsturm@one-point.com> + + * java/net/PlainDatagramSocketImpl.java + (close): Use native implementation. + (finalize): New method. + + * java/net/PlainSocketImpl.java (finalize): New method. + + * java/net/natPlainDatagramSocketImpl.cc + (java/io/FileDescriptor.h): Don't include. + (close): Implement method here. + (create): Don't assign fd. + + * java/net/natPlainSocketImpl.cc + (java/io/FileDescriptor.h): Don't include. + (create): Don't assign fd. + (accept): Likewise. + (close): Synchronize. + 2002-03-27 Richard Henderson <rth@redhat.com> * include/posix-threads.h [alpha] (_Jv_ThreadSelf): Avoid a copy. diff --git a/libjava/java/net/PlainDatagramSocketImpl.java b/libjava/java/net/PlainDatagramSocketImpl.java index 7076ccf31b1..55ea468dadc 100644 --- a/libjava/java/net/PlainDatagramSocketImpl.java +++ b/libjava/java/net/PlainDatagramSocketImpl.java @@ -67,27 +67,7 @@ class PlainDatagramSocketImpl extends DatagramSocketImpl public native Object getOption(int optID) throws SocketException; private native void mcastGrp(InetAddress inetaddr, boolean join) throws IOException; - - protected void 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 - { - if (fd.valid()) - fd.close(); - } - catch (IOException e) - { - System.err.println("PlainDatagramSocketImpl.close: Error closing - " + - e.getMessage()); - } - } + protected native void close(); // Deprecated in JDK 1.2. protected byte getTTL() throws IOException @@ -110,4 +90,14 @@ class PlainDatagramSocketImpl extends DatagramSocketImpl { mcastGrp(inetaddr, false); } + + protected void finalize() throws Throwable + { + synchronized (this) + { + if (fnum != -1) + close(); + } + super.finalize(); + } } diff --git a/libjava/java/net/PlainSocketImpl.java b/libjava/java/net/PlainSocketImpl.java index 81df4873850..354d652a5bf 100644 --- a/libjava/java/net/PlainSocketImpl.java +++ b/libjava/java/net/PlainSocketImpl.java @@ -39,11 +39,6 @@ class PlainSocketImpl extends SocketImpl * This is used for reads and writes to/from the socket and * to close it. * - * {@link SocketImpl#fd} is created from this like so: - * <pre> - * fd = new FileDescriptor (fnum); - * </pre> - * * When the socket is closed this is reset to -1. */ int fnum = -1; @@ -108,6 +103,22 @@ class PlainSocketImpl extends SocketImpl private native void write(byte[] buffer, int offset, int count) throws IOException; + protected void finalize() throws Throwable + { + synchronized (this) + { + if (fnum != -1) + try + { + close(); + } + catch (IOException ex) + { + // ignore + } + } + super.finalize(); + } /** @return the input stream attached to the socket. */ diff --git a/libjava/java/net/natPlainDatagramSocketImpl.cc b/libjava/java/net/natPlainDatagramSocketImpl.cc index 81e17cc52a7..071d3679e51 100644 --- a/libjava/java/net/natPlainDatagramSocketImpl.cc +++ b/libjava/java/net/natPlainDatagramSocketImpl.cc @@ -51,7 +51,6 @@ _Jv_bind (int fd, struct sockaddr *addr, int addrlen) #include <gcj/cni.h> #include <java/io/IOException.h> -#include <java/io/FileDescriptor.h> #include <java/io/InterruptedIOException.h> #include <java/net/BindException.h> #include <java/net/SocketException.h> @@ -91,6 +90,13 @@ java::net::PlainDatagramSocketImpl::peek (java::net::InetAddress *) } void +java::net::PlainDatagramSocketImpl::close () +{ + throw new java::io::IOException ( + JvNewStringLatin1 ("DatagramSocketImpl.close: unimplemented")); +} + +void java::net::PlainDatagramSocketImpl::send (java::net::DatagramPacket *) { throw new java::io::IOException ( @@ -188,8 +194,9 @@ java::net::PlainDatagramSocketImpl::create () _Jv_platform_close_on_exec (sock); + // We use fnum in place of fd here. From leaving fd null we avoid + // the double close problem in FileDescriptor.finalize. fnum = sock; - fd = new java::io::FileDescriptor (sock); } void @@ -284,6 +291,19 @@ java::net::PlainDatagramSocketImpl::peek (java::net::InetAddress *i) throw new java::io::IOException (JvNewStringUTF (strerr)); } +// Close(shutdown) the socket. +void +java::net::PlainDatagramSocketImpl::close () +{ + // Avoid races from asynchronous finalization. + JvSynchronize sync (this); + + // The method isn't declared to throw anything, so we disregard + // the return value. + ::close (fnum); + fnum = -1; +} + void java::net::PlainDatagramSocketImpl::send (java::net::DatagramPacket *p) { diff --git a/libjava/java/net/natPlainSocketImpl.cc b/libjava/java/net/natPlainSocketImpl.cc index 3afc5d53cef..85f831332b8 100644 --- a/libjava/java/net/natPlainSocketImpl.cc +++ b/libjava/java/net/natPlainSocketImpl.cc @@ -102,7 +102,6 @@ _Jv_accept (int fd, struct sockaddr *addr, socklen_t *addrlen) #include <gcj/cni.h> #include <gcj/javaprims.h> #include <java/io/IOException.h> -#include <java/io/FileDescriptor.h> #include <java/io/InterruptedIOException.h> #include <java/net/BindException.h> #include <java/net/ConnectException.h> @@ -234,8 +233,9 @@ java::net::PlainSocketImpl::create (jboolean stream) _Jv_platform_close_on_exec (sock); + // We use fnum in place of fd here. From leaving fd null we avoid + // the double close problem in FileDescriptor.finalize. fnum = sock; - fd = new java::io::FileDescriptor (sock); } void @@ -402,7 +402,6 @@ java::net::PlainSocketImpl::accept (java::net::PlainSocketImpl *s) s->localport = localport; s->address = new InetAddress (raddr, NULL); s->port = rport; - s->fd = new java::io::FileDescriptor (new_socket); return; error: char* strerr = strerror (errno); @@ -413,6 +412,9 @@ java::net::PlainSocketImpl::accept (java::net::PlainSocketImpl *s) void java::net::PlainSocketImpl::close() { + // Avoid races from asynchronous finalization. + JvSynchronize sync (this); + // should we use shutdown here? how would that effect so_linger? int res = ::close (fnum); |