mirror of
git://gcc.gnu.org/git/gcc.git
synced 2024-12-19 19:09:44 +08:00
* 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. From-SVN: r51492
This commit is contained in:
parent
1b58660a9d
commit
47d0866c79
@ -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.
|
||||
|
@ -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();
|
||||
}
|
||||
}
|
||||
|
@ -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.
|
||||
*/
|
||||
|
@ -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>
|
||||
@ -90,6 +89,13 @@ java::net::PlainDatagramSocketImpl::peek (java::net::InetAddress *)
|
||||
JvNewStringLatin1 ("DatagramSocketImpl.peek: unimplemented"));
|
||||
}
|
||||
|
||||
void
|
||||
java::net::PlainDatagramSocketImpl::close ()
|
||||
{
|
||||
throw new java::io::IOException (
|
||||
JvNewStringLatin1 ("DatagramSocketImpl.close: unimplemented"));
|
||||
}
|
||||
|
||||
void
|
||||
java::net::PlainDatagramSocketImpl::send (java::net::DatagramPacket *)
|
||||
{
|
||||
@ -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)
|
||||
{
|
||||
|
@ -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);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user