src/share/classes/sun/net/NetworkClient.java
Print this page
*** 38,47 ****
--- 38,53 ----
* This is the base class for network clients.
*
* @author Jonathan Payne
*/
public class NetworkClient {
+ /* Default value of read timeout, if not specified (infinity) */
+ public static final int DEFAULT_READ_TIMEOUT = -1;
+
+ /* Default value of connect timeout, if not specified (infinity) */
+ public static final int DEFAULT_CONNECT_TIMEOUT = -1;
+
protected Proxy proxy = Proxy.NO_PROXY;
/** Socket for communicating with server. */
protected Socket serverSocket = null;
/** Stream for printing to the server. */
*** 51,62 ****
public InputStream serverInput;
protected static int defaultSoTimeout;
protected static int defaultConnectTimeout;
! protected int readTimeout = -1;
! protected int connectTimeout = -1;
/* Name of encoding to use for output */
protected static String encoding;
static {
final int vals[] = {0, 0};
--- 57,68 ----
public InputStream serverInput;
protected static int defaultSoTimeout;
protected static int defaultConnectTimeout;
! protected int readTimeout = DEFAULT_READ_TIMEOUT;
! protected int connectTimeout = DEFAULT_CONNECT_TIMEOUT;
/* Name of encoding to use for output */
protected static String encoding;
static {
final int vals[] = {0, 0};
*** 69,89 ****
vals[1] = Integer.getInteger("sun.net.client.defaultConnectTimeout", 0).intValue();
encs[0] = System.getProperty("file.encoding", "ISO8859_1");
return null;
}
});
! if (vals[0] == 0)
! defaultSoTimeout = -1;
! else
defaultSoTimeout = vals[0];
!
! if (vals[1] == 0)
! defaultConnectTimeout = -1;
! else
defaultConnectTimeout = vals[1];
-
encoding = encs[0];
try {
if (!isASCIISuperset (encoding)) {
encoding = "ISO8859_1";
}
--- 75,91 ----
vals[1] = Integer.getInteger("sun.net.client.defaultConnectTimeout", 0).intValue();
encs[0] = System.getProperty("file.encoding", "ISO8859_1");
return null;
}
});
! if (vals[0] != 0) {
defaultSoTimeout = vals[0];
! }
! if (vals[1] != 0) {
defaultConnectTimeout = vals[1];
+ }
encoding = encs[0];
try {
if (!isASCIISuperset (encoding)) {
encoding = "ISO8859_1";
}
*** 230,240 ****
--- 232,258 ----
public int getConnectTimeout() {
return connectTimeout;
}
+ /**
+ * Sets the read timeout.
+ *
+ * Note: Public URLConnection (and protocol specific implementations)
+ * protect against negative timeout values being set. This implemenation,
+ * and protocol specific implementations, use -1 to represent the default
+ * read timeout.
+ *
+ * This method may be invoked with the default timeout value when the
+ * protocol handler is trying to reset the timeout after doing a
+ * potentially blocking internal operation, e.g. cleaning up unread
+ * response data, buffering error stream response data, etc
+ */
public void setReadTimeout(int timeout) {
+ if (timeout == DEFAULT_READ_TIMEOUT)
+ timeout = defaultSoTimeout;
+
if (serverSocket != null && timeout >= 0) {
try {
serverSocket.setSoTimeout(timeout);
} catch(IOException e) {
// We tried...