From 89189427a886b2ff456b64269b309d6809441649 Mon Sep 17 00:00:00 2001 From: mgortman Date: Wed, 10 Feb 2016 01:31:16 -0800 Subject: [PATCH] Enables setting options specific to DefaultSocketChannelConfiguration (fix #68) Motivation: Fix a bug that breaks setting options specific to socket-based channel implementations Modifications: Added SetOption overload accepting socket-specific options to DefaultSocketChannelConfiguration Result: It is possible to modify send/receive buffer size and other settings through SetOption on Bootstrap. --- .../DefaultSocketChannelConfiguration.cs | 57 ++++++++++++++++++- .../Sockets/ISocketChannelConfiguration.cs | 13 +++++ 2 files changed, 68 insertions(+), 2 deletions(-) diff --git a/src/DotNetty.Transport/Channels/Sockets/DefaultSocketChannelConfiguration.cs b/src/DotNetty.Transport/Channels/Sockets/DefaultSocketChannelConfiguration.cs index 69656dd5d..b95c5cad2 100644 --- a/src/DotNetty.Transport/Channels/Sockets/DefaultSocketChannelConfiguration.cs +++ b/src/DotNetty.Transport/Channels/Sockets/DefaultSocketChannelConfiguration.cs @@ -8,7 +8,7 @@ namespace DotNetty.Transport.Channels.Sockets using System.Net.Sockets; /// - /// The default {@link SocketChannelConfig} implementation. + /// The default {@link SocketChannelConfig} implementation. /// public class DefaultSocketChannelConfiguration : DefaultChannelConfiguration, ISocketChannelConfiguration { @@ -22,7 +22,13 @@ public DefaultSocketChannelConfiguration(ISocketChannel channel, Socket socket) this.Socket = socket; // Enable TCP_NODELAY by default if possible. - socket.NoDelay = true; + try + { + this.TcpNoDelay = true; + } + catch + { + } } public override T GetOption(ChannelOption option) @@ -63,6 +69,53 @@ public override T GetOption(ChannelOption option) return base.GetOption(option); } + public override bool SetOption(ChannelOption option, T value) + { + if (base.SetOption(option, value)) + { + return true; + } + + if (ChannelOption.SoRcvbuf.Equals(option)) + { + this.ReceiveBufferSize = (int)(object)value; + } + else if (ChannelOption.SoSndbuf.Equals(option)) + { + this.SendBufferSize = (int)(object)value; + } + else if (ChannelOption.TcpNodelay.Equals(option)) + { + this.TcpNoDelay = (bool)(object)value; + } + else if (ChannelOption.SoKeepalive.Equals(option)) + { + this.KeepAlive = (bool)(object)value; + } + else if (ChannelOption.SoReuseaddr.Equals(option)) + { + this.ReuseAddress = (bool)(object)value; + } + else if (ChannelOption.SoLinger.Equals(option)) + { + this.Linger = (int)(object)value; + } + //else if (option == IP_TOS) + //{ + // setTrafficClass((Integer)value); + //} + else if (ChannelOption.AllowHalfClosure.Equals(option)) + { + this.allowHalfClosure = (bool)(object)value; + } + else + { + return false; + } + + return true; + } + public bool AllowHalfClosure { get { return this.allowHalfClosure; } diff --git a/src/DotNetty.Transport/Channels/Sockets/ISocketChannelConfiguration.cs b/src/DotNetty.Transport/Channels/Sockets/ISocketChannelConfiguration.cs index 66537dd57..f05c479f2 100644 --- a/src/DotNetty.Transport/Channels/Sockets/ISocketChannelConfiguration.cs +++ b/src/DotNetty.Transport/Channels/Sockets/ISocketChannelConfiguration.cs @@ -5,5 +5,18 @@ namespace DotNetty.Transport.Channels.Sockets { public interface ISocketChannelConfiguration : IChannelConfiguration { + bool AllowHalfClosure { get; set; } + + int ReceiveBufferSize { get; set; } + + int SendBufferSize { get; set; } + + int Linger { get; set; } + + bool KeepAlive { get; set; } + + bool ReuseAddress { get; set; } + + bool TcpNoDelay { get; set; } } } \ No newline at end of file