Skip to content

Commit

Permalink
Fix #55
Browse files Browse the repository at this point in the history
Motivation:
revisit EmptyByteBuffer port to ensure complete functionality

Modifications:
- ported trivial implementation of ToArray, Duplicate and other methods
- minor cleanup

Result:
EmptyByteBuffer does not throw exceptions when operation can be completed in a trivial way (0 byte length is enough to complete the operation).
  • Loading branch information
nayato committed Nov 25, 2015
1 parent 2405832 commit 7ccec95
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 19 deletions.
6 changes: 3 additions & 3 deletions src/DotNetty.Buffers/EmptyByteBuffer.cs
Expand Up @@ -407,7 +407,7 @@ public IByteBuffer ReadBytes(Stream destination, int length)

public IByteBuffer SkipBytes(int length)
{
throw new IndexOutOfRangeException();
return this.CheckLength(length);
}

public IByteBuffer WriteBoolean(bool value)
Expand Down Expand Up @@ -492,12 +492,12 @@ public byte[] Array

public byte[] ToArray()
{
throw new IndexOutOfRangeException();
return ByteArrayExtensions.Empty;
}

public IByteBuffer Duplicate()
{
throw new IndexOutOfRangeException();
return this;
}

public IByteBuffer WithOrder(ByteOrder endianness)
Expand Down
22 changes: 12 additions & 10 deletions src/DotNetty.Transport/Channels/Groups/DefaultChannelGroup.cs
Expand Up @@ -310,18 +310,19 @@ public Task NewCloseFuture(IChannelMatcher matcher)

static object SafeDuplicate(object message)
{
if (message is IByteBuffer)
var buffer = message as IByteBuffer;
if (buffer != null)
{
return ((IByteBuffer)message).Duplicate().Retain();
return buffer.Duplicate().Retain();
}
else if (message is IByteBufferHolder)
{
return ((IByteBufferHolder)message).Duplicate().Retain();
}
else

var byteBufferHolder = message as IByteBufferHolder;
if (byteBufferHolder != null)
{
return ReferenceCountUtil.Retain(message);
return byteBufferHolder.Duplicate().Retain();
}

return ReferenceCountUtil.Retain(message);
}

public override bool Equals(object obj)
Expand Down Expand Up @@ -355,13 +356,14 @@ public IChannel[] ToArray()

public bool Remove(IChannelId channelId)
{
IChannel ch = null;
IChannel ch;

if (this.serverChannels.TryRemove(channelId, out ch))
{
return true;
}
else if (this.nonServerChannels.TryRemove(channelId, out ch))

if (this.nonServerChannels.TryRemove(channelId, out ch))
{
return true;
}
Expand Down
Expand Up @@ -34,7 +34,7 @@ public DefaultChannelGroupCompletionSource(IChannelGroup group, Dictionary<IChan
this.futures.Add(pair.Key, pair.Value);
pair.Value.ContinueWith(x =>
{
bool success = x.IsCompleted && !x.IsFaulted && !x.IsCanceled;
bool success = x.Status == TaskStatus.RanToCompletion;
bool callSetDone;
lock (this)
{
Expand All @@ -48,7 +48,7 @@ public DefaultChannelGroupCompletionSource(IChannelGroup group, Dictionary<IChan
}
callSetDone = this.successCount + this.failureCount == this.futures.Count;
Debug.Assert(this.successCount + this.failureCount <= this.futures.Count);
Contract.Assert(this.successCount + this.failureCount <= this.futures.Count);
}
if (callSetDone)
Expand Down

This file was deleted.

1 change: 0 additions & 1 deletion src/DotNetty.Transport/DotNetty.Transport.csproj
Expand Up @@ -111,7 +111,6 @@
<Compile Include="Channels\NotYetConnectedException.cs" />
<Compile Include="Channels\IServerChannel.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Channels\Sockets\SocketAsyncOperationPayloadPool.cs" />
<Compile Include="Channels\DefaultChannelConfiguration.cs" />
<Compile Include="Properties\Friends.cs" />
</ItemGroup>
Expand Down

0 comments on commit 7ccec95

Please sign in to comment.