diff options
Diffstat (limited to 'libjava/java/net')
-rw-r--r-- | libjava/java/net/DatagramSocket.java | 81 | ||||
-rw-r--r-- | libjava/java/net/PlainDatagramSocketImpl.java | 20 | ||||
-rw-r--r-- | libjava/java/net/ServerSocket.java | 40 | ||||
-rw-r--r-- | libjava/java/net/Socket.java | 28 | ||||
-rw-r--r-- | libjava/java/net/natPlainDatagramSocketImpl.cc | 8 | ||||
-rw-r--r-- | libjava/java/net/natPlainSocketImpl.cc | 15 |
6 files changed, 179 insertions, 13 deletions
diff --git a/libjava/java/net/DatagramSocket.java b/libjava/java/net/DatagramSocket.java index 93aea07..da97d61 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 * diff --git a/libjava/java/net/PlainDatagramSocketImpl.java b/libjava/java/net/PlainDatagramSocketImpl.java index 3a8db03..54f5c2e 100644 --- a/libjava/java/net/PlainDatagramSocketImpl.java +++ b/libjava/java/net/PlainDatagramSocketImpl.java @@ -72,8 +72,8 @@ class PlainDatagramSocketImpl extends DatagramSocketImpl 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. @@ -90,12 +90,24 @@ class PlainDatagramSocketImpl extends DatagramSocketImpl 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 diff --git a/libjava/java/net/ServerSocket.java b/libjava/java/net/ServerSocket.java index c6b1870..b706acc 100644 --- a/libjava/java/net/ServerSocket.java +++ b/libjava/java/net/ServerSocket.java @@ -38,6 +38,7 @@ exception statement from your version. */ 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. @@ -75,6 +76,12 @@ public class ServerSocket 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. */ private ServerSocket() @@ -282,6 +289,39 @@ public class ServerSocket } /** + * 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 * milliseconds a socket operation can block before an diff --git a/libjava/java/net/Socket.java b/libjava/java/net/Socket.java index 078bfff..25f077b 100644 --- a/libjava/java/net/Socket.java +++ b/libjava/java/net/Socket.java @@ -38,6 +38,7 @@ exception statement from your version. */ 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. @@ -78,6 +79,8 @@ public class Socket */ SocketImpl impl; + SocketChannel ch; // this field must have been set if created by SocketChannel + // Constructors /** @@ -525,6 +528,21 @@ public class Socket } /** + * 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 * * @param on True if SO_OOBLINE should be enabled @@ -819,4 +837,14 @@ public class Socket 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; + } } diff --git a/libjava/java/net/natPlainDatagramSocketImpl.cc b/libjava/java/net/natPlainDatagramSocketImpl.cc index 12eaf3b..cf11925 100644 --- a/libjava/java/net/natPlainDatagramSocketImpl.cc +++ b/libjava/java/net/natPlainDatagramSocketImpl.cc @@ -63,6 +63,7 @@ _Jv_bind (int fd, struct sockaddr *addr, int addrlen) #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> @@ -136,6 +137,7 @@ java::net::PlainDatagramSocketImpl::getTimeToLive () void java::net::PlainDatagramSocketImpl::mcastGrp (java::net::InetAddress *, + java::net::NetworkInterface *, jboolean) { throw new java::io::IOException ( @@ -504,8 +506,11 @@ java::net::PlainDatagramSocketImpl::getTimeToLive () 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); @@ -769,7 +774,8 @@ java::net::PlainDatagramSocketImpl::getOption (jint 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; diff --git a/libjava/java/net/natPlainSocketImpl.cc b/libjava/java/net/natPlainSocketImpl.cc index 9d5b4d2..a1e967e 100644 --- a/libjava/java/net/natPlainSocketImpl.cc +++ b/libjava/java/net/natPlainSocketImpl.cc @@ -381,7 +381,7 @@ java::net::PlainSocketImpl::connect (java::net::SocketAddress *addr, throw new java::net::SocketTimeoutException ( JvNewStringUTF("Connect timed out")); } - else + else #endif { if (_Jv_connect (fnum, ptr, len) != 0) @@ -588,7 +588,8 @@ java::net::PlainSocketImpl::read(void) 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) @@ -647,7 +648,8 @@ java::net::PlainSocketImpl::read(jbyteArray buffer, jint offset, jint count) 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. @@ -776,7 +778,8 @@ java::net::PlainSocketImpl::setOption (jint optID, java::lang::Object *value) } 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) @@ -968,8 +971,8 @@ java::net::PlainSocketImpl::getOption (jint 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; |