提交 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.
*
* 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<Void>() {
@Override
public Void run () {
idleInterval = Long.getLong("sun.net.httpserver.idleInterval",
DEFAULT_IDLE_INTERVAL) * 1000;
clockTick = Integer.getInteger("sun.net.httpserver.clockTick",
DEFAULT_CLOCK_TICK);
maxIdleConnections = Integer.getInteger(
"sun.net.httpserver.maxIdleConnections",
DEFAULT_MAX_IDLE_CONNECTIONS);
drainAmount = Long.getLong("sun.net.httpserver.drainAmount",
DEFAULT_DRAIN_AMOUNT);
maxReqTime = Long.getLong("sun.net.httpserver.maxReqTime",
DEFAULT_MAX_REQ_TIME);
maxRspTime = Long.getLong("sun.net.httpserver.maxRspTime",
DEFAULT_MAX_RSP_TIME);
timerMillis = Long.getLong("sun.net.httpserver.timerMillis",
DEFAULT_TIMER_MILLIS);
debug = Boolean.getBoolean("sun.net.httpserver.debug");
noDelay = Boolean.getBoolean("sun.net.httpserver.nodelay");
return null;
}
});
idleInterval = ((Long)java.security.AccessController.doPrivileged(
new sun.security.action.GetLongAction(
"sun.net.httpserver.idleInterval",
DEFAULT_IDLE_INTERVAL))).longValue() * 1000;
clockTick = ((Integer)java.security.AccessController.doPrivileged(
new sun.security.action.GetIntegerAction(
"sun.net.httpserver.clockTick",
DEFAULT_CLOCK_TICK))).intValue();
maxIdleConnections = ((Integer)java.security.AccessController.doPrivileged(
new sun.security.action.GetIntegerAction(
"sun.net.httpserver.maxIdleConnections",
DEFAULT_MAX_IDLE_CONNECTIONS))).intValue();
drainAmount = ((Long)java.security.AccessController.doPrivileged(
new sun.security.action.GetLongAction(
"sun.net.httpserver.drainAmount",
DEFAULT_DRAIN_AMOUNT))).longValue();
maxReqTime = ((Long)java.security.AccessController.doPrivileged(
new sun.security.action.GetLongAction(
"sun.net.httpserver.maxReqTime",
DEFAULT_MAX_REQ_TIME))).longValue();
maxRspTime = ((Long)java.security.AccessController.doPrivileged(
new sun.security.action.GetLongAction(
"sun.net.httpserver.maxRspTime",
DEFAULT_MAX_RSP_TIME))).longValue();
timerMillis = ((Long)java.security.AccessController.doPrivileged(
new sun.security.action.GetLongAction(
"sun.net.httpserver.timerMillis",
DEFAULT_TIMER_MILLIS))).longValue();
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;
}
}
......@@ -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 ? */
}
......
......@@ -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 {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册