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
src/java.base/share/classes/java/net
test/jdk/java/net/Socket
@ -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);
|
||||
}
|
||||
|
||||
|
@ -581,7 +581,8 @@ class Socket implements java.io.Closeable {
|
||||
* if this socket has an associated channel,
|
||||
* and the channel is in non-blocking mode
|
||||
* @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
|
||||
* @spec JSR-51
|
||||
*/
|
||||
@ -1212,8 +1213,9 @@ class Socket implements java.io.Closeable {
|
||||
* 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()
|
||||
*/
|
||||
|
@ -85,8 +85,7 @@ public class Timeouts {
|
||||
}
|
||||
|
||||
/**
|
||||
* Test connect with a negative timeout. This case is not currently specified
|
||||
* but the long standing behavior is to throw IllegalArgumentException.
|
||||
* Test connect with a negative timeout.
|
||||
*/
|
||||
public void testTimedConnect4() throws IOException {
|
||||
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
|
||||
* specified but the long standing behavior is to throw IllegalArgumentException.
|
||||
* Test Socket setSoTimeout with a negative timeout.
|
||||
*/
|
||||
@Test(expectedExceptions = { IllegalArgumentException.class })
|
||||
public void testBadTimeout1() throws IOException {
|
||||
@ -404,9 +402,7 @@ public class Timeouts {
|
||||
}
|
||||
|
||||
/**
|
||||
* Test ServerSocket setSoTimeout with a negative timeout. This case is not
|
||||
* currently specified but the long standing behavior is to throw
|
||||
* IllegalArgumentException.
|
||||
* Test ServerSocket setSoTimeout with a negative timeout.
|
||||
*/
|
||||
@Test(expectedExceptions = { IllegalArgumentException.class })
|
||||
public void testBadTimeout2() throws IOException {
|
||||
|
Loading…
x
Reference in New Issue
Block a user