summaryrefslogtreecommitdiff
path: root/java/net/DatagramSocket.java
diff options
context:
space:
mode:
authorMichael Koch <konqueror@gmx.de>2003-05-02 11:52:36 +0000
committerMichael Koch <konqueror@gmx.de>2003-05-02 11:52:36 +0000
commit6cb7b02e162a6680b705c99f73496bfbff32f2b2 (patch)
tree04ebda7c626c3a7e54f21f7e1a37859a56c4fbb8 /java/net/DatagramSocket.java
parent93c060eb5e4cd45df7f3e2d5b09212c086108869 (diff)
downloadclasspath-6cb7b02e162a6680b705c99f73496bfbff32f2b2.tar.gz
2003-05-02 Michael Koch <konqueror@gmx.de>
* java/net/DatagramSocket.java, java/net/JarURLConnection, java/net/URLConnection: Partly merged with libgcj.
Diffstat (limited to 'java/net/DatagramSocket.java')
-rw-r--r--java/net/DatagramSocket.java77
1 files changed, 43 insertions, 34 deletions
diff --git a/java/net/DatagramSocket.java b/java/net/DatagramSocket.java
index cf28fb707..ee4f6bc5d 100644
--- a/java/net/DatagramSocket.java
+++ b/java/net/DatagramSocket.java
@@ -153,40 +153,23 @@ public class DatagramSocket
*/
public DatagramSocket(int port, InetAddress laddr) throws SocketException
{
- this (new InetSocketAddress (laddr != null ? laddr : InetAddress.ANY_IF, port));
- }
-
- /**
- * Initializes a new instance of <code>DatagramSocket</code> that binds to
- * the specified local port and address.
- *
- * @param port The local port number to bind to.
- * @param laddr The local address to bind to.
- *
- * @exception SecurityException If a security manager exists and its
- * checkListen method doesn't allow the operation.
- * @exception SocketException If an error occurs.
- *
- * @since 1.4
- */
- public DatagramSocket (SocketAddress address) throws SocketException
- {
- InetSocketAddress tmp = (InetSocketAddress) address;
+ if (port < 0 || port > 65535)
+ throw new IllegalArgumentException("Invalid port: " + port);
SecurityManager s = System.getSecurityManager();
if (s != null)
- s.checkListen(tmp.getPort ());
+ s.checkListen(port);
// Why is there no factory for this?
impl = new PlainDatagramSocketImpl();
impl.create();
- if (address != null)
+ if (laddr != null)
{
try
{
- local_addr = tmp.getAddress ();
- impl.bind(tmp.getPort (), tmp.getAddress ());
+ local_addr = laddr;
+ impl.bind(port, laddr);
}
catch (SocketException exception)
{
@@ -205,6 +188,25 @@ public class DatagramSocket
}
}
}
+
+ /**
+ * Initializes a new instance of <code>DatagramSocket</code> that binds to
+ * the specified local port and address.
+ *
+ * @param port The local port number to bind to.
+ * @param laddr The local address to bind to.
+ *
+ * @exception SecurityException If a security manager exists and its
+ * checkListen method doesn't allow the operation.
+ * @exception SocketException If an error occurs.
+ *
+ * @since 1.4
+ */
+ public DatagramSocket (SocketAddress address) throws SocketException
+ {
+ this (((InetSocketAddress) address).getPort (),
+ ((InetSocketAddress) address).getAddress ());
+ }
/**
* Closes this datagram socket.
@@ -300,7 +302,7 @@ public class DatagramSocket
if (timeout instanceof Integer)
return ((Integer)timeout).intValue();
else
- throw new SocketException("Internal Error");
+ return 0;
}
/**
@@ -404,6 +406,9 @@ public class DatagramSocket
*/
public void setReceiveBufferSize(int size) throws SocketException
{
+ if (impl == null)
+ throw new SocketException ("Cannot initialize Socket implementation");
+
if (size < 0)
throw new IllegalArgumentException("Buffer size is less than 0");
@@ -438,13 +443,17 @@ public class DatagramSocket
if (sm != null)
sm.checkConnect(address.getHostName(), port);
- this.remoteAddress = address;
- this.remotePort = port;
-
- /* FIXME: Shit, we can't do this even though the OS supports it since this
- method isn't in DatagramSocketImpl. */
- // impl.connect(address, port);
- }
+ try
+ {
+ impl.connect (address, port);
+ remoteAddress = address;
+ remotePort = port;
+ }
+ catch (SocketException e)
+ {
+ // This means simply not connected or connect not implemented.
+ }
+ }
/**
* This method disconnects this socket from the address/port it was
@@ -455,9 +464,9 @@ public class DatagramSocket
*/
public void disconnect()
{
- // FIXME: See my comments on connect()
- this.remoteAddress = null;
- this.remotePort = -1;
+ impl.disconnect();
+ remoteAddress = null;
+ remotePort = -1;
}
/**