mirror of
https://github.com/openjdk/jdk.git
synced 2025-08-27 06:45:07 +02:00
8219446: Specify behaviour of timeout accepting methods of Socket and ServerSocket if timeout is negative
Reviewed-by: alanb, dfuchs
This commit is contained in:
parent
75dd3985ca
commit
1933437f12
3 changed files with 13 additions and 12 deletions
|
@ -749,14 +749,17 @@ class ServerSocket implements java.io.Closeable {
|
||||||
* timeout must be {@code > 0}.
|
* timeout must be {@code > 0}.
|
||||||
* A timeout of zero is interpreted as an infinite timeout.
|
* A timeout of zero is interpreted as an infinite timeout.
|
||||||
* @param timeout the specified timeout, in milliseconds
|
* @param timeout the specified timeout, in milliseconds
|
||||||
* @exception SocketException if there is an error in
|
* @throws SocketException if there is an error in the underlying protocol,
|
||||||
* the underlying protocol, such as a TCP error.
|
* such as a TCP error
|
||||||
|
* @throws IllegalArgumentException if {@code timeout} is negative
|
||||||
* @since 1.1
|
* @since 1.1
|
||||||
* @see #getSoTimeout()
|
* @see #getSoTimeout()
|
||||||
*/
|
*/
|
||||||
public synchronized void setSoTimeout(int timeout) throws SocketException {
|
public synchronized void setSoTimeout(int timeout) throws SocketException {
|
||||||
if (isClosed())
|
if (isClosed())
|
||||||
throw new SocketException("Socket is closed");
|
throw new SocketException("Socket is closed");
|
||||||
|
if (timeout < 0)
|
||||||
|
throw new IllegalArgumentException("timeout < 0");
|
||||||
getImpl().setOption(SocketOptions.SO_TIMEOUT, timeout);
|
getImpl().setOption(SocketOptions.SO_TIMEOUT, timeout);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -581,7 +581,8 @@ class Socket implements java.io.Closeable {
|
||||||
* if this socket has an associated channel,
|
* if this socket has an associated channel,
|
||||||
* and the channel is in non-blocking mode
|
* and the channel is in non-blocking mode
|
||||||
* @throws IllegalArgumentException if endpoint is null or is a
|
* @throws IllegalArgumentException if endpoint is null or is a
|
||||||
* SocketAddress subclass not supported by this socket
|
* SocketAddress subclass not supported by this socket, or
|
||||||
|
* if {@code timeout} is negative
|
||||||
* @since 1.4
|
* @since 1.4
|
||||||
* @spec JSR-51
|
* @spec JSR-51
|
||||||
*/
|
*/
|
||||||
|
@ -1212,8 +1213,9 @@ class Socket implements java.io.Closeable {
|
||||||
* A timeout of zero is interpreted as an infinite timeout.
|
* A timeout of zero is interpreted as an infinite timeout.
|
||||||
*
|
*
|
||||||
* @param timeout the specified timeout, in milliseconds.
|
* @param timeout the specified timeout, in milliseconds.
|
||||||
* @exception SocketException if there is an error
|
* @throws SocketException if there is an error in the underlying protocol,
|
||||||
* in the underlying protocol, such as a TCP error.
|
* such as a TCP error
|
||||||
|
* @throws IllegalArgumentException if {@code timeout} is negative
|
||||||
* @since 1.1
|
* @since 1.1
|
||||||
* @see #getSoTimeout()
|
* @see #getSoTimeout()
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -85,8 +85,7 @@ public class Timeouts {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test connect with a negative timeout. This case is not currently specified
|
* Test connect with a negative timeout.
|
||||||
* but the long standing behavior is to throw IllegalArgumentException.
|
|
||||||
*/
|
*/
|
||||||
public void testTimedConnect4() throws IOException {
|
public void testTimedConnect4() throws IOException {
|
||||||
try (ServerSocket ss = new ServerSocket(0)) {
|
try (ServerSocket ss = new ServerSocket(0)) {
|
||||||
|
@ -393,8 +392,7 @@ public class Timeouts {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test Socket setSoTimeout with a negative timeout. This case is not currently
|
* Test Socket setSoTimeout with a negative timeout.
|
||||||
* specified but the long standing behavior is to throw IllegalArgumentException.
|
|
||||||
*/
|
*/
|
||||||
@Test(expectedExceptions = { IllegalArgumentException.class })
|
@Test(expectedExceptions = { IllegalArgumentException.class })
|
||||||
public void testBadTimeout1() throws IOException {
|
public void testBadTimeout1() throws IOException {
|
||||||
|
@ -404,9 +402,7 @@ public class Timeouts {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test ServerSocket setSoTimeout with a negative timeout. This case is not
|
* Test ServerSocket setSoTimeout with a negative timeout.
|
||||||
* currently specified but the long standing behavior is to throw
|
|
||||||
* IllegalArgumentException.
|
|
||||||
*/
|
*/
|
||||||
@Test(expectedExceptions = { IllegalArgumentException.class })
|
@Test(expectedExceptions = { IllegalArgumentException.class })
|
||||||
public void testBadTimeout2() throws IOException {
|
public void testBadTimeout2() throws IOException {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue