2014-04-11 21:08:26 +02:00
|
|
|
/*
|
|
|
|
* Copyright 2012 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;
|
|
|
|
|
2019-09-03 08:40:17 +02:00
|
|
|
import io.netty.buffer.ByteBuf;
|
2014-04-11 21:08:26 +02:00
|
|
|
import io.netty.buffer.ByteBufAllocator;
|
2016-03-15 10:38:25 +01:00
|
|
|
import io.netty.channel.ChannelException;
|
2014-04-11 21:08:26 +02:00
|
|
|
import io.netty.channel.ChannelOption;
|
|
|
|
import io.netty.channel.FixedRecvByteBufAllocator;
|
|
|
|
import io.netty.channel.MessageSizeEstimator;
|
|
|
|
import io.netty.channel.RecvByteBufAllocator;
|
2016-03-30 04:33:35 +02:00
|
|
|
import io.netty.channel.WriteBufferWaterMark;
|
2014-04-11 21:08:26 +02:00
|
|
|
import io.netty.channel.socket.DatagramChannelConfig;
|
2019-09-03 08:40:17 +02:00
|
|
|
import io.netty.util.internal.ObjectUtil;
|
2018-04-17 09:07:02 +02:00
|
|
|
|
2016-03-15 10:38:25 +01:00
|
|
|
import java.io.IOException;
|
2014-04-11 21:08:26 +02:00
|
|
|
import java.net.InetAddress;
|
|
|
|
import java.net.NetworkInterface;
|
|
|
|
import java.util.Map;
|
|
|
|
|
2015-01-29 06:49:14 +01:00
|
|
|
public final class EpollDatagramChannelConfig extends EpollChannelConfig implements DatagramChannelConfig {
|
2014-04-11 21:08:26 +02:00
|
|
|
private static final RecvByteBufAllocator DEFAULT_RCVBUF_ALLOCATOR = new FixedRecvByteBufAllocator(2048);
|
|
|
|
private boolean activeOnOpen;
|
2019-09-03 08:40:17 +02:00
|
|
|
private volatile int maxDatagramSize;
|
2014-04-11 21:08:26 +02:00
|
|
|
|
|
|
|
EpollDatagramChannelConfig(EpollDatagramChannel channel) {
|
|
|
|
super(channel);
|
|
|
|
setRecvByteBufAllocator(DEFAULT_RCVBUF_ALLOCATOR);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2014-07-02 12:04:11 +02:00
|
|
|
@SuppressWarnings("deprecation")
|
2014-04-11 21:08:26 +02:00
|
|
|
public Map<ChannelOption<?>, Object> getOptions() {
|
|
|
|
return getOptions(
|
|
|
|
super.getOptions(),
|
|
|
|
ChannelOption.SO_BROADCAST, ChannelOption.SO_RCVBUF, ChannelOption.SO_SNDBUF,
|
|
|
|
ChannelOption.SO_REUSEADDR, ChannelOption.IP_MULTICAST_LOOP_DISABLED,
|
|
|
|
ChannelOption.IP_MULTICAST_ADDR, ChannelOption.IP_MULTICAST_IF, ChannelOption.IP_MULTICAST_TTL,
|
2014-04-17 11:19:00 +02:00
|
|
|
ChannelOption.IP_TOS, ChannelOption.DATAGRAM_CHANNEL_ACTIVE_ON_REGISTRATION,
|
2019-01-21 07:42:05 +01:00
|
|
|
EpollChannelOption.SO_REUSEPORT, EpollChannelOption.IP_FREEBIND, EpollChannelOption.IP_TRANSPARENT,
|
2019-09-03 08:40:17 +02:00
|
|
|
EpollChannelOption.IP_RECVORIGDSTADDR, EpollChannelOption.MAX_DATAGRAM_PAYLOAD_SIZE);
|
2014-04-11 21:08:26 +02:00
|
|
|
}
|
|
|
|
|
2014-07-02 12:04:11 +02:00
|
|
|
@SuppressWarnings({ "unchecked", "deprecation" })
|
2014-04-11 21:08:26 +02:00
|
|
|
@Override
|
|
|
|
public <T> T getOption(ChannelOption<T> option) {
|
|
|
|
if (option == ChannelOption.SO_BROADCAST) {
|
|
|
|
return (T) Boolean.valueOf(isBroadcast());
|
|
|
|
}
|
|
|
|
if (option == ChannelOption.SO_RCVBUF) {
|
|
|
|
return (T) Integer.valueOf(getReceiveBufferSize());
|
|
|
|
}
|
|
|
|
if (option == ChannelOption.SO_SNDBUF) {
|
|
|
|
return (T) Integer.valueOf(getSendBufferSize());
|
|
|
|
}
|
|
|
|
if (option == ChannelOption.SO_REUSEADDR) {
|
|
|
|
return (T) Boolean.valueOf(isReuseAddress());
|
|
|
|
}
|
|
|
|
if (option == ChannelOption.IP_MULTICAST_LOOP_DISABLED) {
|
|
|
|
return (T) Boolean.valueOf(isLoopbackModeDisabled());
|
|
|
|
}
|
|
|
|
if (option == ChannelOption.IP_MULTICAST_ADDR) {
|
2014-07-02 12:04:11 +02:00
|
|
|
return (T) getInterface();
|
2014-04-11 21:08:26 +02:00
|
|
|
}
|
|
|
|
if (option == ChannelOption.IP_MULTICAST_IF) {
|
2014-07-02 12:04:11 +02:00
|
|
|
return (T) getNetworkInterface();
|
2014-04-11 21:08:26 +02:00
|
|
|
}
|
|
|
|
if (option == ChannelOption.IP_MULTICAST_TTL) {
|
|
|
|
return (T) Integer.valueOf(getTimeToLive());
|
|
|
|
}
|
|
|
|
if (option == ChannelOption.IP_TOS) {
|
|
|
|
return (T) Integer.valueOf(getTrafficClass());
|
|
|
|
}
|
|
|
|
if (option == ChannelOption.DATAGRAM_CHANNEL_ACTIVE_ON_REGISTRATION) {
|
|
|
|
return (T) Boolean.valueOf(activeOnOpen);
|
|
|
|
}
|
2014-04-17 11:19:00 +02:00
|
|
|
if (option == EpollChannelOption.SO_REUSEPORT) {
|
|
|
|
return (T) Boolean.valueOf(isReusePort());
|
|
|
|
}
|
2018-04-17 09:07:02 +02:00
|
|
|
if (option == EpollChannelOption.IP_TRANSPARENT) {
|
|
|
|
return (T) Boolean.valueOf(isIpTransparent());
|
|
|
|
}
|
2019-01-21 07:42:05 +01:00
|
|
|
if (option == EpollChannelOption.IP_FREEBIND) {
|
|
|
|
return (T) Boolean.valueOf(isFreeBind());
|
|
|
|
}
|
2018-04-26 08:00:36 +02:00
|
|
|
if (option == EpollChannelOption.IP_RECVORIGDSTADDR) {
|
|
|
|
return (T) Boolean.valueOf(isIpRecvOrigDestAddr());
|
|
|
|
}
|
2019-09-03 08:40:17 +02:00
|
|
|
if (option == EpollChannelOption.MAX_DATAGRAM_PAYLOAD_SIZE) {
|
|
|
|
return (T) Integer.valueOf(getMaxDatagramPayloadSize());
|
|
|
|
}
|
2014-04-11 21:08:26 +02:00
|
|
|
return super.getOption(option);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2014-07-02 12:04:11 +02:00
|
|
|
@SuppressWarnings("deprecation")
|
2014-04-11 21:08:26 +02:00
|
|
|
public <T> boolean setOption(ChannelOption<T> option, T value) {
|
|
|
|
validate(option, value);
|
|
|
|
|
|
|
|
if (option == ChannelOption.SO_BROADCAST) {
|
|
|
|
setBroadcast((Boolean) value);
|
|
|
|
} else if (option == ChannelOption.SO_RCVBUF) {
|
|
|
|
setReceiveBufferSize((Integer) value);
|
|
|
|
} else if (option == ChannelOption.SO_SNDBUF) {
|
|
|
|
setSendBufferSize((Integer) value);
|
|
|
|
} else if (option == ChannelOption.SO_REUSEADDR) {
|
|
|
|
setReuseAddress((Boolean) value);
|
|
|
|
} else if (option == ChannelOption.IP_MULTICAST_LOOP_DISABLED) {
|
|
|
|
setLoopbackModeDisabled((Boolean) value);
|
|
|
|
} else if (option == ChannelOption.IP_MULTICAST_ADDR) {
|
|
|
|
setInterface((InetAddress) value);
|
|
|
|
} else if (option == ChannelOption.IP_MULTICAST_IF) {
|
|
|
|
setNetworkInterface((NetworkInterface) value);
|
|
|
|
} else if (option == ChannelOption.IP_MULTICAST_TTL) {
|
|
|
|
setTimeToLive((Integer) value);
|
|
|
|
} else if (option == ChannelOption.IP_TOS) {
|
|
|
|
setTrafficClass((Integer) value);
|
|
|
|
} else if (option == ChannelOption.DATAGRAM_CHANNEL_ACTIVE_ON_REGISTRATION) {
|
|
|
|
setActiveOnOpen((Boolean) value);
|
2014-04-17 11:19:00 +02:00
|
|
|
} else if (option == EpollChannelOption.SO_REUSEPORT) {
|
|
|
|
setReusePort((Boolean) value);
|
2019-01-21 07:42:05 +01:00
|
|
|
} else if (option == EpollChannelOption.IP_FREEBIND) {
|
|
|
|
setFreeBind((Boolean) value);
|
2018-04-17 09:07:02 +02:00
|
|
|
} else if (option == EpollChannelOption.IP_TRANSPARENT) {
|
|
|
|
setIpTransparent((Boolean) value);
|
2018-04-26 08:00:36 +02:00
|
|
|
} else if (option == EpollChannelOption.IP_RECVORIGDSTADDR) {
|
|
|
|
setIpRecvOrigDestAddr((Boolean) value);
|
2019-09-03 08:40:17 +02:00
|
|
|
} else if (option == EpollChannelOption.MAX_DATAGRAM_PAYLOAD_SIZE) {
|
|
|
|
setMaxDatagramPayloadSize((Integer) value);
|
2014-04-11 21:08:26 +02:00
|
|
|
} else {
|
|
|
|
return super.setOption(option, value);
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
private void setActiveOnOpen(boolean activeOnOpen) {
|
|
|
|
if (channel.isRegistered()) {
|
|
|
|
throw new IllegalStateException("Can only changed before channel was registered");
|
|
|
|
}
|
|
|
|
this.activeOnOpen = activeOnOpen;
|
|
|
|
}
|
|
|
|
|
2017-02-16 17:05:48 +01:00
|
|
|
boolean getActiveOnOpen() {
|
|
|
|
return activeOnOpen;
|
|
|
|
}
|
|
|
|
|
2014-04-11 21:08:26 +02:00
|
|
|
@Override
|
|
|
|
public EpollDatagramChannelConfig setMessageSizeEstimator(MessageSizeEstimator estimator) {
|
|
|
|
super.setMessageSizeEstimator(estimator);
|
|
|
|
return this;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2016-03-30 04:33:35 +02:00
|
|
|
@Deprecated
|
2014-04-11 21:08:26 +02:00
|
|
|
public EpollDatagramChannelConfig setWriteBufferLowWaterMark(int writeBufferLowWaterMark) {
|
|
|
|
super.setWriteBufferLowWaterMark(writeBufferLowWaterMark);
|
|
|
|
return this;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2016-03-30 04:33:35 +02:00
|
|
|
@Deprecated
|
2014-04-11 21:08:26 +02:00
|
|
|
public EpollDatagramChannelConfig setWriteBufferHighWaterMark(int writeBufferHighWaterMark) {
|
|
|
|
super.setWriteBufferHighWaterMark(writeBufferHighWaterMark);
|
|
|
|
return this;
|
|
|
|
}
|
|
|
|
|
2016-03-30 04:33:35 +02:00
|
|
|
@Override
|
|
|
|
public EpollDatagramChannelConfig setWriteBufferWaterMark(WriteBufferWaterMark writeBufferWaterMark) {
|
|
|
|
super.setWriteBufferWaterMark(writeBufferWaterMark);
|
|
|
|
return this;
|
|
|
|
}
|
|
|
|
|
2014-04-11 21:08:26 +02:00
|
|
|
@Override
|
|
|
|
public EpollDatagramChannelConfig setAutoClose(boolean autoClose) {
|
|
|
|
super.setAutoClose(autoClose);
|
|
|
|
return this;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public EpollDatagramChannelConfig setAutoRead(boolean autoRead) {
|
|
|
|
super.setAutoRead(autoRead);
|
|
|
|
return this;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public EpollDatagramChannelConfig setRecvByteBufAllocator(RecvByteBufAllocator allocator) {
|
|
|
|
super.setRecvByteBufAllocator(allocator);
|
|
|
|
return this;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public EpollDatagramChannelConfig setWriteSpinCount(int writeSpinCount) {
|
|
|
|
super.setWriteSpinCount(writeSpinCount);
|
|
|
|
return this;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public EpollDatagramChannelConfig setAllocator(ByteBufAllocator allocator) {
|
|
|
|
super.setAllocator(allocator);
|
|
|
|
return this;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public EpollDatagramChannelConfig setConnectTimeoutMillis(int connectTimeoutMillis) {
|
|
|
|
super.setConnectTimeoutMillis(connectTimeoutMillis);
|
|
|
|
return this;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2015-06-05 03:36:55 +02:00
|
|
|
@Deprecated
|
2014-04-11 21:08:26 +02:00
|
|
|
public EpollDatagramChannelConfig setMaxMessagesPerRead(int maxMessagesPerRead) {
|
|
|
|
super.setMaxMessagesPerRead(maxMessagesPerRead);
|
|
|
|
return this;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public int getSendBufferSize() {
|
2016-03-15 10:38:25 +01:00
|
|
|
try {
|
2018-09-28 17:37:14 +02:00
|
|
|
return ((EpollDatagramChannel) channel).socket.getSendBufferSize();
|
2016-03-15 10:38:25 +01:00
|
|
|
} catch (IOException e) {
|
|
|
|
throw new ChannelException(e);
|
|
|
|
}
|
2014-04-11 21:08:26 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public EpollDatagramChannelConfig setSendBufferSize(int sendBufferSize) {
|
2016-03-15 10:38:25 +01:00
|
|
|
try {
|
2018-09-28 17:37:14 +02:00
|
|
|
((EpollDatagramChannel) channel).socket.setSendBufferSize(sendBufferSize);
|
2016-03-15 10:38:25 +01:00
|
|
|
return this;
|
|
|
|
} catch (IOException e) {
|
|
|
|
throw new ChannelException(e);
|
|
|
|
}
|
2014-04-11 21:08:26 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public int getReceiveBufferSize() {
|
2016-03-15 10:38:25 +01:00
|
|
|
try {
|
2018-09-28 17:37:14 +02:00
|
|
|
return ((EpollDatagramChannel) channel).socket.getReceiveBufferSize();
|
2016-03-15 10:38:25 +01:00
|
|
|
} catch (IOException e) {
|
|
|
|
throw new ChannelException(e);
|
|
|
|
}
|
2014-04-11 21:08:26 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public EpollDatagramChannelConfig setReceiveBufferSize(int receiveBufferSize) {
|
2016-03-15 10:38:25 +01:00
|
|
|
try {
|
2018-09-28 17:37:14 +02:00
|
|
|
((EpollDatagramChannel) channel).socket.setReceiveBufferSize(receiveBufferSize);
|
2016-03-15 10:38:25 +01:00
|
|
|
return this;
|
|
|
|
} catch (IOException e) {
|
|
|
|
throw new ChannelException(e);
|
|
|
|
}
|
2014-04-11 21:08:26 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public int getTrafficClass() {
|
2016-03-15 10:38:25 +01:00
|
|
|
try {
|
2018-09-28 17:37:14 +02:00
|
|
|
return ((EpollDatagramChannel) channel).socket.getTrafficClass();
|
2016-03-15 10:38:25 +01:00
|
|
|
} catch (IOException e) {
|
|
|
|
throw new ChannelException(e);
|
|
|
|
}
|
2014-04-11 21:08:26 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public EpollDatagramChannelConfig setTrafficClass(int trafficClass) {
|
2016-03-15 10:38:25 +01:00
|
|
|
try {
|
2018-09-28 17:37:14 +02:00
|
|
|
((EpollDatagramChannel) channel).socket.setTrafficClass(trafficClass);
|
2016-03-15 10:38:25 +01:00
|
|
|
return this;
|
|
|
|
} catch (IOException e) {
|
|
|
|
throw new ChannelException(e);
|
|
|
|
}
|
2014-04-11 21:08:26 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean isReuseAddress() {
|
2016-03-15 10:38:25 +01:00
|
|
|
try {
|
2018-09-28 17:37:14 +02:00
|
|
|
return ((EpollDatagramChannel) channel).socket.isReuseAddress();
|
2016-03-15 10:38:25 +01:00
|
|
|
} catch (IOException e) {
|
|
|
|
throw new ChannelException(e);
|
|
|
|
}
|
2014-04-11 21:08:26 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public EpollDatagramChannelConfig setReuseAddress(boolean reuseAddress) {
|
2016-03-15 10:38:25 +01:00
|
|
|
try {
|
2018-09-28 17:37:14 +02:00
|
|
|
((EpollDatagramChannel) channel).socket.setReuseAddress(reuseAddress);
|
2016-03-15 10:38:25 +01:00
|
|
|
return this;
|
|
|
|
} catch (IOException e) {
|
|
|
|
throw new ChannelException(e);
|
|
|
|
}
|
2014-04-11 21:08:26 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean isBroadcast() {
|
2016-03-15 10:38:25 +01:00
|
|
|
try {
|
2018-09-28 17:37:14 +02:00
|
|
|
return ((EpollDatagramChannel) channel).socket.isBroadcast();
|
2016-03-15 10:38:25 +01:00
|
|
|
} catch (IOException e) {
|
|
|
|
throw new ChannelException(e);
|
|
|
|
}
|
2014-04-11 21:08:26 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public EpollDatagramChannelConfig setBroadcast(boolean broadcast) {
|
2016-03-15 10:38:25 +01:00
|
|
|
try {
|
2018-09-28 17:37:14 +02:00
|
|
|
((EpollDatagramChannel) channel).socket.setBroadcast(broadcast);
|
2016-03-15 10:38:25 +01:00
|
|
|
return this;
|
|
|
|
} catch (IOException e) {
|
|
|
|
throw new ChannelException(e);
|
|
|
|
}
|
2014-04-11 21:08:26 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean isLoopbackModeDisabled() {
|
2019-06-07 22:44:06 +02:00
|
|
|
try {
|
|
|
|
return ((EpollDatagramChannel) channel).socket.isLoopbackModeDisabled();
|
|
|
|
} catch (IOException e) {
|
|
|
|
throw new ChannelException(e);
|
|
|
|
}
|
2014-04-11 21:08:26 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public DatagramChannelConfig setLoopbackModeDisabled(boolean loopbackModeDisabled) {
|
2019-06-07 22:44:06 +02:00
|
|
|
try {
|
|
|
|
((EpollDatagramChannel) channel).socket.setLoopbackModeDisabled(loopbackModeDisabled);
|
|
|
|
return this;
|
|
|
|
} catch (IOException e) {
|
|
|
|
throw new ChannelException(e);
|
|
|
|
}
|
2014-04-11 21:08:26 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public int getTimeToLive() {
|
2019-04-08 20:13:39 +02:00
|
|
|
try {
|
|
|
|
return ((EpollDatagramChannel) channel).socket.getTimeToLive();
|
|
|
|
} catch (IOException e) {
|
|
|
|
throw new ChannelException(e);
|
|
|
|
}
|
2014-04-11 21:08:26 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public EpollDatagramChannelConfig setTimeToLive(int ttl) {
|
2019-04-08 20:13:39 +02:00
|
|
|
try {
|
|
|
|
((EpollDatagramChannel) channel).socket.setTimeToLive(ttl);
|
|
|
|
return this;
|
|
|
|
} catch (IOException e) {
|
|
|
|
throw new ChannelException(e);
|
|
|
|
}
|
2014-04-11 21:08:26 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public InetAddress getInterface() {
|
2019-06-07 22:44:06 +02:00
|
|
|
try {
|
|
|
|
return ((EpollDatagramChannel) channel).socket.getInterface();
|
|
|
|
} catch (IOException e) {
|
|
|
|
throw new ChannelException(e);
|
|
|
|
}
|
2014-04-11 21:08:26 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public EpollDatagramChannelConfig setInterface(InetAddress interfaceAddress) {
|
2019-04-08 20:13:39 +02:00
|
|
|
try {
|
|
|
|
((EpollDatagramChannel) channel).socket.setInterface(interfaceAddress);
|
|
|
|
return this;
|
|
|
|
} catch (IOException e) {
|
|
|
|
throw new ChannelException(e);
|
|
|
|
}
|
2014-04-11 21:08:26 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public NetworkInterface getNetworkInterface() {
|
2019-06-07 22:44:06 +02:00
|
|
|
try {
|
|
|
|
return ((EpollDatagramChannel) channel).socket.getNetworkInterface();
|
|
|
|
} catch (IOException e) {
|
|
|
|
throw new ChannelException(e);
|
|
|
|
}
|
2014-04-11 21:08:26 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public EpollDatagramChannelConfig setNetworkInterface(NetworkInterface networkInterface) {
|
2019-04-08 20:13:39 +02:00
|
|
|
try {
|
|
|
|
EpollDatagramChannel datagramChannel = (EpollDatagramChannel) channel;
|
2019-05-26 20:22:55 +02:00
|
|
|
datagramChannel.socket.setNetworkInterface(networkInterface);
|
2019-04-08 20:13:39 +02:00
|
|
|
return this;
|
|
|
|
} catch (IOException e) {
|
|
|
|
throw new ChannelException(e);
|
|
|
|
}
|
2014-04-11 21:08:26 +02:00
|
|
|
}
|
2014-04-10 08:27:27 +02:00
|
|
|
|
2014-04-17 11:19:00 +02:00
|
|
|
/**
|
|
|
|
* Returns {@code true} if the SO_REUSEPORT option is set.
|
|
|
|
*/
|
|
|
|
public boolean isReusePort() {
|
2016-03-15 10:38:25 +01:00
|
|
|
try {
|
2018-09-28 17:37:14 +02:00
|
|
|
return ((EpollDatagramChannel) channel).socket.isReusePort();
|
2016-03-15 10:38:25 +01:00
|
|
|
} catch (IOException e) {
|
|
|
|
throw new ChannelException(e);
|
|
|
|
}
|
2014-04-17 11:19:00 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Set the SO_REUSEPORT option on the underlying Channel. This will allow to bind multiple
|
|
|
|
* {@link EpollSocketChannel}s to the same port and so accept connections with multiple threads.
|
|
|
|
*
|
|
|
|
* Be aware this method needs be called before {@link EpollDatagramChannel#bind(java.net.SocketAddress)} to have
|
|
|
|
* any affect.
|
|
|
|
*/
|
|
|
|
public EpollDatagramChannelConfig setReusePort(boolean reusePort) {
|
2016-03-15 10:38:25 +01:00
|
|
|
try {
|
2018-09-28 17:37:14 +02:00
|
|
|
((EpollDatagramChannel) channel).socket.setReusePort(reusePort);
|
2016-03-15 10:38:25 +01:00
|
|
|
return this;
|
|
|
|
} catch (IOException e) {
|
|
|
|
throw new ChannelException(e);
|
|
|
|
}
|
2014-04-17 11:19:00 +02:00
|
|
|
}
|
2018-04-17 09:07:02 +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 ((EpollDatagramChannel) channel).socket.isIpTransparent();
|
2018-04-17 09:07:02 +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 EpollDatagramChannelConfig setIpTransparent(boolean ipTransparent) {
|
|
|
|
try {
|
2018-09-28 17:37:14 +02:00
|
|
|
((EpollDatagramChannel) channel).socket.setIpTransparent(ipTransparent);
|
2018-04-17 09:07:02 +02:00
|
|
|
return this;
|
2019-01-21 07:42:05 +01:00
|
|
|
} catch (IOException e) {
|
|
|
|
throw new ChannelException(e);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns {@code true} if <a href="http://man7.org/linux/man-pages/man7/ip.7.html">IP_FREEBIND</a> is enabled,
|
|
|
|
* {@code false} otherwise.
|
|
|
|
*/
|
|
|
|
public boolean isFreeBind() {
|
|
|
|
try {
|
|
|
|
return ((EpollDatagramChannel) channel).socket.isIpFreeBind();
|
|
|
|
} 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_FREEBIND</a> is enabled,
|
|
|
|
* {@code false} for disable it. Default is disabled.
|
|
|
|
*/
|
|
|
|
public EpollDatagramChannelConfig setFreeBind(boolean freeBind) {
|
|
|
|
try {
|
|
|
|
((EpollDatagramChannel) channel).socket.setIpFreeBind(freeBind);
|
|
|
|
return this;
|
2018-04-17 09:07:02 +02:00
|
|
|
} catch (IOException e) {
|
|
|
|
throw new ChannelException(e);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-04-26 08:00:36 +02:00
|
|
|
/**
|
|
|
|
* Returns {@code true} if <a href="http://man7.org/linux/man-pages/man7/ip.7.html">IP_RECVORIGDSTADDR</a> is
|
|
|
|
* enabled, {@code false} otherwise.
|
|
|
|
*/
|
|
|
|
public boolean isIpRecvOrigDestAddr() {
|
|
|
|
try {
|
2018-09-28 17:37:14 +02:00
|
|
|
return ((EpollDatagramChannel) channel).socket.isIpRecvOrigDestAddr();
|
2018-04-26 08:00:36 +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_RECVORIGDSTADDR</a> is
|
|
|
|
* enabled, {@code false} for disable it. Default is disabled.
|
|
|
|
*/
|
|
|
|
public EpollDatagramChannelConfig setIpRecvOrigDestAddr(boolean ipTransparent) {
|
|
|
|
try {
|
2018-09-28 17:37:14 +02:00
|
|
|
((EpollDatagramChannel) channel).socket.setIpRecvOrigDestAddr(ipTransparent);
|
2018-04-26 08:00:36 +02:00
|
|
|
return this;
|
|
|
|
} catch (IOException e) {
|
|
|
|
throw new ChannelException(e);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-09-03 08:40:17 +02:00
|
|
|
/**
|
|
|
|
* Set the maximum {@link io.netty.channel.socket.DatagramPacket} size. This will be used to determine if
|
|
|
|
* {@code recvmmsg} should be used when reading from the underlying socket. When {@code recvmmsg} is used
|
|
|
|
* we may be able to read multiple {@link io.netty.channel.socket.DatagramPacket}s with one syscall and so
|
|
|
|
* greatly improve the performance. This number will be used to slice {@link ByteBuf}s returned by the used
|
|
|
|
* {@link RecvByteBufAllocator}. You can use {@code 0} to disable the usage of recvmmsg, any other bigger value
|
|
|
|
* will enable it.
|
|
|
|
*/
|
|
|
|
public EpollDatagramChannelConfig setMaxDatagramPayloadSize(int maxDatagramSize) {
|
|
|
|
this.maxDatagramSize = ObjectUtil.checkPositiveOrZero(maxDatagramSize, "maxDatagramSize");
|
|
|
|
return this;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the maximum {@link io.netty.channel.socket.DatagramPacket} size.
|
|
|
|
*/
|
|
|
|
public int getMaxDatagramPayloadSize() {
|
|
|
|
return maxDatagramSize;
|
|
|
|
}
|
2014-04-11 21:08:26 +02:00
|
|
|
}
|