Skip to content

Commit

Permalink
Update DotNettyMessageSender.cs
Browse files Browse the repository at this point in the history
  • Loading branch information
fanliang11 authored Jun 20, 2024
1 parent 63d8fbc commit 753f1f8
Showing 1 changed file with 10 additions and 49 deletions.
59 changes: 10 additions & 49 deletions src/Surging.Core/Surging.Core.DotNetty/DotNettyMessageSender.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

namespace Surging.Core.DotNetty
{
/// <summary>
/// <summary>
/// 基于DotNetty的消息发送者基类。
/// </summary>
public abstract class DotNettyMessageSender
Expand Down Expand Up @@ -62,18 +62,9 @@ public void Dispose()
/// <returns>一个任务。</returns>
public async Task SendAsync(TransportMessage message)
{
var buffer = GetByteBuffer(message);
try
{
await _channel.WriteAndFlushAsync(buffer);
}
finally
{
if (buffer != null)
{
ReferenceCountUtil.Release(buffer);
}
}
var buffer = GetByteBuffer(message);
await _channel.WriteAndFlushAsync(buffer);

}

/// <summary>
Expand All @@ -83,18 +74,8 @@ public async Task SendAsync(TransportMessage message)
/// <returns>一个任务。</returns>
public async Task SendAndFlushAsync(TransportMessage message)
{
var buffer = GetByteBuffer(message);
try
{
await _channel.WriteAndFlushAsync(buffer);
}
finally
{
if (buffer != null)
{
ReferenceCountUtil.Release(buffer);
}
}
var buffer = GetByteBuffer(message);
await _channel.WriteAndFlushAsync(buffer);
}

#endregion Implementation of IMessageSender
Expand All @@ -121,18 +102,8 @@ public DotNettyServerMessageSender(ITransportMessageEncoder transportMessageEnco
/// <returns>一个任务。</returns>
public async Task SendAsync(TransportMessage message)
{
var buffer = GetByteBuffer(message);
try
{
await _context.WriteAsync(buffer);
}
finally
{
if (buffer != null)
{
ReferenceCountUtil.Release(buffer);
}
}
var buffer = GetByteBuffer(message);
await _context.WriteAsync(buffer);
}

/// <summary>
Expand All @@ -142,18 +113,8 @@ public async Task SendAsync(TransportMessage message)
/// <returns>一个任务。</returns>
public async Task SendAndFlushAsync(TransportMessage message)
{
var buffer = GetByteBuffer(message);
try
{
await _context.WriteAndFlushAsync(buffer);
}
finally
{
if (buffer != null)
{
ReferenceCountUtil.Release(buffer);
}
}
var buffer = GetByteBuffer(message);
await _context.WriteAndFlushAsync(buffer);
}

#endregion Implementation of IMessageSender
Expand Down

0 comments on commit 753f1f8

Please sign in to comment.