diff --git a/jdk/src/share/classes/sun/net/httpserver/ServerConfig.java b/jdk/src/share/classes/sun/net/httpserver/ServerConfig.java index 0ada03ddfcc..1b791634599 100644 --- a/jdk/src/share/classes/sun/net/httpserver/ServerConfig.java +++ b/jdk/src/share/classes/sun/net/httpserver/ServerConfig.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2005, 2011, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -25,8 +25,6 @@ package sun.net.httpserver; -import com.sun.net.httpserver.*; -import com.sun.net.httpserver.spi.*; import java.util.logging.Logger; import java.security.PrivilegedAction; @@ -59,48 +57,46 @@ class ServerConfig { static long maxReqTime; static long maxRspTime; static long timerMillis; - static boolean debug = false; + static boolean debug; + + // the value of the TCP_NODELAY socket-level option + static boolean noDelay; static { + java.security.AccessController.doPrivileged( + new PrivilegedAction() { + @Override + public Void run () { + idleInterval = Long.getLong("sun.net.httpserver.idleInterval", + DEFAULT_IDLE_INTERVAL) * 1000; - idleInterval = ((Long)java.security.AccessController.doPrivileged( - new sun.security.action.GetLongAction( - "sun.net.httpserver.idleInterval", - DEFAULT_IDLE_INTERVAL))).longValue() * 1000; + clockTick = Integer.getInteger("sun.net.httpserver.clockTick", + DEFAULT_CLOCK_TICK); - clockTick = ((Integer)java.security.AccessController.doPrivileged( - new sun.security.action.GetIntegerAction( - "sun.net.httpserver.clockTick", - DEFAULT_CLOCK_TICK))).intValue(); + maxIdleConnections = Integer.getInteger( + "sun.net.httpserver.maxIdleConnections", + DEFAULT_MAX_IDLE_CONNECTIONS); - maxIdleConnections = ((Integer)java.security.AccessController.doPrivileged( - new sun.security.action.GetIntegerAction( - "sun.net.httpserver.maxIdleConnections", - DEFAULT_MAX_IDLE_CONNECTIONS))).intValue(); + drainAmount = Long.getLong("sun.net.httpserver.drainAmount", + DEFAULT_DRAIN_AMOUNT); - drainAmount = ((Long)java.security.AccessController.doPrivileged( - new sun.security.action.GetLongAction( - "sun.net.httpserver.drainAmount", - DEFAULT_DRAIN_AMOUNT))).longValue(); + maxReqTime = Long.getLong("sun.net.httpserver.maxReqTime", + DEFAULT_MAX_REQ_TIME); - maxReqTime = ((Long)java.security.AccessController.doPrivileged( - new sun.security.action.GetLongAction( - "sun.net.httpserver.maxReqTime", - DEFAULT_MAX_REQ_TIME))).longValue(); + maxRspTime = Long.getLong("sun.net.httpserver.maxRspTime", + DEFAULT_MAX_RSP_TIME); - maxRspTime = ((Long)java.security.AccessController.doPrivileged( - new sun.security.action.GetLongAction( - "sun.net.httpserver.maxRspTime", - DEFAULT_MAX_RSP_TIME))).longValue(); + timerMillis = Long.getLong("sun.net.httpserver.timerMillis", + DEFAULT_TIMER_MILLIS); - timerMillis = ((Long)java.security.AccessController.doPrivileged( - new sun.security.action.GetLongAction( - "sun.net.httpserver.timerMillis", - DEFAULT_TIMER_MILLIS))).longValue(); + debug = Boolean.getBoolean("sun.net.httpserver.debug"); + + noDelay = Boolean.getBoolean("sun.net.httpserver.nodelay"); + + return null; + } + }); - debug = ((Boolean)java.security.AccessController.doPrivileged( - new sun.security.action.GetBooleanAction( - "sun.net.httpserver.debug"))).booleanValue(); } @@ -172,4 +168,8 @@ class ServerConfig { static long getTimerMillis () { return timerMillis; } + + static boolean noDelay() { + return noDelay; + } } diff --git a/jdk/src/share/classes/sun/net/httpserver/ServerImpl.java b/jdk/src/share/classes/sun/net/httpserver/ServerImpl.java index 0fa61a8b4d8..5b53389d45f 100644 --- a/jdk/src/share/classes/sun/net/httpserver/ServerImpl.java +++ b/jdk/src/share/classes/sun/net/httpserver/ServerImpl.java @@ -27,8 +27,6 @@ package sun.net.httpserver; import java.net.*; import java.io.*; -import java.nio.*; -import java.security.*; import java.nio.channels.*; import java.util.*; import java.util.concurrent.*; @@ -36,7 +34,6 @@ import java.util.logging.Logger; import java.util.logging.Level; import javax.net.ssl.*; import com.sun.net.httpserver.*; -import com.sun.net.httpserver.spi.*; import sun.net.httpserver.HttpConnection.State; /** @@ -358,6 +355,12 @@ class ServerImpl implements TimeSource { continue; } SocketChannel chan = schan.accept(); + + // Set TCP_NODELAY, if appropriate + if (ServerConfig.noDelay()) { + chan.socket().setTcpNoDelay(true); + } + if (chan == null) { continue; /* cancel something ? */ } diff --git a/jdk/test/com/sun/net/httpserver/Test1.java b/jdk/test/com/sun/net/httpserver/Test1.java index c8d784df935..e0da2cebe4a 100644 --- a/jdk/test/com/sun/net/httpserver/Test1.java +++ b/jdk/test/com/sun/net/httpserver/Test1.java @@ -26,6 +26,7 @@ * @bug 6270015 * @run main/othervm Test1 * @run main/othervm -Dsun.net.httpserver.maxReqTime=10 Test1 + * @run main/othervm -Dsun.net.httpserver.nodelay=true Test1 * @summary Light weight HTTP server */ @@ -42,6 +43,10 @@ import javax.net.ssl.*; * - send/receive large/small file * - chunked encoding * - via http and https + * + * The test is also run with sun.net.httpserver.nodelay simply to exercise + * this option. There is no specific pass or failure related to running with + * this option. */ public class Test1 extends Test {