summaryrefslogtreecommitdiff
path: root/libjava/java/net/DatagramSocket.java
diff options
context:
space:
mode:
authorMichael Koch <konqueror@gmx.de>2002-09-21 06:59:20 +0000
committerMichael Koch <mkoch@gcc.gnu.org>2002-09-21 06:59:20 +0000
commitbe362a0d5ba42bee36bd339e25374100a9f1942c (patch)
tree83851aefa46dabb8d83a414a2859a534a89184ca /libjava/java/net/DatagramSocket.java
parent84d7dd4a5361d64c2168b354b2c7c03b4f21a8f5 (diff)
2002-09-21 Michael Koch <konqueror@gmx.de>
* java/net/Socket.java (sendUrgentData): New method. (getChannel): New method. * java/net/ServerSocket.java (getChannel): New method. (isBound): New method. * java/net/DatagramSocket.java (DatagramSocket): Two new methods. (bind): New method. (getChannel): New method. (isBound): New method. (send): Added newline to to make shorter lines. * java/net/PlainDatagramSocketImpl.java (mcastGrp): Added argument. (join): Use new mcastGrp. (leave): Use new mcastGrp. (joinGroup): New method. (leaveGroup): New method. * java/net/natPlainDatagramSocketImpl.cc (mcastGrp): Added argument, no yet really implemented. (getOption): Added newline for shorter lines. * java/net/natPlainSocketImpl.cc (read, setOption, getOption): Added newline for shorter lines. From-SVN: r57380
Diffstat (limited to 'libjava/java/net/DatagramSocket.java')
-rw-r--r--libjava/java/net/DatagramSocket.java81
1 files changed, 79 insertions, 2 deletions
diff --git a/libjava/java/net/DatagramSocket.java b/libjava/java/net/DatagramSocket.java
index 93aea0754ed..da97d6115c3 100644
--- a/libjava/java/net/DatagramSocket.java
+++ b/libjava/java/net/DatagramSocket.java
@@ -1,6 +1,6 @@
// DatagramSocket.java
-/* Copyright (C) 1999, 2000 Free Software Foundation
+/* Copyright (C) 1999, 2000, 2002 Free Software Foundation
This file is part of libgcj.
@@ -10,6 +10,7 @@ details. */
package java.net;
import java.io.IOException;
+import java.nio.channels.DatagramChannel;
/**
* @author Warren Levy <warrenl@cygnus.com>
@@ -26,12 +27,42 @@ public class DatagramSocket
{
DatagramSocketImpl impl;
+ DatagramChannel ch;
+
public DatagramSocket() throws SocketException
{
this(0, null);
}
/**
+ * Creates a DatagramSocket from a specified DatagramSocketImpl instance
+ *
+ * @param impl The DatagramSocketImpl the socket will be created from
+ *
+ * @since 1.4
+ */
+ protected DatagramSocket (DatagramSocketImpl impl)
+ {
+ this.impl = impl;
+ }
+
+ /**
+ * Creates a datagram socket that is bound to a given socket address
+ *
+ * @param bindaddr The socket address to bind to
+ *
+ * @exception SocketException If an error occurs
+ *
+ * @since 1.4
+ */
+ public DatagramSocket (SocketAddress bindaddr)
+ throws SocketException
+ {
+ this (((InetSocketAddress) bindaddr).getPort (),
+ ((InetSocketAddress) bindaddr).getAddress ());
+ }
+
+ /**
* Creates a datagram socket that is bound to a specific port
*
* @param port The port number to bind to
@@ -85,6 +116,22 @@ public class DatagramSocket
}
/**
+ * Binds the socket to the given socket addres
+ *
+ * @param address The socket address to bind to
+ *
+ * @exception SocketException If an error occurs
+ *
+ * @since 1.4
+ */
+ public void bind (SocketAddress address)
+ throws SocketException
+ {
+ InetSocketAddress tmp = (InetSocketAddress) address;
+ impl.bind (tmp.getPort (), tmp.getAddress ());
+ }
+
+ /**
* Closes the datagram socket
*/
public void close()
@@ -93,6 +140,16 @@ public class DatagramSocket
}
/**
+ * Gets a datagram channel assoziated with the socket
+ *
+ * @since 1.4
+ */
+ public DatagramChannel getChannel()
+ {
+ return ch;
+ }
+
+ /**
* Returns the local address of the datagram socket
*
* @since 1.1
@@ -199,7 +256,8 @@ public class DatagramSocket
s.checkConnect(addr.getHostAddress(), p.getPort());
}
- // FIXME: if this is a subclass of MulticastSocket, use getTimeToLive for TTL val.
+ // FIXME: if this is a subclass of MulticastSocket,
+ // use getTimeToLive for TTL val.
impl.send(p);
}
@@ -247,6 +305,25 @@ public class DatagramSocket
}
/**
+ * Returns the binding state of the socket
+ *
+ * @since 1.4
+ */
+ public boolean isBound()
+ {
+ try
+ {
+ Object bindaddr = impl.getOption (SocketOptions.SO_BINDADDR);
+ }
+ catch (SocketException e)
+ {
+ return false;
+ }
+
+ return true;
+ }
+
+ /**
* Returns the InetAddress the socket is connected to
* or null if the socket is not connected
*