This is the mail archive of the
java-patches@gcc.gnu.org
mailing list for the Java project.
Re: PATCH: remove all traces of java.io.FileDescriptor from java.net
- From: Bryce McKinlay <bryce at waitaki dot otago dot ac dot nz>
- To: Jeff Sturm <jsturm at one-point dot com>
- Cc: Tom Tromey <tromey at redhat dot com>, java-patches at gcc dot gnu dot org
- Date: Wed, 27 Mar 2002 11:02:52 +1200
- Subject: Re: PATCH: remove all traces of java.io.FileDescriptor from java.net
- References: <Pine.LNX.4.10.10203261147510.3710-100000@mars.deadcafe.org>
Jeff Sturm wrote:
>Here's my updated patch. Hans convinced me that close/finalize ought to
>synchronize access to fnum, I've included that below.
>
Hmm, why is that? Also I noticed that it is actually synchronizing
twice, both in finalize and close?
Bryce.
>@@ -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.
> */
>
>@@ -413,6 +410,9 @@ java::net::PlainSocketImpl::accept (java
> 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);
>
>