Java Code Examples for java.nio.channels.NetworkChannel#setOption()

The following examples show how to use java.nio.channels.NetworkChannel#setOption() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: NetSystem.java    From Mycat-NIO with Apache License 2.0 6 votes vote down vote up
public void setSocketParams(Connection con, boolean isFrontChannel) throws IOException {
	int sorcvbuf = 0;
	int sosndbuf = 0;
	int soNoDelay = 0;
	if (isFrontChannel) {
		sorcvbuf = netConfig.getFrontsocketsorcvbuf();
		sosndbuf = netConfig.getFrontsocketsosndbuf();
		soNoDelay = netConfig.getFrontSocketNoDelay();
	} else {
		sorcvbuf = netConfig.getBacksocketsorcvbuf();
		sosndbuf = netConfig.getBacksocketsosndbuf();
		soNoDelay = netConfig.getBackSocketNoDelay();
	}
	NetworkChannel channel = con.getChannel();
	channel.setOption(StandardSocketOptions.SO_RCVBUF, sorcvbuf);
	channel.setOption(StandardSocketOptions.SO_SNDBUF, sosndbuf);
	channel.setOption(StandardSocketOptions.TCP_NODELAY, soNoDelay == 1);
	channel.setOption(StandardSocketOptions.SO_REUSEADDR, true);
	channel.setOption(StandardSocketOptions.SO_KEEPALIVE, true);

	con.setMaxPacketSize(netConfig.getMaxPacketSize());
	con.setPacketHeaderSize(netConfig.getPacketHeaderSize());

}
 
Example 2
Source File: MycatConfig.java    From Mycat2 with GNU General Public License v3.0 5 votes vote down vote up
public void setSocketParams(AbstractConnection con, boolean isFrontChannel)
		throws IOException {
	
	int sorcvbuf = 0;
	int sosndbuf = 0;
	int soNoDelay = 0;
	if ( isFrontChannel ) {
		sorcvbuf = system.getFrontsocketsorcvbuf();
		sosndbuf = system.getFrontsocketsosndbuf();
		soNoDelay = system.getFrontSocketNoDelay();
	} else {
		sorcvbuf = system.getBacksocketsorcvbuf();
		sosndbuf = system.getBacksocketsosndbuf();
		soNoDelay = system.getBackSocketNoDelay();
	}
	
	NetworkChannel channel = con.getChannel();
	channel.setOption(StandardSocketOptions.SO_RCVBUF, sorcvbuf);
	channel.setOption(StandardSocketOptions.SO_SNDBUF, sosndbuf);
	channel.setOption(StandardSocketOptions.TCP_NODELAY, soNoDelay == 1);
	channel.setOption(StandardSocketOptions.SO_REUSEADDR, true);
	channel.setOption(StandardSocketOptions.SO_KEEPALIVE, true);
	
	con.setMaxPacketSize(system.getMaxPacketSize());
	con.setPacketHeaderSize(system.getPacketHeaderSize());
	con.setIdleTimeout(system.getIdleTimeout());
	con.setCharset(system.getCharset());

}
 
Example 3
Source File: FrontendConnectionFactory.java    From Mycat2 with GNU General Public License v3.0 5 votes vote down vote up
public FrontendConnection make(NetworkChannel channel) throws IOException {
	channel.setOption(StandardSocketOptions.SO_REUSEADDR, true);
	channel.setOption(StandardSocketOptions.SO_KEEPALIVE, true);

	FrontendConnection c = getConnection(channel);
	MycatServer.getInstance().getConfig().setSocketParams(c, true);
	return c;
}
 
Example 4
Source File: FrontendConnectionFactory.java    From dble with GNU General Public License v2.0 5 votes vote down vote up
public FrontendConnection make(NetworkChannel channel) throws IOException {
    channel.setOption(StandardSocketOptions.SO_REUSEADDR, true);
    channel.setOption(StandardSocketOptions.SO_KEEPALIVE, true);

    FrontendConnection c = getConnection(channel);
    c.setSocketParams(true);
    return c;
}