src/share/classes/java/net/AbstractPlainDatagramSocketImpl.java

Print this page




  82             ResourceManager.afterUdpClose();
  83             fd = null;
  84             throw ioe;
  85         }
  86     }
  87 
  88     /**
  89      * Binds a datagram socket to a local port.
  90      */
  91     protected synchronized void bind(int lport, InetAddress laddr)
  92         throws SocketException {
  93         bind0(lport, laddr);
  94     }
  95 
  96     protected abstract void bind0(int lport, InetAddress laddr)
  97         throws SocketException;
  98 
  99     /**
 100      * Sends a datagram packet. The packet contains the data and the
 101      * destination address to send the packet to.
 102      * @param packet to be sent.
 103      */
 104     protected abstract void send(DatagramPacket p) throws IOException;
 105 
 106     /**
 107      * Connects a datagram socket to a remote destination. This associates the remote
 108      * address with the local socket so that datagrams may only be sent to this destination
 109      * and received from this destination.
 110      * @param address the remote InetAddress to connect to
 111      * @param port the remote port number
 112      */
 113     protected void connect(InetAddress address, int port) throws SocketException {
 114         connect0(address, port);
 115         connectedAddress = address;
 116         connectedPort = port;
 117         connected = true;
 118     }
 119 
 120     /**
 121      * Disconnects a previously connected socket. Does nothing if the socket was
 122      * not connected already.
 123      */
 124     protected void disconnect() {
 125         disconnect0(connectedAddress.family);
 126         connected = false;
 127         connectedAddress = null;
 128         connectedPort = -1;
 129     }
 130 
 131     /**
 132      * Peek at the packet to see who it is from.
 133      * @param return the address which the packet came from.
 134      */
 135     protected abstract int peek(InetAddress i) throws IOException;
 136     protected abstract int peekData(DatagramPacket p) throws IOException;
 137     /**
 138      * Receive the datagram packet.
 139      * @param Packet Received.
 140      */
 141     protected synchronized void receive(DatagramPacket p)
 142         throws IOException {
 143         receive0(p);
 144     }
 145 
 146     protected abstract void receive0(DatagramPacket p)
 147         throws IOException;
 148 
 149     /**
 150      * Set the TTL (time-to-live) option.
 151      * @param TTL to be set.
 152      */
 153     protected abstract void setTimeToLive(int ttl) throws IOException;
 154 
 155     /**
 156      * Get the TTL (time-to-live) option.
 157      */
 158     protected abstract int getTimeToLive() throws IOException;
 159 
 160     /**
 161      * Set the TTL (time-to-live) option.
 162      * @param TTL to be set.
 163      */
 164     @Deprecated
 165     protected abstract void setTTL(byte ttl) throws IOException;
 166 
 167     /**
 168      * Get the TTL (time-to-live) option.
 169      */
 170     @Deprecated
 171     protected abstract byte getTTL() throws IOException;
 172 
 173     /**
 174      * Join the multicast group.
 175      * @param multicast address to join.
 176      */
 177     protected void join(InetAddress inetaddr) throws IOException {
 178         join(inetaddr, null);
 179     }
 180 
 181     /**
 182      * Leave the multicast group.
 183      * @param multicast address to leave.
 184      */
 185     protected void leave(InetAddress inetaddr) throws IOException {
 186         leave(inetaddr, null);
 187     }
 188     /**
 189      * Join the multicast group.
 190      * @param multicast address to join.
 191      * @param netIf specifies the local interface to receive multicast
 192      *        datagram packets
 193      * @throws  IllegalArgumentException if mcastaddr is null or is a
 194      *          SocketAddress subclass not supported by this socket
 195      * @since 1.4
 196      */
 197 
 198     protected void joinGroup(SocketAddress mcastaddr, NetworkInterface netIf)
 199         throws IOException {
 200         if (mcastaddr == null || !(mcastaddr instanceof InetSocketAddress))
 201             throw new IllegalArgumentException("Unsupported address type");
 202         join(((InetSocketAddress)mcastaddr).getAddress(), netIf);
 203     }
 204 
 205     protected abstract void join(InetAddress inetaddr, NetworkInterface netIf)
 206         throws IOException;
 207 
 208     /**
 209      * Leave the multicast group.
 210      * @param multicast address to leave.
 211      * @param netIf specified the local interface to leave the group at
 212      * @throws  IllegalArgumentException if mcastaddr is null or is a
 213      *          SocketAddress subclass not supported by this socket
 214      * @since 1.4
 215      */
 216     protected void leaveGroup(SocketAddress mcastaddr, NetworkInterface netIf)
 217         throws IOException {
 218         if (mcastaddr == null || !(mcastaddr instanceof InetSocketAddress))
 219             throw new IllegalArgumentException("Unsupported address type");
 220         leave(((InetSocketAddress)mcastaddr).getAddress(), netIf);
 221     }
 222 
 223     protected abstract void leave(InetAddress inetaddr, NetworkInterface netIf)
 224         throws IOException;
 225 
 226     /**
 227      * Close the socket.
 228      */
 229     protected void close() {
 230         if (fd != null) {




  82             ResourceManager.afterUdpClose();
  83             fd = null;
  84             throw ioe;
  85         }
  86     }
  87 
  88     /**
  89      * Binds a datagram socket to a local port.
  90      */
  91     protected synchronized void bind(int lport, InetAddress laddr)
  92         throws SocketException {
  93         bind0(lport, laddr);
  94     }
  95 
  96     protected abstract void bind0(int lport, InetAddress laddr)
  97         throws SocketException;
  98 
  99     /**
 100      * Sends a datagram packet. The packet contains the data and the
 101      * destination address to send the packet to.
 102      * @param p to be sent.
 103      */
 104     protected abstract void send(DatagramPacket p) throws IOException;
 105 
 106     /**
 107      * Connects a datagram socket to a remote destination. This associates the remote
 108      * address with the local socket so that datagrams may only be sent to this destination
 109      * and received from this destination.
 110      * @param address the remote InetAddress to connect to
 111      * @param port the remote port number
 112      */
 113     protected void connect(InetAddress address, int port) throws SocketException {
 114         connect0(address, port);
 115         connectedAddress = address;
 116         connectedPort = port;
 117         connected = true;
 118     }
 119 
 120     /**
 121      * Disconnects a previously connected socket. Does nothing if the socket was
 122      * not connected already.
 123      */
 124     protected void disconnect() {
 125         disconnect0(connectedAddress.family);
 126         connected = false;
 127         connectedAddress = null;
 128         connectedPort = -1;
 129     }
 130 
 131     /**
 132      * Peek at the packet to see who it is from.
 133      * @param i the address to populate with the sender address
 134      */
 135     protected abstract int peek(InetAddress i) throws IOException;
 136     protected abstract int peekData(DatagramPacket p) throws IOException;
 137     /**
 138      * Receive the datagram packet.
 139      * @param p the packet to receive into
 140      */
 141     protected synchronized void receive(DatagramPacket p)
 142         throws IOException {
 143         receive0(p);
 144     }
 145 
 146     protected abstract void receive0(DatagramPacket p)
 147         throws IOException;
 148 
 149     /**
 150      * Set the TTL (time-to-live) option.
 151      * @param ttl TTL to be set.
 152      */
 153     protected abstract void setTimeToLive(int ttl) throws IOException;
 154 
 155     /**
 156      * Get the TTL (time-to-live) option.
 157      */
 158     protected abstract int getTimeToLive() throws IOException;
 159 
 160     /**
 161      * Set the TTL (time-to-live) option.
 162      * @param ttl TTL to be set.
 163      */
 164     @Deprecated
 165     protected abstract void setTTL(byte ttl) throws IOException;
 166 
 167     /**
 168      * Get the TTL (time-to-live) option.
 169      */
 170     @Deprecated
 171     protected abstract byte getTTL() throws IOException;
 172 
 173     /**
 174      * Join the multicast group.
 175      * @param inetaddr multicast address to join.
 176      */
 177     protected void join(InetAddress inetaddr) throws IOException {
 178         join(inetaddr, null);
 179     }
 180 
 181     /**
 182      * Leave the multicast group.
 183      * @param inetaddr multicast address to leave.
 184      */
 185     protected void leave(InetAddress inetaddr) throws IOException {
 186         leave(inetaddr, null);
 187     }
 188     /**
 189      * Join the multicast group.
 190      * @param mcastaddr multicast address to join.
 191      * @param netIf specifies the local interface to receive multicast
 192      *        datagram packets
 193      * @throws  IllegalArgumentException if mcastaddr is null or is a
 194      *          SocketAddress subclass not supported by this socket
 195      * @since 1.4
 196      */
 197 
 198     protected void joinGroup(SocketAddress mcastaddr, NetworkInterface netIf)
 199         throws IOException {
 200         if (mcastaddr == null || !(mcastaddr instanceof InetSocketAddress))
 201             throw new IllegalArgumentException("Unsupported address type");
 202         join(((InetSocketAddress)mcastaddr).getAddress(), netIf);
 203     }
 204 
 205     protected abstract void join(InetAddress inetaddr, NetworkInterface netIf)
 206         throws IOException;
 207 
 208     /**
 209      * Leave the multicast group.
 210      * @param mcastaddr  multicast address to leave.
 211      * @param netIf specified the local interface to leave the group at
 212      * @throws  IllegalArgumentException if mcastaddr is null or is a
 213      *          SocketAddress subclass not supported by this socket
 214      * @since 1.4
 215      */
 216     protected void leaveGroup(SocketAddress mcastaddr, NetworkInterface netIf)
 217         throws IOException {
 218         if (mcastaddr == null || !(mcastaddr instanceof InetSocketAddress))
 219             throw new IllegalArgumentException("Unsupported address type");
 220         leave(((InetSocketAddress)mcastaddr).getAddress(), netIf);
 221     }
 222 
 223     protected abstract void leave(InetAddress inetaddr, NetworkInterface netIf)
 224         throws IOException;
 225 
 226     /**
 227      * Close the socket.
 228      */
 229     protected void close() {
 230         if (fd != null) {