8219446: Specify behaviour of timeout accepting methods of Socket and ServerSocket if timeout is negative

Reviewed-by: alanb, dfuchs
This commit is contained in:
Chris Hegarty 2019-03-26 17:02:11 +00:00
parent 75dd3985ca
commit 1933437f12
3 changed files with 13 additions and 12 deletions

View file

@ -749,14 +749,17 @@ class ServerSocket implements java.io.Closeable {
* timeout must be {@code > 0}.
* A timeout of zero is interpreted as an infinite timeout.
* @param timeout the specified timeout, in milliseconds
* @exception SocketException if there is an error in
* the underlying protocol, such as a TCP error.
* @throws SocketException if there is an error in the underlying protocol,
* such as a TCP error
* @throws IllegalArgumentException if {@code timeout} is negative
* @since 1.1
* @see #getSoTimeout()
*/
public synchronized void setSoTimeout(int timeout) throws SocketException {
if (isClosed())
throw new SocketException("Socket is closed");
if (timeout < 0)
throw new IllegalArgumentException("timeout < 0");
getImpl().setOption(SocketOptions.SO_TIMEOUT, timeout);
}