2014-02-15 22:26:36 +01:00
|
|
|
/*
|
|
|
|
* Copyright 2014 The Netty Project
|
|
|
|
*
|
|
|
|
* The Netty Project licenses this file to you under the Apache License,
|
|
|
|
* version 2.0 (the "License"); you may not use this file except in compliance
|
|
|
|
* with the License. You may obtain a copy of the License at:
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
|
|
|
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
|
|
|
* License for the specific language governing permissions and limitations
|
|
|
|
* under the License.
|
|
|
|
*/
|
|
|
|
package io.netty.channel.epoll;
|
|
|
|
|
|
|
|
import io.netty.buffer.ByteBufAllocator;
|
2016-03-15 10:38:25 +01:00
|
|
|
import io.netty.channel.ChannelException;
|
2014-02-15 22:26:36 +01:00
|
|
|
import io.netty.channel.ChannelOption;
|
|
|
|
import io.netty.channel.MessageSizeEstimator;
|
|
|
|
import io.netty.channel.RecvByteBufAllocator;
|
2016-03-30 04:33:35 +02:00
|
|
|
import io.netty.channel.WriteBufferWaterMark;
|
2014-02-15 22:26:36 +01:00
|
|
|
import io.netty.channel.socket.SocketChannelConfig;
|
|
|
|
import io.netty.util.internal.PlatformDependent;
|
|
|
|
|
2016-03-15 10:38:25 +01:00
|
|
|
import java.io.IOException;
|
2015-08-30 12:11:41 +02:00
|
|
|
import java.net.InetAddress;
|
2014-02-15 22:26:36 +01:00
|
|
|
import java.util.Map;
|
|
|
|
|
2017-01-19 17:31:34 +01:00
|
|
|
import static io.netty.channel.ChannelOption.ALLOW_HALF_CLOSURE;
|
|
|
|
import static io.netty.channel.ChannelOption.IP_TOS;
|
|
|
|
import static io.netty.channel.ChannelOption.SO_KEEPALIVE;
|
|
|
|
import static io.netty.channel.ChannelOption.SO_LINGER;
|
|
|
|
import static io.netty.channel.ChannelOption.SO_RCVBUF;
|
|
|
|
import static io.netty.channel.ChannelOption.SO_REUSEADDR;
|
|
|
|
import static io.netty.channel.ChannelOption.SO_SNDBUF;
|
|
|
|
import static io.netty.channel.ChannelOption.TCP_NODELAY;
|
2014-02-15 22:26:36 +01:00
|
|
|
|
2015-01-29 06:49:14 +01:00
|
|
|
public final class EpollSocketChannelConfig extends EpollChannelConfig implements SocketChannelConfig {
|
2014-02-15 22:26:36 +01:00
|
|
|
private volatile boolean allowHalfClosure;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Creates a new instance.
|
|
|
|
*/
|
|
|
|
EpollSocketChannelConfig(EpollSocketChannel channel) {
|
|
|
|
super(channel);
|
|
|
|
|
|
|
|
if (PlatformDependent.canEnableTcpNoDelayByDefault()) {
|
|
|
|
setTcpNoDelay(true);
|
|
|
|
}
|
2017-12-08 01:00:52 +01:00
|
|
|
calculateMaxBytesPerGatheringWrite();
|
2014-02-15 22:26:36 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public Map<ChannelOption<?>, Object> getOptions() {
|
|
|
|
return getOptions(
|
|
|
|
super.getOptions(),
|
|
|
|
SO_RCVBUF, SO_SNDBUF, TCP_NODELAY, SO_KEEPALIVE, SO_REUSEADDR, SO_LINGER, IP_TOS,
|
2015-05-28 03:37:56 +02:00
|
|
|
ALLOW_HALF_CLOSURE, EpollChannelOption.TCP_CORK, EpollChannelOption.TCP_NOTSENT_LOWAT,
|
2015-08-30 12:11:41 +02:00
|
|
|
EpollChannelOption.TCP_KEEPCNT, EpollChannelOption.TCP_KEEPIDLE, EpollChannelOption.TCP_KEEPINTVL,
|
2017-10-26 17:17:02 +02:00
|
|
|
EpollChannelOption.TCP_MD5SIG, EpollChannelOption.TCP_QUICKACK, EpollChannelOption.IP_TRANSPARENT,
|
2018-09-07 20:50:51 +02:00
|
|
|
EpollChannelOption.TCP_FASTOPEN_CONNECT, EpollChannelOption.SO_BUSY_POLL);
|
2014-02-15 22:26:36 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@SuppressWarnings("unchecked")
|
|
|
|
@Override
|
|
|
|
public <T> T getOption(ChannelOption<T> option) {
|
|
|
|
if (option == SO_RCVBUF) {
|
|
|
|
return (T) Integer.valueOf(getReceiveBufferSize());
|
|
|
|
}
|
|
|
|
if (option == SO_SNDBUF) {
|
|
|
|
return (T) Integer.valueOf(getSendBufferSize());
|
|
|
|
}
|
|
|
|
if (option == TCP_NODELAY) {
|
|
|
|
return (T) Boolean.valueOf(isTcpNoDelay());
|
|
|
|
}
|
|
|
|
if (option == SO_KEEPALIVE) {
|
|
|
|
return (T) Boolean.valueOf(isKeepAlive());
|
|
|
|
}
|
|
|
|
if (option == SO_REUSEADDR) {
|
|
|
|
return (T) Boolean.valueOf(isReuseAddress());
|
|
|
|
}
|
|
|
|
if (option == SO_LINGER) {
|
|
|
|
return (T) Integer.valueOf(getSoLinger());
|
|
|
|
}
|
|
|
|
if (option == IP_TOS) {
|
|
|
|
return (T) Integer.valueOf(getTrafficClass());
|
|
|
|
}
|
|
|
|
if (option == ALLOW_HALF_CLOSURE) {
|
|
|
|
return (T) Boolean.valueOf(isAllowHalfClosure());
|
|
|
|
}
|
|
|
|
if (option == EpollChannelOption.TCP_CORK) {
|
|
|
|
return (T) Boolean.valueOf(isTcpCork());
|
|
|
|
}
|
2015-05-28 03:37:56 +02:00
|
|
|
if (option == EpollChannelOption.TCP_NOTSENT_LOWAT) {
|
|
|
|
return (T) Long.valueOf(getTcpNotSentLowAt());
|
|
|
|
}
|
2014-04-17 21:41:04 +02:00
|
|
|
if (option == EpollChannelOption.TCP_KEEPIDLE) {
|
|
|
|
return (T) Integer.valueOf(getTcpKeepIdle());
|
|
|
|
}
|
|
|
|
if (option == EpollChannelOption.TCP_KEEPINTVL) {
|
|
|
|
return (T) Integer.valueOf(getTcpKeepIntvl());
|
|
|
|
}
|
|
|
|
if (option == EpollChannelOption.TCP_KEEPCNT) {
|
|
|
|
return (T) Integer.valueOf(getTcpKeepCnt());
|
|
|
|
}
|
2015-08-31 00:11:39 +02:00
|
|
|
if (option == EpollChannelOption.TCP_USER_TIMEOUT) {
|
|
|
|
return (T) Integer.valueOf(getTcpUserTimeout());
|
|
|
|
}
|
2016-03-04 10:32:11 +01:00
|
|
|
if (option == EpollChannelOption.TCP_QUICKACK) {
|
|
|
|
return (T) Boolean.valueOf(isTcpQuickAck());
|
|
|
|
}
|
2017-07-30 11:48:57 +02:00
|
|
|
if (option == EpollChannelOption.IP_TRANSPARENT) {
|
|
|
|
return (T) Boolean.valueOf(isIpTransparent());
|
|
|
|
}
|
2017-10-26 17:17:02 +02:00
|
|
|
if (option == EpollChannelOption.TCP_FASTOPEN_CONNECT) {
|
|
|
|
return (T) Boolean.valueOf(isTcpFastOpenConnect());
|
|
|
|
}
|
2018-09-07 20:50:51 +02:00
|
|
|
if (option == EpollChannelOption.SO_BUSY_POLL) {
|
|
|
|
return (T) Integer.valueOf(getSoBusyPoll());
|
|
|
|
}
|
2014-02-15 22:26:36 +01:00
|
|
|
return super.getOption(option);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public <T> boolean setOption(ChannelOption<T> option, T value) {
|
|
|
|
validate(option, value);
|
|
|
|
|
|
|
|
if (option == SO_RCVBUF) {
|
|
|
|
setReceiveBufferSize((Integer) value);
|
|
|
|
} else if (option == SO_SNDBUF) {
|
|
|
|
setSendBufferSize((Integer) value);
|
|
|
|
} else if (option == TCP_NODELAY) {
|
|
|
|
setTcpNoDelay((Boolean) value);
|
|
|
|
} else if (option == SO_KEEPALIVE) {
|
|
|
|
setKeepAlive((Boolean) value);
|
|
|
|
} else if (option == SO_REUSEADDR) {
|
|
|
|
setReuseAddress((Boolean) value);
|
|
|
|
} else if (option == SO_LINGER) {
|
|
|
|
setSoLinger((Integer) value);
|
|
|
|
} else if (option == IP_TOS) {
|
|
|
|
setTrafficClass((Integer) value);
|
|
|
|
} else if (option == ALLOW_HALF_CLOSURE) {
|
|
|
|
setAllowHalfClosure((Boolean) value);
|
|
|
|
} else if (option == EpollChannelOption.TCP_CORK) {
|
|
|
|
setTcpCork((Boolean) value);
|
2015-05-28 03:37:56 +02:00
|
|
|
} else if (option == EpollChannelOption.TCP_NOTSENT_LOWAT) {
|
|
|
|
setTcpNotSentLowAt((Long) value);
|
2014-04-17 21:41:04 +02:00
|
|
|
} else if (option == EpollChannelOption.TCP_KEEPIDLE) {
|
|
|
|
setTcpKeepIdle((Integer) value);
|
|
|
|
} else if (option == EpollChannelOption.TCP_KEEPCNT) {
|
2017-06-27 19:07:27 +02:00
|
|
|
setTcpKeepCnt((Integer) value);
|
2014-04-17 21:41:04 +02:00
|
|
|
} else if (option == EpollChannelOption.TCP_KEEPINTVL) {
|
|
|
|
setTcpKeepIntvl((Integer) value);
|
2015-08-31 00:11:39 +02:00
|
|
|
} else if (option == EpollChannelOption.TCP_USER_TIMEOUT) {
|
|
|
|
setTcpUserTimeout((Integer) value);
|
2017-07-30 11:48:57 +02:00
|
|
|
} else if (option == EpollChannelOption.IP_TRANSPARENT) {
|
|
|
|
setIpTransparent((Boolean) value);
|
2015-08-30 12:11:41 +02:00
|
|
|
} else if (option == EpollChannelOption.TCP_MD5SIG) {
|
|
|
|
@SuppressWarnings("unchecked")
|
|
|
|
final Map<InetAddress, byte[]> m = (Map<InetAddress, byte[]>) value;
|
|
|
|
setTcpMd5Sig(m);
|
2016-03-04 10:32:11 +01:00
|
|
|
} else if (option == EpollChannelOption.TCP_QUICKACK) {
|
|
|
|
setTcpQuickAck((Boolean) value);
|
2017-10-26 17:17:02 +02:00
|
|
|
} else if (option == EpollChannelOption.TCP_FASTOPEN_CONNECT) {
|
|
|
|
setTcpFastOpenConnect((Boolean) value);
|
2018-09-07 20:50:51 +02:00
|
|
|
} else if (option == EpollChannelOption.SO_BUSY_POLL) {
|
|
|
|
setSoBusyPoll((Integer) value);
|
2014-02-15 22:26:36 +01:00
|
|
|
} else {
|
|
|
|
return super.setOption(option, value);
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public int getReceiveBufferSize() {
|
2016-03-15 10:38:25 +01:00
|
|
|
try {
|
2018-09-28 17:37:14 +02:00
|
|
|
return ((EpollSocketChannel) channel).socket.getReceiveBufferSize();
|
2016-03-15 10:38:25 +01:00
|
|
|
} catch (IOException e) {
|
|
|
|
throw new ChannelException(e);
|
|
|
|
}
|
2014-02-15 22:26:36 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public int getSendBufferSize() {
|
2016-03-15 10:38:25 +01:00
|
|
|
try {
|
2018-09-28 17:37:14 +02:00
|
|
|
return ((EpollSocketChannel) channel).socket.getSendBufferSize();
|
2016-03-15 10:38:25 +01:00
|
|
|
} catch (IOException e) {
|
|
|
|
throw new ChannelException(e);
|
|
|
|
}
|
2014-02-15 22:26:36 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public int getSoLinger() {
|
2016-03-15 10:38:25 +01:00
|
|
|
try {
|
2018-09-28 17:37:14 +02:00
|
|
|
return ((EpollSocketChannel) channel).socket.getSoLinger();
|
2016-03-15 10:38:25 +01:00
|
|
|
} catch (IOException e) {
|
|
|
|
throw new ChannelException(e);
|
|
|
|
}
|
2014-02-15 22:26:36 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public int getTrafficClass() {
|
2016-03-15 10:38:25 +01:00
|
|
|
try {
|
2018-09-28 17:37:14 +02:00
|
|
|
return ((EpollSocketChannel) channel).socket.getTrafficClass();
|
2016-03-15 10:38:25 +01:00
|
|
|
} catch (IOException e) {
|
|
|
|
throw new ChannelException(e);
|
|
|
|
}
|
2014-02-15 22:26:36 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean isKeepAlive() {
|
2016-03-15 10:38:25 +01:00
|
|
|
try {
|
2018-09-28 17:37:14 +02:00
|
|
|
return ((EpollSocketChannel) channel).socket.isKeepAlive();
|
2016-03-15 10:38:25 +01:00
|
|
|
} catch (IOException e) {
|
|
|
|
throw new ChannelException(e);
|
|
|
|
}
|
2014-02-15 22:26:36 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean isReuseAddress() {
|
2016-03-15 10:38:25 +01:00
|
|
|
try {
|
2018-09-28 17:37:14 +02:00
|
|
|
return ((EpollSocketChannel) channel).socket.isReuseAddress();
|
2016-03-15 10:38:25 +01:00
|
|
|
} catch (IOException e) {
|
|
|
|
throw new ChannelException(e);
|
|
|
|
}
|
2014-02-15 22:26:36 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean isTcpNoDelay() {
|
2016-03-15 10:38:25 +01:00
|
|
|
try {
|
2018-09-28 17:37:14 +02:00
|
|
|
return ((EpollSocketChannel) channel).socket.isTcpNoDelay();
|
2016-03-15 10:38:25 +01:00
|
|
|
} catch (IOException e) {
|
|
|
|
throw new ChannelException(e);
|
|
|
|
}
|
2014-02-15 22:26:36 +01:00
|
|
|
}
|
|
|
|
|
2014-04-17 21:41:04 +02:00
|
|
|
/**
|
|
|
|
* Get the {@code TCP_CORK} option on the socket. See {@code man 7 tcp} for more details.
|
|
|
|
*/
|
2014-02-15 22:26:36 +01:00
|
|
|
public boolean isTcpCork() {
|
2016-03-15 10:38:25 +01:00
|
|
|
try {
|
2018-09-28 17:37:14 +02:00
|
|
|
return ((EpollSocketChannel) channel).socket.isTcpCork();
|
2016-03-15 10:38:25 +01:00
|
|
|
} catch (IOException e) {
|
|
|
|
throw new ChannelException(e);
|
|
|
|
}
|
2014-02-15 22:26:36 +01:00
|
|
|
}
|
|
|
|
|
2018-09-07 20:50:51 +02:00
|
|
|
/**
|
|
|
|
* Get the {@code SO_BUSY_POLL} option on the socket. See {@code man 7 tcp} for more details.
|
|
|
|
*/
|
|
|
|
public int getSoBusyPoll() {
|
|
|
|
try {
|
2018-09-28 17:37:14 +02:00
|
|
|
return ((EpollSocketChannel) channel).socket.getSoBusyPoll();
|
2018-09-07 20:50:51 +02:00
|
|
|
} catch (IOException e) {
|
|
|
|
throw new ChannelException(e);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-05-28 03:37:56 +02:00
|
|
|
/**
|
|
|
|
* Get the {@code TCP_NOTSENT_LOWAT} option on the socket. See {@code man 7 tcp} for more details.
|
|
|
|
* @return value is a uint32_t
|
|
|
|
*/
|
|
|
|
public long getTcpNotSentLowAt() {
|
2016-03-15 10:38:25 +01:00
|
|
|
try {
|
2018-09-28 17:37:14 +02:00
|
|
|
return ((EpollSocketChannel) channel).socket.getTcpNotSentLowAt();
|
2016-03-15 10:38:25 +01:00
|
|
|
} catch (IOException e) {
|
|
|
|
throw new ChannelException(e);
|
|
|
|
}
|
2015-05-28 03:37:56 +02:00
|
|
|
}
|
|
|
|
|
2014-04-17 21:41:04 +02:00
|
|
|
/**
|
|
|
|
* Get the {@code TCP_KEEPIDLE} option on the socket. See {@code man 7 tcp} for more details.
|
|
|
|
*/
|
|
|
|
public int getTcpKeepIdle() {
|
2016-03-15 10:38:25 +01:00
|
|
|
try {
|
2018-09-28 17:37:14 +02:00
|
|
|
return ((EpollSocketChannel) channel).socket.getTcpKeepIdle();
|
2016-03-15 10:38:25 +01:00
|
|
|
} catch (IOException e) {
|
|
|
|
throw new ChannelException(e);
|
|
|
|
}
|
2014-04-17 21:41:04 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the {@code TCP_KEEPINTVL} option on the socket. See {@code man 7 tcp} for more details.
|
|
|
|
*/
|
|
|
|
public int getTcpKeepIntvl() {
|
2016-03-15 10:38:25 +01:00
|
|
|
try {
|
2018-09-28 17:37:14 +02:00
|
|
|
return ((EpollSocketChannel) channel).socket.getTcpKeepIntvl();
|
2016-03-15 10:38:25 +01:00
|
|
|
} catch (IOException e) {
|
|
|
|
throw new ChannelException(e);
|
|
|
|
}
|
2014-04-17 21:41:04 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the {@code TCP_KEEPCNT} option on the socket. See {@code man 7 tcp} for more details.
|
|
|
|
*/
|
|
|
|
public int getTcpKeepCnt() {
|
2016-03-15 10:38:25 +01:00
|
|
|
try {
|
2018-09-28 17:37:14 +02:00
|
|
|
return ((EpollSocketChannel) channel).socket.getTcpKeepCnt();
|
2016-03-15 10:38:25 +01:00
|
|
|
} catch (IOException e) {
|
|
|
|
throw new ChannelException(e);
|
|
|
|
}
|
2014-04-17 21:41:04 +02:00
|
|
|
}
|
|
|
|
|
2015-08-31 00:11:39 +02:00
|
|
|
/**
|
|
|
|
* Get the {@code TCP_USER_TIMEOUT} option on the socket. See {@code man 7 tcp} for more details.
|
|
|
|
*/
|
|
|
|
public int getTcpUserTimeout() {
|
2016-03-15 10:38:25 +01:00
|
|
|
try {
|
2018-09-28 17:37:14 +02:00
|
|
|
return ((EpollSocketChannel) channel).socket.getTcpUserTimeout();
|
2016-03-15 10:38:25 +01:00
|
|
|
} catch (IOException e) {
|
|
|
|
throw new ChannelException(e);
|
|
|
|
}
|
2015-08-31 00:11:39 +02:00
|
|
|
}
|
|
|
|
|
2014-02-15 22:26:36 +01:00
|
|
|
@Override
|
|
|
|
public EpollSocketChannelConfig setKeepAlive(boolean keepAlive) {
|
2016-03-15 10:38:25 +01:00
|
|
|
try {
|
2018-09-28 17:37:14 +02:00
|
|
|
((EpollSocketChannel) channel).socket.setKeepAlive(keepAlive);
|
2016-03-15 10:38:25 +01:00
|
|
|
return this;
|
|
|
|
} catch (IOException e) {
|
|
|
|
throw new ChannelException(e);
|
|
|
|
}
|
2014-02-15 22:26:36 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public EpollSocketChannelConfig setPerformancePreferences(
|
|
|
|
int connectionTime, int latency, int bandwidth) {
|
|
|
|
return this;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public EpollSocketChannelConfig setReceiveBufferSize(int receiveBufferSize) {
|
2016-03-15 10:38:25 +01:00
|
|
|
try {
|
2018-09-28 17:37:14 +02:00
|
|
|
((EpollSocketChannel) channel).socket.setReceiveBufferSize(receiveBufferSize);
|
2016-03-15 10:38:25 +01:00
|
|
|
return this;
|
|
|
|
} catch (IOException e) {
|
|
|
|
throw new ChannelException(e);
|
|
|
|
}
|
2014-02-15 22:26:36 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public EpollSocketChannelConfig setReuseAddress(boolean reuseAddress) {
|
2016-03-15 10:38:25 +01:00
|
|
|
try {
|
2018-09-28 17:37:14 +02:00
|
|
|
((EpollSocketChannel) channel).socket.setReuseAddress(reuseAddress);
|
2016-03-15 10:38:25 +01:00
|
|
|
return this;
|
|
|
|
} catch (IOException e) {
|
|
|
|
throw new ChannelException(e);
|
|
|
|
}
|
2014-02-15 22:26:36 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public EpollSocketChannelConfig setSendBufferSize(int sendBufferSize) {
|
2016-03-15 10:38:25 +01:00
|
|
|
try {
|
2018-09-28 17:37:14 +02:00
|
|
|
((EpollSocketChannel) channel).socket.setSendBufferSize(sendBufferSize);
|
2017-12-08 01:00:52 +01:00
|
|
|
calculateMaxBytesPerGatheringWrite();
|
2016-03-15 10:38:25 +01:00
|
|
|
return this;
|
|
|
|
} catch (IOException e) {
|
|
|
|
throw new ChannelException(e);
|
|
|
|
}
|
2014-02-15 22:26:36 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public EpollSocketChannelConfig setSoLinger(int soLinger) {
|
2016-03-15 10:38:25 +01:00
|
|
|
try {
|
2018-09-28 17:37:14 +02:00
|
|
|
((EpollSocketChannel) channel).socket.setSoLinger(soLinger);
|
2016-03-15 10:38:25 +01:00
|
|
|
return this;
|
|
|
|
} catch (IOException e) {
|
|
|
|
throw new ChannelException(e);
|
|
|
|
}
|
2014-02-15 22:26:36 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public EpollSocketChannelConfig setTcpNoDelay(boolean tcpNoDelay) {
|
2016-03-15 10:38:25 +01:00
|
|
|
try {
|
2018-09-28 17:37:14 +02:00
|
|
|
((EpollSocketChannel) channel).socket.setTcpNoDelay(tcpNoDelay);
|
2016-03-15 10:38:25 +01:00
|
|
|
return this;
|
|
|
|
} catch (IOException e) {
|
|
|
|
throw new ChannelException(e);
|
|
|
|
}
|
2014-02-15 22:26:36 +01:00
|
|
|
}
|
|
|
|
|
2014-04-17 21:41:04 +02:00
|
|
|
/**
|
|
|
|
* Set the {@code TCP_CORK} option on the socket. See {@code man 7 tcp} for more details.
|
|
|
|
*/
|
2014-02-15 22:26:36 +01:00
|
|
|
public EpollSocketChannelConfig setTcpCork(boolean tcpCork) {
|
2016-03-15 10:38:25 +01:00
|
|
|
try {
|
2018-09-28 17:37:14 +02:00
|
|
|
((EpollSocketChannel) channel).socket.setTcpCork(tcpCork);
|
2016-03-15 10:38:25 +01:00
|
|
|
return this;
|
|
|
|
} catch (IOException e) {
|
|
|
|
throw new ChannelException(e);
|
|
|
|
}
|
2014-02-15 22:26:36 +01:00
|
|
|
}
|
|
|
|
|
2018-09-07 20:50:51 +02:00
|
|
|
/**
|
|
|
|
* Set the {@code SO_BUSY_POLL} option on the socket. See {@code man 7 tcp} for more details.
|
|
|
|
*/
|
|
|
|
public EpollSocketChannelConfig setSoBusyPoll(int loopMicros) {
|
|
|
|
try {
|
2018-09-28 17:37:14 +02:00
|
|
|
((EpollSocketChannel) channel).socket.setSoBusyPoll(loopMicros);
|
2018-09-07 20:50:51 +02:00
|
|
|
return this;
|
|
|
|
} catch (IOException e) {
|
|
|
|
throw new ChannelException(e);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-05-28 03:37:56 +02:00
|
|
|
/**
|
|
|
|
* Set the {@code TCP_NOTSENT_LOWAT} option on the socket. See {@code man 7 tcp} for more details.
|
|
|
|
* @param tcpNotSentLowAt is a uint32_t
|
|
|
|
*/
|
|
|
|
public EpollSocketChannelConfig setTcpNotSentLowAt(long tcpNotSentLowAt) {
|
2016-03-15 10:38:25 +01:00
|
|
|
try {
|
2018-09-28 17:37:14 +02:00
|
|
|
((EpollSocketChannel) channel).socket.setTcpNotSentLowAt(tcpNotSentLowAt);
|
2016-03-15 10:38:25 +01:00
|
|
|
return this;
|
|
|
|
} catch (IOException e) {
|
|
|
|
throw new ChannelException(e);
|
|
|
|
}
|
2015-05-28 03:37:56 +02:00
|
|
|
}
|
|
|
|
|
2014-02-15 22:26:36 +01:00
|
|
|
@Override
|
|
|
|
public EpollSocketChannelConfig setTrafficClass(int trafficClass) {
|
2016-03-15 10:38:25 +01:00
|
|
|
try {
|
2018-09-28 17:37:14 +02:00
|
|
|
((EpollSocketChannel) channel).socket.setTrafficClass(trafficClass);
|
2016-03-15 10:38:25 +01:00
|
|
|
return this;
|
|
|
|
} catch (IOException e) {
|
|
|
|
throw new ChannelException(e);
|
|
|
|
}
|
2014-02-15 22:26:36 +01:00
|
|
|
}
|
|
|
|
|
2014-04-17 21:41:04 +02:00
|
|
|
/**
|
|
|
|
* Set the {@code TCP_KEEPIDLE} option on the socket. See {@code man 7 tcp} for more details.
|
|
|
|
*/
|
|
|
|
public EpollSocketChannelConfig setTcpKeepIdle(int seconds) {
|
2016-03-15 10:38:25 +01:00
|
|
|
try {
|
2018-09-28 17:37:14 +02:00
|
|
|
((EpollSocketChannel) channel).socket.setTcpKeepIdle(seconds);
|
2016-03-15 10:38:25 +01:00
|
|
|
return this;
|
|
|
|
} catch (IOException e) {
|
|
|
|
throw new ChannelException(e);
|
|
|
|
}
|
2014-04-17 21:41:04 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Set the {@code TCP_KEEPINTVL} option on the socket. See {@code man 7 tcp} for more details.
|
|
|
|
*/
|
|
|
|
public EpollSocketChannelConfig setTcpKeepIntvl(int seconds) {
|
2016-03-15 10:38:25 +01:00
|
|
|
try {
|
2018-09-28 17:37:14 +02:00
|
|
|
((EpollSocketChannel) channel).socket.setTcpKeepIntvl(seconds);
|
2016-03-15 10:38:25 +01:00
|
|
|
return this;
|
|
|
|
} catch (IOException e) {
|
|
|
|
throw new ChannelException(e);
|
|
|
|
}
|
2014-04-17 21:41:04 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2017-06-27 19:07:27 +02:00
|
|
|
* @deprecated use {@link #setTcpKeepCnt(int)}
|
2014-04-17 21:41:04 +02:00
|
|
|
*/
|
2017-06-27 19:07:27 +02:00
|
|
|
@Deprecated
|
2014-04-17 21:41:04 +02:00
|
|
|
public EpollSocketChannelConfig setTcpKeepCntl(int probes) {
|
2017-06-27 19:07:27 +02:00
|
|
|
return setTcpKeepCnt(probes);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Set the {@code TCP_KEEPCNT} option on the socket. See {@code man 7 tcp} for more details.
|
|
|
|
*/
|
|
|
|
public EpollSocketChannelConfig setTcpKeepCnt(int probes) {
|
2016-03-15 10:38:25 +01:00
|
|
|
try {
|
2018-09-28 17:37:14 +02:00
|
|
|
((EpollSocketChannel) channel).socket.setTcpKeepCnt(probes);
|
2016-03-15 10:38:25 +01:00
|
|
|
return this;
|
|
|
|
} catch (IOException e) {
|
|
|
|
throw new ChannelException(e);
|
|
|
|
}
|
2014-04-17 21:41:04 +02:00
|
|
|
}
|
|
|
|
|
2015-08-31 00:11:39 +02:00
|
|
|
/**
|
|
|
|
* Set the {@code TCP_USER_TIMEOUT} option on the socket. See {@code man 7 tcp} for more details.
|
|
|
|
*/
|
|
|
|
public EpollSocketChannelConfig setTcpUserTimeout(int milliseconds) {
|
2016-03-15 10:38:25 +01:00
|
|
|
try {
|
2018-09-28 17:37:14 +02:00
|
|
|
((EpollSocketChannel) channel).socket.setTcpUserTimeout(milliseconds);
|
2016-03-15 10:38:25 +01:00
|
|
|
return this;
|
|
|
|
} catch (IOException e) {
|
|
|
|
throw new ChannelException(e);
|
|
|
|
}
|
2015-08-31 00:11:39 +02:00
|
|
|
}
|
|
|
|
|
2017-07-30 11:48:57 +02:00
|
|
|
/**
|
|
|
|
* Returns {@code true} if <a href="http://man7.org/linux/man-pages/man7/ip.7.html">IP_TRANSPARENT</a> is enabled,
|
|
|
|
* {@code false} otherwise.
|
|
|
|
*/
|
|
|
|
public boolean isIpTransparent() {
|
|
|
|
try {
|
2018-09-28 17:37:14 +02:00
|
|
|
return ((EpollSocketChannel) channel).socket.isIpTransparent();
|
2017-07-30 11:48:57 +02:00
|
|
|
} catch (IOException e) {
|
|
|
|
throw new ChannelException(e);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* If {@code true} is used <a href="http://man7.org/linux/man-pages/man7/ip.7.html">IP_TRANSPARENT</a> is enabled,
|
|
|
|
* {@code false} for disable it. Default is disabled.
|
|
|
|
*/
|
|
|
|
public EpollSocketChannelConfig setIpTransparent(boolean transparent) {
|
|
|
|
try {
|
2018-09-28 17:37:14 +02:00
|
|
|
((EpollSocketChannel) channel).socket.setIpTransparent(transparent);
|
2017-07-30 11:48:57 +02:00
|
|
|
return this;
|
|
|
|
} catch (IOException e) {
|
|
|
|
throw new ChannelException(e);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-03-04 10:32:11 +01:00
|
|
|
/**
|
2015-08-30 12:11:41 +02:00
|
|
|
* Set the {@code TCP_MD5SIG} option on the socket. See {@code linux/tcp.h} for more details.
|
|
|
|
* Keys can only be set on, not read to prevent a potential leak, as they are confidential.
|
|
|
|
* Allowing them being read would mean anyone with access to the channel could get them.
|
|
|
|
*/
|
|
|
|
public EpollSocketChannelConfig setTcpMd5Sig(Map<InetAddress, byte[]> keys) {
|
2016-03-15 10:38:25 +01:00
|
|
|
try {
|
2018-09-28 17:37:14 +02:00
|
|
|
((EpollSocketChannel) channel).setTcpMd5Sig(keys);
|
2016-03-15 10:38:25 +01:00
|
|
|
return this;
|
|
|
|
} catch (IOException e) {
|
|
|
|
throw new ChannelException(e);
|
|
|
|
}
|
2015-08-30 12:11:41 +02:00
|
|
|
}
|
|
|
|
|
2016-03-04 10:32:11 +01:00
|
|
|
/**
|
|
|
|
* Set the {@code TCP_QUICKACK} option on the socket. See <a href="http://linux.die.net/man/7/tcp">TCP_QUICKACK</a>
|
|
|
|
* for more details.
|
|
|
|
*/
|
|
|
|
public EpollSocketChannelConfig setTcpQuickAck(boolean quickAck) {
|
2016-03-15 10:38:25 +01:00
|
|
|
try {
|
2018-09-28 17:37:14 +02:00
|
|
|
((EpollSocketChannel) channel).socket.setTcpQuickAck(quickAck);
|
2016-03-15 10:38:25 +01:00
|
|
|
return this;
|
|
|
|
} catch (IOException e) {
|
|
|
|
throw new ChannelException(e);
|
|
|
|
}
|
2016-03-04 10:32:11 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns {@code true} if <a href="http://linux.die.net/man/7/tcp">TCP_QUICKACK</a> is enabled,
|
|
|
|
* {@code false} otherwise.
|
|
|
|
*/
|
|
|
|
public boolean isTcpQuickAck() {
|
2016-03-15 10:38:25 +01:00
|
|
|
try {
|
2018-09-28 17:37:14 +02:00
|
|
|
return ((EpollSocketChannel) channel).socket.isTcpQuickAck();
|
2016-03-15 10:38:25 +01:00
|
|
|
} catch (IOException e) {
|
|
|
|
throw new ChannelException(e);
|
|
|
|
}
|
2016-03-04 10:32:11 +01:00
|
|
|
}
|
|
|
|
|
2017-10-26 17:17:02 +02:00
|
|
|
/**
|
|
|
|
* Set the {@code TCP_FASTOPEN_CONNECT} option on the socket. Requires Linux kernel 4.11 or later.
|
|
|
|
* See
|
|
|
|
* <a href="https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=19f6d3f3">this commit</a>
|
|
|
|
* for more details.
|
|
|
|
*/
|
|
|
|
public EpollSocketChannelConfig setTcpFastOpenConnect(boolean fastOpenConnect) {
|
|
|
|
try {
|
2018-09-28 17:37:14 +02:00
|
|
|
((EpollSocketChannel) channel).socket.setTcpFastOpenConnect(fastOpenConnect);
|
2017-10-26 17:17:02 +02:00
|
|
|
return this;
|
|
|
|
} catch (IOException e) {
|
|
|
|
throw new ChannelException(e);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns {@code true} if {@code TCP_FASTOPEN_CONNECT} is enabled, {@code false} otherwise.
|
|
|
|
*/
|
|
|
|
public boolean isTcpFastOpenConnect() {
|
|
|
|
try {
|
2018-09-28 17:37:14 +02:00
|
|
|
return ((EpollSocketChannel) channel).socket.isTcpFastOpenConnect();
|
2017-10-26 17:17:02 +02:00
|
|
|
} catch (IOException e) {
|
|
|
|
throw new ChannelException(e);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-02-15 22:26:36 +01:00
|
|
|
@Override
|
|
|
|
public boolean isAllowHalfClosure() {
|
|
|
|
return allowHalfClosure;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public EpollSocketChannelConfig setAllowHalfClosure(boolean allowHalfClosure) {
|
|
|
|
this.allowHalfClosure = allowHalfClosure;
|
|
|
|
return this;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public EpollSocketChannelConfig setConnectTimeoutMillis(int connectTimeoutMillis) {
|
|
|
|
super.setConnectTimeoutMillis(connectTimeoutMillis);
|
|
|
|
return this;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2015-06-05 03:36:55 +02:00
|
|
|
@Deprecated
|
2014-02-15 22:26:36 +01:00
|
|
|
public EpollSocketChannelConfig setMaxMessagesPerRead(int maxMessagesPerRead) {
|
|
|
|
super.setMaxMessagesPerRead(maxMessagesPerRead);
|
|
|
|
return this;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public EpollSocketChannelConfig setWriteSpinCount(int writeSpinCount) {
|
|
|
|
super.setWriteSpinCount(writeSpinCount);
|
|
|
|
return this;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public EpollSocketChannelConfig setAllocator(ByteBufAllocator allocator) {
|
|
|
|
super.setAllocator(allocator);
|
|
|
|
return this;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public EpollSocketChannelConfig setRecvByteBufAllocator(RecvByteBufAllocator allocator) {
|
|
|
|
super.setRecvByteBufAllocator(allocator);
|
|
|
|
return this;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public EpollSocketChannelConfig setAutoRead(boolean autoRead) {
|
|
|
|
super.setAutoRead(autoRead);
|
|
|
|
return this;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public EpollSocketChannelConfig setAutoClose(boolean autoClose) {
|
|
|
|
super.setAutoClose(autoClose);
|
|
|
|
return this;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2016-03-30 04:33:35 +02:00
|
|
|
@Deprecated
|
2014-02-15 22:26:36 +01:00
|
|
|
public EpollSocketChannelConfig setWriteBufferHighWaterMark(int writeBufferHighWaterMark) {
|
|
|
|
super.setWriteBufferHighWaterMark(writeBufferHighWaterMark);
|
|
|
|
return this;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2016-03-30 04:33:35 +02:00
|
|
|
@Deprecated
|
2014-02-15 22:26:36 +01:00
|
|
|
public EpollSocketChannelConfig setWriteBufferLowWaterMark(int writeBufferLowWaterMark) {
|
|
|
|
super.setWriteBufferLowWaterMark(writeBufferLowWaterMark);
|
|
|
|
return this;
|
|
|
|
}
|
|
|
|
|
2016-03-30 04:33:35 +02:00
|
|
|
@Override
|
|
|
|
public EpollSocketChannelConfig setWriteBufferWaterMark(WriteBufferWaterMark writeBufferWaterMark) {
|
|
|
|
super.setWriteBufferWaterMark(writeBufferWaterMark);
|
|
|
|
return this;
|
|
|
|
}
|
|
|
|
|
2014-02-15 22:26:36 +01:00
|
|
|
@Override
|
|
|
|
public EpollSocketChannelConfig setMessageSizeEstimator(MessageSizeEstimator estimator) {
|
|
|
|
super.setMessageSizeEstimator(estimator);
|
|
|
|
return this;
|
|
|
|
}
|
2014-04-10 08:27:27 +02:00
|
|
|
|
2017-12-08 01:00:52 +01:00
|
|
|
private void calculateMaxBytesPerGatheringWrite() {
|
|
|
|
// Multiply by 2 to give some extra space in case the OS can process write data faster than we can provide.
|
|
|
|
int newSendBufferSize = getSendBufferSize() << 1;
|
|
|
|
if (newSendBufferSize > 0) {
|
|
|
|
setMaxBytesPerGatheringWrite(getSendBufferSize() << 1);
|
|
|
|
}
|
|
|
|
}
|
2014-02-15 22:26:36 +01:00
|
|
|
}
|