src/java.base/share/classes/java/net/DatagramSocketImpl.java
changeset 58242 94bb65cb37d3
parent 55500 80abfee2afaf
child 58679 9c3209ff7550
child 59200 a686b67a59d9
equal deleted inserted replaced
58241:33de7752835c 58242:94bb65cb37d3
    68         return 0;
    68         return 0;
    69     }
    69     }
    70 
    70 
    71     /**
    71     /**
    72      * Creates a datagram socket.
    72      * Creates a datagram socket.
    73      * @exception SocketException if there is an error in the
    73      * @throws    SocketException if there is an error in the
    74      * underlying protocol, such as a TCP error.
    74      * underlying protocol, such as a TCP error.
    75      */
    75      */
    76     protected abstract void create() throws SocketException;
    76     protected abstract void create() throws SocketException;
    77 
    77 
    78     /**
    78     /**
    79      * Binds a datagram socket to a local port and address.
    79      * Binds a datagram socket to a local port and address.
    80      * @param lport the local port
    80      * @param     lport the local port
    81      * @param laddr the local address
    81      * @param     laddr the local address
    82      * @exception SocketException if there is an error in the
    82      * @throws    SocketException if there is an error in the
    83      * underlying protocol, such as a TCP error.
    83      *            underlying protocol, such as a TCP error.
    84      */
    84      */
    85     protected abstract void bind(int lport, InetAddress laddr) throws SocketException;
    85     protected abstract void bind(int lport, InetAddress laddr) throws SocketException;
    86 
    86 
    87     /**
    87     /**
    88      * Sends a datagram packet. The packet contains the data and the
    88      * Sends a datagram packet. The packet contains the data and the
    89      * destination address to send the packet to.
    89      * destination address to send the packet to.
    90      * @param p the packet to be sent.
    90      * @param    p the packet to be sent.
    91      * @exception IOException if an I/O exception occurs while sending the
    91      * @throws   IOException if an I/O exception occurs while sending the
    92      * datagram packet.
    92      *           datagram packet.
    93      * @exception  PortUnreachableException may be thrown if the socket is connected
    93      * @throws   PortUnreachableException may be thrown if the socket is connected
    94      * to a currently unreachable destination. Note, there is no guarantee that
    94      *           to a currently unreachable destination. Note, there is no guarantee that
    95      * the exception will be thrown.
    95      *           the exception will be thrown.
    96      */
    96      */
    97     protected abstract void send(DatagramPacket p) throws IOException;
    97     protected abstract void send(DatagramPacket p) throws IOException;
    98 
    98 
    99     /**
    99     /**
   100      * Connects a datagram socket to a remote destination. This associates the remote
   100      * Connects a datagram socket to a remote destination. This associates the remote
   105      * <p>If the remote destination to which the socket is connected does not
   105      * <p>If the remote destination to which the socket is connected does not
   106      * exist, or is otherwise unreachable, and if an ICMP destination unreachable
   106      * exist, or is otherwise unreachable, and if an ICMP destination unreachable
   107      * packet has been received for that address, then a subsequent call to
   107      * packet has been received for that address, then a subsequent call to
   108      * send or receive may throw a PortUnreachableException.
   108      * send or receive may throw a PortUnreachableException.
   109      * Note, there is no guarantee that the exception will be thrown.
   109      * Note, there is no guarantee that the exception will be thrown.
   110      * @param address the remote InetAddress to connect to
   110      * @param   address the remote InetAddress to connect to
   111      * @param port the remote port number
   111      * @param   port the remote port number
   112      * @exception   SocketException may be thrown if the socket cannot be
   112      * @throws  SocketException may be thrown if the socket cannot be
   113      * connected to the remote destination
   113      *          connected to the remote destination
   114      * @since 1.4
   114      * @since   1.4
   115      */
   115      */
   116     protected void connect(InetAddress address, int port) throws SocketException {}
   116     protected void connect(InetAddress address, int port) throws SocketException {}
   117 
   117 
   118     /**
   118     /**
   119      * Disconnects a datagram socket from its remote destination.
   119      * Disconnects a datagram socket from its remote destination.
   122     protected void disconnect() {}
   122     protected void disconnect() {}
   123 
   123 
   124     /**
   124     /**
   125      * Peek at the packet to see who it is from. Updates the specified {@code InetAddress}
   125      * Peek at the packet to see who it is from. Updates the specified {@code InetAddress}
   126      * to the address which the packet came from.
   126      * to the address which the packet came from.
   127      * @param i an InetAddress object
   127      * @param     i an InetAddress object
   128      * @return the port number which the packet came from.
   128      * @return    the port number which the packet came from.
   129      * @exception IOException if an I/O exception occurs
   129      * @throws    IOException if an I/O exception occurs
   130      * @exception  PortUnreachableException may be thrown if the socket is connected
   130      * @throws    PortUnreachableException may be thrown if the socket is connected
   131      *       to a currently unreachable destination. Note, there is no guarantee that the
   131      *            to a currently unreachable destination. Note, there is no guarantee that the
   132      *       exception will be thrown.
   132      *            exception will be thrown.
   133      */
   133      */
   134     protected abstract int peek(InetAddress i) throws IOException;
   134     protected abstract int peek(InetAddress i) throws IOException;
   135 
   135 
   136     /**
   136     /**
   137      * Peek at the packet to see who it is from. The data is copied into the specified
   137      * Peek at the packet to see who it is from. The data is copied into the specified
   138      * {@code DatagramPacket}. The data is returned,
   138      * {@code DatagramPacket}. The data is returned,
   139      * but not consumed, so that a subsequent peekData/receive operation
   139      * but not consumed, so that a subsequent peekData/receive operation
   140      * will see the same data.
   140      * will see the same data.
   141      * @param p the Packet Received.
   141      * @param     p the Packet Received.
   142      * @return the port number which the packet came from.
   142      * @return    the port number which the packet came from.
   143      * @exception IOException if an I/O exception occurs
   143      * @throws    IOException if an I/O exception occurs
   144      * @exception  PortUnreachableException may be thrown if the socket is connected
   144      * @throws    PortUnreachableException may be thrown if the socket is connected
   145      *       to a currently unreachable destination. Note, there is no guarantee that the
   145      *            to a currently unreachable destination. Note, there is no guarantee that the
   146      *       exception will be thrown.
   146      *            exception will be thrown.
   147      * @since 1.4
   147      * @since 1.4
   148      */
   148      */
   149     protected abstract int peekData(DatagramPacket p) throws IOException;
   149     protected abstract int peekData(DatagramPacket p) throws IOException;
   150     /**
   150     /**
   151      * Receive the datagram packet.
   151      * Receive the datagram packet.
   152      * @param p the Packet Received.
   152      * @param     p the Packet Received.
   153      * @exception IOException if an I/O exception occurs
   153      * @throws    IOException if an I/O exception occurs
   154      * while receiving the datagram packet.
   154      *            while receiving the datagram packet.
   155      * @exception  PortUnreachableException may be thrown if the socket is connected
   155      * @throws    PortUnreachableException may be thrown if the socket is connected
   156      *       to a currently unreachable destination. Note, there is no guarantee that the
   156      *            to a currently unreachable destination. Note, there is no guarantee that the
   157      *       exception will be thrown.
   157      *            exception will be thrown.
   158      */
   158      */
   159     protected abstract void receive(DatagramPacket p) throws IOException;
   159     protected abstract void receive(DatagramPacket p) throws IOException;
   160 
   160 
   161     /**
   161     /**
   162      * Set the TTL (time-to-live) option.
   162      * Set the TTL (time-to-live) option.
   163      * @param ttl a byte specifying the TTL value
   163      * @param ttl a byte specifying the TTL value
   164      *
   164      *
   165      * @deprecated use setTimeToLive instead.
   165      * @deprecated use setTimeToLive instead.
   166      * @exception IOException if an I/O exception occurs while setting
   166      * @throws    IOException if an I/O exception occurs while setting
   167      * the time-to-live option.
   167      * the time-to-live option.
   168      * @see #getTTL()
   168      * @see #getTTL()
   169      */
   169      */
   170     @Deprecated
   170     @Deprecated
   171     protected abstract void setTTL(byte ttl) throws IOException;
   171     protected abstract void setTTL(byte ttl) throws IOException;
   172 
   172 
   173     /**
   173     /**
   174      * Retrieve the TTL (time-to-live) option.
   174      * Retrieve the TTL (time-to-live) option.
   175      *
   175      *
   176      * @exception IOException if an I/O exception occurs
   176      * @throws    IOException if an I/O exception occurs
   177      * while retrieving the time-to-live option
   177      * while retrieving the time-to-live option
   178      * @deprecated use getTimeToLive instead.
   178      * @deprecated use getTimeToLive instead.
   179      * @return a byte representing the TTL value
   179      * @return a byte representing the TTL value
   180      * @see #setTTL(byte)
   180      * @see #setTTL(byte)
   181      */
   181      */
   183     protected abstract byte getTTL() throws IOException;
   183     protected abstract byte getTTL() throws IOException;
   184 
   184 
   185     /**
   185     /**
   186      * Set the TTL (time-to-live) option.
   186      * Set the TTL (time-to-live) option.
   187      * @param ttl an {@code int} specifying the time-to-live value
   187      * @param ttl an {@code int} specifying the time-to-live value
   188      * @exception IOException if an I/O exception occurs
   188      * @throws    IOException if an I/O exception occurs
   189      * while setting the time-to-live option.
   189      * while setting the time-to-live option.
   190      * @see #getTimeToLive()
   190      * @see #getTimeToLive()
   191      */
   191      */
   192     protected abstract void setTimeToLive(int ttl) throws IOException;
   192     protected abstract void setTimeToLive(int ttl) throws IOException;
   193 
   193 
   194     /**
   194     /**
   195      * Retrieve the TTL (time-to-live) option.
   195      * Retrieve the TTL (time-to-live) option.
   196      * @exception IOException if an I/O exception occurs
   196      * @throws    IOException if an I/O exception occurs
   197      * while retrieving the time-to-live option
   197      * while retrieving the time-to-live option
   198      * @return an {@code int} representing the time-to-live value
   198      * @return an {@code int} representing the time-to-live value
   199      * @see #setTimeToLive(int)
   199      * @see #setTimeToLive(int)
   200      */
   200      */
   201     protected abstract int getTimeToLive() throws IOException;
   201     protected abstract int getTimeToLive() throws IOException;
   202 
   202 
   203     /**
   203     /**
   204      * Join the multicast group.
   204      * Join the multicast group.
   205      * @param inetaddr multicast address to join.
   205      * @param inetaddr multicast address to join.
   206      * @exception IOException if an I/O exception occurs
   206      * @throws    IOException if an I/O exception occurs
   207      * while joining the multicast group.
   207      * while joining the multicast group.
   208      */
   208      */
   209     protected abstract void join(InetAddress inetaddr) throws IOException;
   209     protected abstract void join(InetAddress inetaddr) throws IOException;
   210 
   210 
   211     /**
   211     /**
   212      * Leave the multicast group.
   212      * Leave the multicast group.
   213      * @param inetaddr multicast address to leave.
   213      * @param inetaddr multicast address to leave.
   214      * @exception IOException if an I/O exception occurs
   214      * @throws    IOException if an I/O exception occurs
   215      * while leaving the multicast group.
   215      * while leaving the multicast group.
   216      */
   216      */
   217     protected abstract void leave(InetAddress inetaddr) throws IOException;
   217     protected abstract void leave(InetAddress inetaddr) throws IOException;
   218 
   218 
   219     /**
   219     /**
   270      * The default implementation of this method first checks that the given
   270      * The default implementation of this method first checks that the given
   271      * socket option {@code name} is not null, then throws {@code
   271      * socket option {@code name} is not null, then throws {@code
   272      * UnsupportedOperationException}. Subclasses should override this method
   272      * UnsupportedOperationException}. Subclasses should override this method
   273      * with an appropriate implementation.
   273      * with an appropriate implementation.
   274      *
   274      *
   275      * @param <T> The type of the socket option value
   275      * @param  <T> The type of the socket option value
   276      * @param name The socket option
   276      * @param  name The socket option
   277      * @param value The value of the socket option. A value of {@code null}
   277      * @param  value The value of the socket option. A value of {@code null}
   278      *              may be valid for some options.
   278      *              may be valid for some options.
   279      *
   279      *
   280      * @throws UnsupportedOperationException if the DatagramSocketImpl does not
   280      * @throws UnsupportedOperationException if the DatagramSocketImpl does not
   281      *         support the option
   281      *         support the option
   282      * @throws IllegalArgumentException if the value is not valid for
   282      * @throws IllegalArgumentException if the value is not valid for
   298      * The default implementation of this method first checks that the given
   298      * The default implementation of this method first checks that the given
   299      * socket option {@code name} is not null, then throws {@code
   299      * socket option {@code name} is not null, then throws {@code
   300      * UnsupportedOperationException}. Subclasses should override this method
   300      * UnsupportedOperationException}. Subclasses should override this method
   301      * with an appropriate implementation.
   301      * with an appropriate implementation.
   302      *
   302      *
   303      * @param <T> The type of the socket option value
   303      * @param  <T> The type of the socket option value
   304      * @param name The socket option
   304      * @param  name The socket option
   305      * @return the socket option
   305      * @return the socket option
   306      *
   306      *
   307      * @throws UnsupportedOperationException if the DatagramSocketImpl does not
   307      * @throws UnsupportedOperationException if the DatagramSocketImpl does not
   308      *         support the option
   308      *         support the option
   309      * @throws IOException if an I/O error occurs, or if the socket is closed
   309      * @throws IOException if an I/O error occurs, or if the socket is closed