From f2ed9e9656a375cf80b11dfb3a264a7551654ecd Mon Sep 17 00:00:00 2001 From: Warren Levy Date: Wed, 26 May 1999 17:00:06 +0000 Subject: [multiple changes] 1999-05-26 Bryce McKinlay * java/net/DatagramSocket.java (getSoTimeout): Verify class type. * java/net/DatagramSocketImpl.java (getOption): Made abstract. (setOption): Made abstract. * java/net/PlainDatagramSocketImpl.java: Mirror SocketOptions fields to avoid cpp conflicts in native code. * java/net/PlainSocketImpl.java: Mirror SocketOptions fields to avoid cpp conflicts in native code. * java/net/ServerSocket.java (toString): Prepended "ServerSocket". * java/net/Socket.java (getLocalAddress): Implemented. (setTcpNoDelay): Implemented. (getTcpNoDelay): Implemented. (setSoLinger): Implemented. (getSoLinger): Implemented. (getSoTimeout): Verify class type. (setSendBufferSize): Implemented. (getSendBufferSize): Implemented. (setReceiveBufferSize): Implemented. (getReceiveBufferSize): Implemented. (toString): Prepended "Socket". * java/net/SocketImpl.java (toString): Rewritten. (getOption): Made abstract. (setOption): Made abstract. * java/net/natPlainSocketImpl.cc (connect): Set localport properly. (setOption): Implemented. (getOption): Implemented. 1999-05-26 Warren Levy * java/net/DatagramSocket.java (DatagramSocket): Get local host address when null. Set SO_REUSEADDR for multicasts. (getSoTimeout): Implemented. (setSoTimeout): Implemented. * java/net/DatagramSocketImpl.java: Implement SocketOptions interface. * java/net/MulticastSocket.java (getInterface): Implemented. (setInterface): Implemented. (setTimeToLive): Check for invalid ttl. (joinGroup): Verify multicast address and security. (leaveGroup): Verify multicast address and security. (send): Implemented. * java/net/PlainDatagramSocketImpl.java (timeout): Added. (iface): Added. (ttl): Added. (setOption): Added. (getOption): Added. (mcastGrp): Added. (getTTL): Implemented as non-native. (setTTL): ditto. (join): ditto. (leave): ditto. * java/net/ServerSocket.java (setSoTimeout): Implemented. (getSoTimeout): Implemented. (setSocketFactory): Made synchronized. * java/net/Socket.java (setSoTimeout): Implemented. (getSoTimeout): Implemented. (close): Made synchronized. (setSocketImplFactory): Made synchronized. * java/net/SocketImpl.java: Implement SocketOptions interface. * java/net/natInetAddress.cc: Corrected module name at top of file. * java/net/natPlainDatagramSocketImpl.cc (McastReq): Added union. (bind): Added FIXME. (peek): Implemented. (setTTL): Removed. (getTTL): Removed. (join): Removed. (leave): Removed. (mcastGrp): Added. (setOption): Implemented for SO_REUSEADDR. (getOption): Implemented for SO_REUSEADDR. From-SVN: r27184 --- libjava/java/net/MulticastSocket.java | 49 ++++++++++++++++++++++++++++++----- 1 file changed, 42 insertions(+), 7 deletions(-) (limited to 'libjava/java/net/MulticastSocket.java') diff --git a/libjava/java/net/MulticastSocket.java b/libjava/java/net/MulticastSocket.java index 1cb01c1..03a6e6b 100644 --- a/libjava/java/net/MulticastSocket.java +++ b/libjava/java/net/MulticastSocket.java @@ -25,7 +25,8 @@ import java.io.IOException; public class MulticastSocket extends DatagramSocket { // FIXME: the local addr bound to the multicast socket can be reused; - // unlike unicast sockets. see p.1159 JCL book. + // unlike unicast sockets. It binds to any available network interface. + // See p.1159 JCL book. public MulticastSocket() throws IOException { @@ -39,13 +40,16 @@ public class MulticastSocket extends DatagramSocket public InetAddress getInterface() throws SocketException { - // FIXME: TODO - MulticastSocket.getInterface - throw new SocketException("MulticastSocket.getInterface - not yet implemented"); + // FIXME: Is it possible that an InetAddress wasn't returned from getOption? + return (InetAddress) impl.getOption(SocketOptions.IP_MULTICAST_IF); } // Deprecated in JDK1.2 public byte getTTL() throws IOException { + // Use getTTL here rather than getTimeToLive in case we're using an impl + // other than the default PlainDatagramSocketImpl and it doesn't have + // getTimeToLive yet. return impl.getTTL(); } @@ -57,35 +61,66 @@ public class MulticastSocket extends DatagramSocket public void setInterface(InetAddress inf) throws SocketException { - // FIXME: TODO - MulticastSocket.setInterface - throw new SocketException("MulticastSocket.setInterface - not yet implemented"); + impl.setOption(SocketOptions.IP_MULTICAST_IF, inf); } // Deprecated in JDK1.2 public void setTTL(byte ttl) throws IOException { + // Use setTTL here rather than setTimeToLive in case we're using an impl + // other than the default PlainDatagramSocketImpl and it doesn't have + // setTimeToLive yet. impl.setTTL(ttl); } // JDK1.2 public void setTimeToLive(int ttl) throws IOException { + if (ttl < 0 || ttl > 255) + throw new IllegalArgumentException("Invalid ttl: " + ttl); + impl.setTimeToLive(ttl); } public void joinGroup(InetAddress mcastaddr) throws IOException { + if (! mcastaddr.isMulticastAddress()) + throw new IOException("Not a Multicast address"); + + SecurityManager s = System.getSecurityManager(); + if (s != null) + s.checkMulticast(mcastaddr); + impl.join(mcastaddr); } public void leaveGroup(InetAddress mcastaddr) throws IOException { + if (! mcastaddr.isMulticastAddress()) + throw new IOException("Not a Multicast address"); + + SecurityManager s = System.getSecurityManager(); + if (s != null) + s.checkMulticast(mcastaddr); + impl.leave(mcastaddr); } - public void send(DatagramPacket p, byte ttl) throws IOException + public synchronized void send(DatagramPacket p, byte ttl) throws IOException { - // FIXME: use ttl instead of getTTL() for time to live. + SecurityManager s = System.getSecurityManager(); + if (s != null) + { + InetAddress addr = p.getAddress(); + if (addr.isMulticastAddress()) + s.checkMulticast(addr, ttl); + else + s.checkConnect(addr.getHostAddress(), p.getPort()); + } + + int oldttl = impl.getTimeToLive(); + impl.setTimeToLive(((int) ttl) & 0xFF); impl.send(p); + impl.setTimeToLive(oldttl); } } -- cgit v1.1