Skip to content

Commit

Permalink
Enables setting options specific to DefaultSocketChannelConfiguration (
Browse files Browse the repository at this point in the history
…fix Azure#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.
  • Loading branch information
nayato committed Feb 10, 2016
1 parent 21a8dc1 commit 8918942
Show file tree
Hide file tree
Showing 2 changed files with 68 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ namespace DotNetty.Transport.Channels.Sockets
using System.Net.Sockets;

/// <summary>
/// The default {@link SocketChannelConfig} implementation.
/// The default {@link SocketChannelConfig} implementation.
/// </summary>
public class DefaultSocketChannelConfiguration : DefaultChannelConfiguration, ISocketChannelConfiguration
{
Expand All @@ -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<T>(ChannelOption<T> option)
Expand Down Expand Up @@ -63,6 +69,53 @@ public override T GetOption<T>(ChannelOption<T> option)
return base.GetOption(option);
}

public override bool SetOption<T>(ChannelOption<T> 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; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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; }
}
}

0 comments on commit 8918942

Please sign in to comment.