Added sndBufSize / rcvBufSize parameters to IOReactorConfig
git-svn-id: https://svn.apache.org/repos/asf/httpcomponents/httpcore/branches/4.2.x@1444384 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/httpcore-nio/src/main/java/org/apache/http/impl/nio/reactor/AbstractMultiworkerIOReactor.java b/httpcore-nio/src/main/java/org/apache/http/impl/nio/reactor/AbstractMultiworkerIOReactor.java
index 38c4e08..62519c0 100644
--- a/httpcore-nio/src/main/java/org/apache/http/impl/nio/reactor/AbstractMultiworkerIOReactor.java
+++ b/httpcore-nio/src/main/java/org/apache/http/impl/nio/reactor/AbstractMultiworkerIOReactor.java
@@ -523,8 +523,17 @@
*/
protected void prepareSocket(final Socket socket) throws IOException {
socket.setTcpNoDelay(this.config.isTcpNoDelay());
- socket.setSoTimeout(this.config.getSoTimeout());
socket.setKeepAlive(this.config.isSoKeepalive());
+ socket.setReuseAddress(this.config.isSoReuseAddress());
+ if (this.config.getSoTimeout() > 0) {
+ socket.setSoTimeout(this.config.getSoTimeout());
+ }
+ if (this.config.getSndBufSize() > 0) {
+ socket.setSendBufferSize(this.config.getSndBufSize());
+ }
+ if (this.config.getRcvBufSize() > 0) {
+ socket.setReceiveBufferSize(this.config.getRcvBufSize());
+ }
int linger = this.config.getSoLinger();
if (linger >= 0) {
socket.setSoLinger(linger > 0, linger);
diff --git a/httpcore-nio/src/main/java/org/apache/http/impl/nio/reactor/DefaultListeningIOReactor.java b/httpcore-nio/src/main/java/org/apache/http/impl/nio/reactor/DefaultListeningIOReactor.java
index 2a24c98..b1a2ac6 100644
--- a/httpcore-nio/src/main/java/org/apache/http/impl/nio/reactor/DefaultListeningIOReactor.java
+++ b/httpcore-nio/src/main/java/org/apache/http/impl/nio/reactor/DefaultListeningIOReactor.java
@@ -28,6 +28,7 @@
package org.apache.http.impl.nio.reactor;
import java.io.IOException;
+import java.net.ServerSocket;
import java.net.SocketAddress;
import java.nio.channels.CancelledKeyException;
import java.nio.channels.SelectionKey;
@@ -231,8 +232,10 @@
throw new IOReactorException("Failure opening server socket", ex);
}
try {
+ ServerSocket socket = serverChannel.socket();
+ socket.setReuseAddress(this.config.isSoReuseAddress());
serverChannel.configureBlocking(false);
- serverChannel.socket().bind(address);
+ socket.bind(address);
} catch (IOException ex) {
closeChannel(serverChannel);
request.failed(ex);
diff --git a/httpcore-nio/src/main/java/org/apache/http/impl/nio/reactor/IOReactorConfig.java b/httpcore-nio/src/main/java/org/apache/http/impl/nio/reactor/IOReactorConfig.java
index 562257e..f555b39 100644
--- a/httpcore-nio/src/main/java/org/apache/http/impl/nio/reactor/IOReactorConfig.java
+++ b/httpcore-nio/src/main/java/org/apache/http/impl/nio/reactor/IOReactorConfig.java
@@ -41,7 +41,7 @@
public final class IOReactorConfig implements Cloneable {
private static final int AVAIL_PROCS = Runtime.getRuntime().availableProcessors();
-
+
private long selectInterval;
private long shutdownGracePeriod;
private boolean interestOpQueued;
@@ -52,6 +52,8 @@
private boolean soKeepAlive;
private boolean tcpNoDelay;
private int connectTimeout;
+ private int sndBufSize;
+ private int rcvBufSize;
public IOReactorConfig() {
super();
@@ -285,6 +287,50 @@
this.connectTimeout = connectTimeout;
}
+ /**
+ * Determines the default value of the {@link SocketOptions#SO_SNDBUF} parameter
+ * for newly created sockets.
+ * <p/>
+ * Default: <code>0</code> (system default)
+ *
+ * @see SocketOptions#SO_SNDBUF
+ */
+ public int getSndBufSize() {
+ return sndBufSize;
+ }
+
+ /**
+ * Defines the default value of the {@link SocketOptions#SO_SNDBUF} parameter
+ * for newly created sockets.
+ *
+ * @see SocketOptions#SO_SNDBUF
+ */
+ public void setSndBufSize(int sndBufSize) {
+ this.sndBufSize = sndBufSize;
+ }
+
+ /**
+ * Determines the default value of the {@link SocketOptions#SO_RCVBUF} parameter
+ * for newly created sockets.
+ * <p/>
+ * Default: <code>0</code> (system default)
+ *
+ * @see SocketOptions#SO_RCVBUF
+ */
+ public int getRcvBufSize() {
+ return rcvBufSize;
+ }
+
+ /**
+ * Defines the default value of the {@link SocketOptions#SO_RCVBUF} parameter
+ * for newly created sockets.
+ *
+ * @see SocketOptions#SO_RCVBUF
+ */
+ public void setRcvBufSize(int rcvBufSize) {
+ this.rcvBufSize = rcvBufSize;
+ }
+
@Override
protected IOReactorConfig clone() throws CloneNotSupportedException {
return (IOReactorConfig) super.clone();
@@ -302,7 +348,10 @@
.append(", soLinger=").append(this.soLinger)
.append(", soKeepAlive=").append(this.soKeepAlive)
.append(", tcpNoDelay=").append(this.tcpNoDelay)
- .append(", connectTimeout=").append(this.connectTimeout).append("]");
+ .append(", connectTimeout=").append(this.connectTimeout)
+ .append(", sndBufSize=").append(this.sndBufSize)
+ .append(", rcvBufSize=").append(this.rcvBufSize)
+ .append("]");
return builder.toString();
}