+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.
+
2002-09-19 Tom Tromey <tromey@redhat.com>
* java/lang/ClassLoader.java (resolveClass0): Set cause for
// DatagramSocket.java
-/* Copyright (C) 1999, 2000 Free Software Foundation
+/* Copyright (C) 1999, 2000, 2002 Free Software Foundation
This file is part of libgcj.
package java.net;
import java.io.IOException;
+import java.nio.channels.DatagramChannel;
/**
* @author Warren Levy <warrenl@cygnus.com>
{
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
*
impl.bind(port, laddr == null ? InetAddress.ANY_IF : laddr);
}
+ /**
+ * 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
*/
impl.close();
}
+ /**
+ * Gets a datagram channel assoziated with the socket
+ *
+ * @since 1.4
+ */
+ public DatagramChannel getChannel()
+ {
+ return ch;
+ }
+
/**
* Returns the local address of the datagram socket
*
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);
}
//impl.disconnect();
}
+ /**
+ * 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
protected native void receive(DatagramPacket p) throws IOException;
public native void setOption(int optID, Object value) throws SocketException;
public native Object getOption(int optID) throws SocketException;
- private native void mcastGrp(InetAddress inetaddr, boolean join)
- throws IOException;
+ private native void mcastGrp(InetAddress inetaddr, NetworkInterface netIf,
+ boolean join) throws IOException;
protected native void close();
// Deprecated in JDK 1.2.
protected void join(InetAddress inetaddr) throws IOException
{
- mcastGrp(inetaddr, true);
+ mcastGrp(inetaddr, null, true);
}
protected void leave(InetAddress inetaddr) throws IOException
{
- mcastGrp(inetaddr, false);
+ mcastGrp(inetaddr, null, false);
+ }
+
+ protected void joinGroup (SocketAddress mcastaddr, NetworkInterface netIf)
+ throws IOException
+ {
+ mcastGrp(((InetSocketAddress)mcastaddr).getAddress(), netIf, true);
+ }
+
+ protected void leaveGroup (SocketAddress mcastaddr, NetworkInterface netIf)
+ throws IOException
+ {
+ mcastGrp(((InetSocketAddress)mcastaddr).getAddress(), netIf, false);
}
protected void finalize() throws Throwable
package java.net;
import java.io.IOException;
+import java.nio.channels.ServerSocketChannel;
/* Written using on-line Java Platform 1.2 API Specification.
* Status: I believe all methods are implemented.
*/
private SocketImpl impl;
+ /**
+ * ServerSocketChannel of this ServerSocket. This channel only exists
+ * when the socket is created by ServerSocketChannel.open().
+ */
+ private ServerSocketChannel ch;
+
/**
* Private constructor that simply sets the implementation.
*/
impl.close();
}
+ /**
+ * Returns the unique ServerSocketChannel object
+ * associated with this socket, if any.
+ *
+ * The socket only has a ServerSocketChannel if its created
+ * by ServerSocketChannel.open.
+ *
+ * @since 1.4
+ */
+ public ServerSocketChannel getChannel()
+ {
+ return ch;
+ }
+
+ /**
+ * Returns true then the socket is bound, otherwise false
+ *
+ * @since 1.4
+ */
+ public boolean isBound()
+ {
+ try
+ {
+ Object bindaddr = impl.getOption (SocketOptions.SO_BINDADDR);
+ }
+ catch (SocketException e)
+ {
+ return false;
+ }
+
+ return true;
+ }
+
/**
* Sets the value of SO_TIMEOUT. A value of 0 implies that SO_TIMEOUT is
* disabled (ie, operations never time out). This is the number of
package java.net;
import java.io.*;
+import java.nio.channels.SocketChannel;
/* Written using on-line Java Platform 1.2 API Specification.
* Status: I believe all methods are implemented.
*/
SocketImpl impl;
+ SocketChannel ch; // this field must have been set if created by SocketChannel
+
// Constructors
/**
return -1;
}
+ /**
+ * Sends urgent data through the socket
+ *
+ * @param data The data to send.
+ * Only the lowest eight bits of data are sent
+ *
+ * @exception IOException If an error occurs
+ *
+ * @since 1.4
+ */
+ public void sendUrgentData (int data) throws IOException
+ {
+ impl.sendUrgentData (data);
+ }
+
/**
* Enables/disables the SO_OOBINLINE option
*
if (impl != null)
impl.shutdownOutput();
}
+
+ /**
+ * Returns the socket channel associated with this socket.
+ *
+ * It returns null if no associated socket exists.
+ */
+ public SocketChannel getChannel()
+ {
+ return ch;
+ }
}
#include <java/net/SocketException.h>
#include <java/net/PlainDatagramSocketImpl.h>
#include <java/net/InetAddress.h>
+#include <java/net/NetworkInterface.h>
#include <java/net/DatagramPacket.h>
#include <java/lang/InternalError.h>
#include <java/lang/Object.h>
void
java::net::PlainDatagramSocketImpl::mcastGrp (java::net::InetAddress *,
+ java::net::NetworkInterface *,
jboolean)
{
throw new java::io::IOException (
void
java::net::PlainDatagramSocketImpl::mcastGrp (java::net::InetAddress *inetaddr,
+ java::net::NetworkInterface *,
jboolean join)
{
+ // FIXME: implement use of NetworkInterface
+
union McastReq u;
jbyteArray haddress = inetaddr->addr;
jbyte *bytes = elements (haddress);
}
#endif
else
- throw new java::net::SocketException (JvNewStringUTF ("invalid family"));
+ throw new java::net::SocketException (
+ JvNewStringUTF ("invalid family"));
localAddress = new java::net::InetAddress (laddr, NULL);
}
return localAddress;
throw new java::net::SocketTimeoutException (
JvNewStringUTF("Connect timed out"));
}
- else
+ else
#endif
{
if (_Jv_connect (fnum, ptr, len) != 0)
timeout_value.tv_sec = timeout / 1000;
timeout_value.tv_usec = (timeout % 1000) * 1000;
// Select on the fds.
- int sel_retval = _Jv_select (fnum + 1, &read_fds, NULL, NULL, &timeout_value);
+ int sel_retval =
+ _Jv_select (fnum + 1, &read_fds, NULL, NULL, &timeout_value);
// If select returns 0 we've waited without getting data...
// that means we've timed out.
if (sel_retval == 0)
timeout_value.tv_sec = timeout / 1000;
timeout_value.tv_usec =(timeout % 1000) * 1000;
// Select on the fds.
- int sel_retval = _Jv_select (fnum + 1, &read_fds, NULL, NULL, &timeout_value);
+ int sel_retval =
+ _Jv_select (fnum + 1, &read_fds, NULL, NULL, &timeout_value);
// We're only interested in the 0 return.
// error returns still require us to try to read
// the socket to see what happened.
}
else
{
- throw new java::lang::IllegalArgumentException (JvNewStringLatin1 ("`value' must be Boolean or Integer"));
+ throw new java::lang::IllegalArgumentException (
+ JvNewStringLatin1 ("`value' must be Boolean or Integer"));
}
switch (optID)
}
#endif
else
- throw
- new java::net::SocketException (JvNewStringUTF ("invalid family"));
+ throw new java::net::SocketException (
+ JvNewStringUTF ("invalid family"));
localAddress = new java::net::InetAddress (laddr, NULL);
}
return localAddress;