提交 31842b4a 编写于 作者: C chegar

7068416: Lightweight HTTP Server should support TCP_NODELAY

Reviewed-by: alanb, michaelm
上级 7bb451c3
/* /*
* 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. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
...@@ -25,8 +25,6 @@ ...@@ -25,8 +25,6 @@
package sun.net.httpserver; package sun.net.httpserver;
import com.sun.net.httpserver.*;
import com.sun.net.httpserver.spi.*;
import java.util.logging.Logger; import java.util.logging.Logger;
import java.security.PrivilegedAction; import java.security.PrivilegedAction;
...@@ -59,48 +57,46 @@ class ServerConfig { ...@@ -59,48 +57,46 @@ class ServerConfig {
static long maxReqTime; static long maxReqTime;
static long maxRspTime; static long maxRspTime;
static long timerMillis; static long timerMillis;
static boolean debug = false; static boolean debug;
static { // the value of the TCP_NODELAY socket-level option
static boolean noDelay;
idleInterval = ((Long)java.security.AccessController.doPrivileged( static {
new sun.security.action.GetLongAction( java.security.AccessController.doPrivileged(
"sun.net.httpserver.idleInterval", new PrivilegedAction<Void>() {
DEFAULT_IDLE_INTERVAL))).longValue() * 1000; @Override
public Void run () {
idleInterval = Long.getLong("sun.net.httpserver.idleInterval",
DEFAULT_IDLE_INTERVAL) * 1000;
clockTick = ((Integer)java.security.AccessController.doPrivileged( clockTick = Integer.getInteger("sun.net.httpserver.clockTick",
new sun.security.action.GetIntegerAction( DEFAULT_CLOCK_TICK);
"sun.net.httpserver.clockTick",
DEFAULT_CLOCK_TICK))).intValue();
maxIdleConnections = ((Integer)java.security.AccessController.doPrivileged( maxIdleConnections = Integer.getInteger(
new sun.security.action.GetIntegerAction(
"sun.net.httpserver.maxIdleConnections", "sun.net.httpserver.maxIdleConnections",
DEFAULT_MAX_IDLE_CONNECTIONS))).intValue(); DEFAULT_MAX_IDLE_CONNECTIONS);
drainAmount = Long.getLong("sun.net.httpserver.drainAmount",
DEFAULT_DRAIN_AMOUNT);
drainAmount = ((Long)java.security.AccessController.doPrivileged( maxReqTime = Long.getLong("sun.net.httpserver.maxReqTime",
new sun.security.action.GetLongAction( DEFAULT_MAX_REQ_TIME);
"sun.net.httpserver.drainAmount",
DEFAULT_DRAIN_AMOUNT))).longValue();
maxReqTime = ((Long)java.security.AccessController.doPrivileged( maxRspTime = Long.getLong("sun.net.httpserver.maxRspTime",
new sun.security.action.GetLongAction( DEFAULT_MAX_RSP_TIME);
"sun.net.httpserver.maxReqTime",
DEFAULT_MAX_REQ_TIME))).longValue();
maxRspTime = ((Long)java.security.AccessController.doPrivileged( timerMillis = Long.getLong("sun.net.httpserver.timerMillis",
new sun.security.action.GetLongAction( DEFAULT_TIMER_MILLIS);
"sun.net.httpserver.maxRspTime",
DEFAULT_MAX_RSP_TIME))).longValue();
timerMillis = ((Long)java.security.AccessController.doPrivileged( debug = Boolean.getBoolean("sun.net.httpserver.debug");
new sun.security.action.GetLongAction(
"sun.net.httpserver.timerMillis", noDelay = Boolean.getBoolean("sun.net.httpserver.nodelay");
DEFAULT_TIMER_MILLIS))).longValue();
return null;
}
});
debug = ((Boolean)java.security.AccessController.doPrivileged(
new sun.security.action.GetBooleanAction(
"sun.net.httpserver.debug"))).booleanValue();
} }
...@@ -172,4 +168,8 @@ class ServerConfig { ...@@ -172,4 +168,8 @@ class ServerConfig {
static long getTimerMillis () { static long getTimerMillis () {
return timerMillis; return timerMillis;
} }
static boolean noDelay() {
return noDelay;
}
} }
...@@ -27,8 +27,6 @@ package sun.net.httpserver; ...@@ -27,8 +27,6 @@ package sun.net.httpserver;
import java.net.*; import java.net.*;
import java.io.*; import java.io.*;
import java.nio.*;
import java.security.*;
import java.nio.channels.*; import java.nio.channels.*;
import java.util.*; import java.util.*;
import java.util.concurrent.*; import java.util.concurrent.*;
...@@ -36,7 +34,6 @@ import java.util.logging.Logger; ...@@ -36,7 +34,6 @@ import java.util.logging.Logger;
import java.util.logging.Level; import java.util.logging.Level;
import javax.net.ssl.*; import javax.net.ssl.*;
import com.sun.net.httpserver.*; import com.sun.net.httpserver.*;
import com.sun.net.httpserver.spi.*;
import sun.net.httpserver.HttpConnection.State; import sun.net.httpserver.HttpConnection.State;
/** /**
...@@ -358,6 +355,12 @@ class ServerImpl implements TimeSource { ...@@ -358,6 +355,12 @@ class ServerImpl implements TimeSource {
continue; continue;
} }
SocketChannel chan = schan.accept(); SocketChannel chan = schan.accept();
// Set TCP_NODELAY, if appropriate
if (ServerConfig.noDelay()) {
chan.socket().setTcpNoDelay(true);
}
if (chan == null) { if (chan == null) {
continue; /* cancel something ? */ continue; /* cancel something ? */
} }
......
...@@ -26,6 +26,7 @@ ...@@ -26,6 +26,7 @@
* @bug 6270015 * @bug 6270015
* @run main/othervm Test1 * @run main/othervm Test1
* @run main/othervm -Dsun.net.httpserver.maxReqTime=10 Test1 * @run main/othervm -Dsun.net.httpserver.maxReqTime=10 Test1
* @run main/othervm -Dsun.net.httpserver.nodelay=true Test1
* @summary Light weight HTTP server * @summary Light weight HTTP server
*/ */
...@@ -42,6 +43,10 @@ import javax.net.ssl.*; ...@@ -42,6 +43,10 @@ import javax.net.ssl.*;
* - send/receive large/small file * - send/receive large/small file
* - chunked encoding * - chunked encoding
* - via http and https * - 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 { public class Test1 extends Test {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册