Commit 927818a5 by Michael Koch Committed by Tom Tromey

2003-01-10 Michael Koch <konqueror@gmx.de>

	* java/net/DatagramSocket.java
	(ch): Description added.
	(remotePort): Initialize with -1.
	(connect): Doesnt throws SocketException.
	* java/net/MulticastSocket.java
	(setInterface): Merge with Classpath.
	* java/net/ServerSocket.java
	(closed): New member variable.
	(bind): Check if socket is closed.
	(close): Close an associated channel too, set new value to closed.
	(isBound): Reindented.
	(isClosed): Implemented.
	* java/net/Socket.java
	(closed): New member variable.
	(bind): Check if socket is closed.
	(connect): Check if socket is closed.
	(close): Close an associated channel too, set new value to closed.
	(isClosed): Implemented.

From-SVN: r61185
parent b1771c6a
2003-01-10 Michael Koch <konqueror@gmx.de> 2003-01-10 Michael Koch <konqueror@gmx.de>
* java/net/DatagramSocket.java
(ch): Description added.
(remotePort): Initialize with -1.
(connect): Doesnt throws SocketException.
* java/net/MulticastSocket.java
(setInterface): Merge with Classpath.
* java/net/ServerSocket.java
(closed): New member variable.
(bind): Check if socket is closed.
(close): Close an associated channel too, set new value to closed.
(isBound): Reindented.
(isClosed): Implemented.
* java/net/Socket.java
(closed): New member variable.
(bind): Check if socket is closed.
(connect): Check if socket is closed.
(close): Close an associated channel too, set new value to closed.
(isClosed): Implemented.
2003-01-10 Michael Koch <konqueror@gmx.de>
* java/awt/DisplayMode.java * java/awt/DisplayMode.java
(equals): Fixed argument type and implementation. (equals): Fixed argument type and implementation.
......
...@@ -72,6 +72,10 @@ public class DatagramSocket ...@@ -72,6 +72,10 @@ public class DatagramSocket
*/ */
DatagramSocketImpl impl; DatagramSocketImpl impl;
/**
* The unique DatagramChannel object associated with this datagram socket,
* or null.
*/
DatagramChannel ch; DatagramChannel ch;
/** /**
...@@ -82,7 +86,7 @@ public class DatagramSocket ...@@ -82,7 +86,7 @@ public class DatagramSocket
/** /**
* This is the port we are "connected" to * This is the port we are "connected" to
*/ */
private int remotePort; private int remotePort = -1;
/** /**
* Creates a DatagramSocket from a specified DatagramSocketImpl instance * Creates a DatagramSocket from a specified DatagramSocketImpl instance
...@@ -439,7 +443,6 @@ public class DatagramSocket ...@@ -439,7 +443,6 @@ public class DatagramSocket
* @since 1.2 * @since 1.2
*/ */
public void connect(InetAddress address, int port) public void connect(InetAddress address, int port)
throws SocketException
{ {
if (address == null) if (address == null)
throw new IllegalArgumentException ("Address may not be null"); throw new IllegalArgumentException ("Address may not be null");
...@@ -451,10 +454,15 @@ public class DatagramSocket ...@@ -451,10 +454,15 @@ public class DatagramSocket
if (sm != null) if (sm != null)
sm.checkAccept(address.getHostName (), port); sm.checkAccept(address.getHostName (), port);
try
{
impl.connect (address, port); impl.connect (address, port);
remoteAddress = address; remoteAddress = address;
remotePort = port; remotePort = port;
}
catch (SocketException e)
{
}
} }
/** /**
......
/* MulticastSocket.java -- Class for using multicast sockets /* MulticastSocket.java -- Class for using multicast sockets
Copyright (C) 1998, 1999, 2000, 2001 Free Software Foundation, Inc. Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003
Free Software Foundation, Inc.
This file is part of GNU Classpath. This file is part of GNU Classpath.
...@@ -163,13 +164,15 @@ public class MulticastSocket extends DatagramSocket ...@@ -163,13 +164,15 @@ public class MulticastSocket extends DatagramSocket
/** /**
* Sets the interface to use for sending multicast packets. * Sets the interface to use for sending multicast packets.
* *
* @param inf The new interface to use * @param addr The new interface to use.
* *
* @exception SocketException If an error occurs * @exception SocketException If an error occurs.
*
* @since 1.4
*/ */
public void setInterface(InetAddress inf) throws SocketException public void setInterface(InetAddress addr) throws SocketException
{ {
impl.setOption(SocketOptions.IP_MULTICAST_IF, inf); impl.setOption(SocketOptions.IP_MULTICAST_IF, addr);
} }
/** /**
......
...@@ -77,6 +77,8 @@ public class ServerSocket ...@@ -77,6 +77,8 @@ public class ServerSocket
*/ */
private ServerSocketChannel ch; private ServerSocketChannel ch;
private boolean closed = false;
/** /**
* Constructor that simply sets the implementation. * Constructor that simply sets the implementation.
* *
...@@ -200,6 +202,9 @@ public class ServerSocket ...@@ -200,6 +202,9 @@ public class ServerSocket
*/ */
public void bind (SocketAddress endpoint, int backlog) throws IOException public void bind (SocketAddress endpoint, int backlog) throws IOException
{ {
if (closed)
throw new SocketException ("ServerSocket is closed");
if (impl == null) if (impl == null)
throw new IOException ("Cannot initialize Socket implementation"); throw new IOException ("Cannot initialize Socket implementation");
...@@ -315,7 +320,13 @@ public class ServerSocket ...@@ -315,7 +320,13 @@ public class ServerSocket
*/ */
public void close () throws IOException public void close () throws IOException
{ {
impl.close(); if (impl != null)
impl.close ();
if (ch != null)
ch.close ();
closed = true;
} }
/** /**
...@@ -358,8 +369,7 @@ public class ServerSocket ...@@ -358,8 +369,7 @@ public class ServerSocket
*/ */
public boolean isClosed() public boolean isClosed()
{ {
// FIXME: implement this return closed;
return false;
} }
/** /**
......
...@@ -85,6 +85,8 @@ public class Socket ...@@ -85,6 +85,8 @@ public class Socket
SocketChannel ch; // this field must have been set if created by SocketChannel SocketChannel ch; // this field must have been set if created by SocketChannel
private boolean closed = false;
// Constructors // Constructors
/** /**
...@@ -308,6 +310,9 @@ public class Socket ...@@ -308,6 +310,9 @@ public class Socket
*/ */
public void bind (SocketAddress bindpoint) throws IOException public void bind (SocketAddress bindpoint) throws IOException
{ {
if (closed)
throw new SocketException ("Socket is closed");
if ( !(bindpoint instanceof InetSocketAddress)) if ( !(bindpoint instanceof InetSocketAddress))
throw new IllegalArgumentException (); throw new IllegalArgumentException ();
...@@ -330,6 +335,9 @@ public class Socket ...@@ -330,6 +335,9 @@ public class Socket
public void connect (SocketAddress endpoint) public void connect (SocketAddress endpoint)
throws IOException throws IOException
{ {
if (closed)
throw new SocketException ("Socket is closed");
if (! (endpoint instanceof InetSocketAddress)) if (! (endpoint instanceof InetSocketAddress))
throw new IllegalArgumentException ("Address type not supported"); throw new IllegalArgumentException ("Address type not supported");
...@@ -357,6 +365,9 @@ public class Socket ...@@ -357,6 +365,9 @@ public class Socket
public void connect (SocketAddress endpoint, int timeout) public void connect (SocketAddress endpoint, int timeout)
throws IOException throws IOException
{ {
if (closed)
throw new SocketException ("Socket is closed");
if (! (endpoint instanceof InetSocketAddress)) if (! (endpoint instanceof InetSocketAddress))
throw new IllegalArgumentException ("Address type not supported"); throw new IllegalArgumentException ("Address type not supported");
...@@ -853,6 +864,11 @@ public class Socket ...@@ -853,6 +864,11 @@ public class Socket
{ {
if (impl != null) if (impl != null)
impl.close(); impl.close();
if (ch != null)
ch.close();
closed = true;
} }
/** /**
...@@ -1035,8 +1051,7 @@ public class Socket ...@@ -1035,8 +1051,7 @@ public class Socket
*/ */
public boolean isClosed () public boolean isClosed ()
{ {
// FIXME: implement this. return closed;
return false;
} }
/** /**
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment