Skip to content

Commit

Permalink
fixed all the old name "Channel"
Browse files Browse the repository at this point in the history
  • Loading branch information
kerryjiang committed Oct 26, 2024
1 parent 20f3277 commit aa17cab
Show file tree
Hide file tree
Showing 11 changed files with 89 additions and 26 deletions.
2 changes: 1 addition & 1 deletion src/SuperSocket.Connection/PipeConnection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ protected async ValueTask<bool> ProcessOutputRead(PipeReader reader)
}
catch (Exception e)
{
// Cancel all the work in the channel if encounter an error during sending
// Cancel all the work in the connection if encounter an error during sending
Cancel();

if (!IsIgnorableException(e))
Expand Down
6 changes: 3 additions & 3 deletions src/SuperSocket.Connection/PipeConnectionBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ private async ValueTask HandleClosing()
}
catch (Exception e)
{
OnError("Unhandled exception in the method PipeChannel.Run.", e);
OnError("Unhandled exception in the method PipeConnection.Run.", e);
}
finally
{
Expand All @@ -120,7 +120,7 @@ private async ValueTask HandleClosing()
catch (Exception exc)
{
if (!IsIgnorableException(exc))
OnError("Unhandled exception in the method PipeChannel.Close.", exc);
OnError("Unhandled exception in the method PipeConnection.Close.", exc);
}
}
}
Expand Down Expand Up @@ -160,7 +160,7 @@ private void CheckConnectionOpen()
{
if (this.IsClosed)
{
throw new Exception("Channel is closed now, send is not allowed.");
throw new Exception("Connection is closed now, send is not allowed.");
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/SuperSocket.Server/Connection/TcpConnectionListener.cs
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ private async void OnNewClientAccept(Socket socket)
}
catch (Exception e)
{
_logger.LogError(e, $"Failed to create channel for {socket.RemoteEndPoint}.");
_logger.LogError(e, $"Failed to create connection for {socket.RemoteEndPoint}.");
return;
}

Expand Down
6 changes: 3 additions & 3 deletions src/SuperSocket.Server/SuperSocketService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ private Task<bool> StartListenAsync(CancellationToken cancellationToken)

if (!AddConnectionListener(null, serverOptions))
{
_logger.LogError($"Failed to add the channel creator.");
_logger.LogError($"Failed to add the connection creator.");
return Task.FromResult(false);
}
}
Expand Down Expand Up @@ -288,7 +288,7 @@ private async ValueTask<bool> InitializeSession(IAppSession session, IConnection
return false;
}

connection.Closed += (s, e) => OnChannelClosed(session, e);
connection.Closed += (s, e) => OnConnectionClosed(session, e);
return true;
}

Expand All @@ -303,7 +303,7 @@ protected virtual ValueTask OnSessionConnectedAsync(IAppSession session)
return new ValueTask();
}

private void OnChannelClosed(IAppSession session, CloseEventArgs e)
private void OnConnectionClosed(IAppSession session, CloseEventArgs e)
{
FireSessionClosedEvent(session as AppSession, e.Reason).DoNotAwait();
}
Expand Down
2 changes: 1 addition & 1 deletion src/SuperSocket.Udp/UdpConnectionListener.cs
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ private async ValueTask<IConnection> CreateConnection(Socket socket, IPEndPoint
}
catch (Exception e)
{
_logger.LogError(e, $"Failed to create channel for {socket.RemoteEndPoint}.");
_logger.LogError(e, $"Failed to create connection for {socket.RemoteEndPoint}.");
return null;
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/SuperSocket.WebSocket.Server/WebSocketPackageHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -354,8 +354,8 @@ private async ValueTask<bool> HandleHandshake(IAppSession session, WebSocketPack

if (selectedExtensionHeadItems != null && selectedExtensionHeadItems.Count > 0)
{
var pipeChannel = session.Connection as IPipeConnection;
pipeChannel.PipelineFilter.Context = new WebSocketPipelineFilterContext
var pipeConnection = session.Connection as IPipeConnection;
pipeConnection.PipelineFilter.Context = new WebSocketPipelineFilterContext
{
Extensions = extensions
};
Expand Down
8 changes: 4 additions & 4 deletions src/SuperSocket.WebSocket.Server/WebSocketSession.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
using SuperSocket.ProtoBase;
using SuperSocket.Server;
using SuperSocket.Server.Abstractions.Session;
using ChannelCloseReason = SuperSocket.Connection.CloseReason;
using ConnectionCloseReason = SuperSocket.Connection.CloseReason;

namespace SuperSocket.WebSocket.Server
{
Expand Down Expand Up @@ -117,17 +117,17 @@ private void OnCloseHandshakeStarted()

internal void CloseWithoutHandshake()
{
base.CloseAsync(ChannelCloseReason.LocalClosing).DoNotAwait();
base.CloseAsync(ConnectionCloseReason.LocalClosing).DoNotAwait();
}

public override async ValueTask CloseAsync(ChannelCloseReason closeReason)
public override async ValueTask CloseAsync(ConnectionCloseReason closeReason)
{
var closeStatus = CloseStatus;

if (closeStatus != null)
{
var clientInitiated = closeStatus.RemoteInitiated;
await base.CloseAsync(clientInitiated ? ChannelCloseReason.RemoteClosing : ChannelCloseReason.LocalClosing);
await base.CloseAsync(clientInitiated ? ConnectionCloseReason.RemoteClosing : ConnectionCloseReason.LocalClosing);
return;
}

Expand Down
6 changes: 3 additions & 3 deletions test/SuperSocket.Benchmarks/TransparentPipeConnection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@ namespace SuperSocket.Benchmarks
public class TransparentPipeConnection : PipeConnection
{
private TaskCompletionSource<int> _tcs;
private Task<int> _channelTask;
private Task<int> _connectionTask;

public TransparentPipeConnection(ConnectionOptions options)
: base(options)
{
_tcs = new TaskCompletionSource<int>();
_channelTask = _tcs.Task;
_connectionTask = _tcs.Task;
}

public override ValueTask CloseAsync(CloseReason closeReason)
Expand All @@ -32,7 +32,7 @@ protected override void Close()

protected override async ValueTask<int> FillPipeWithDataAsync(Memory<byte> memory, CancellationToken cancellationToken)
{
await _channelTask;
await _connectionTask;
return 0;
}

Expand Down
14 changes: 7 additions & 7 deletions test/SuperSocket.Tests/ClientTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -257,38 +257,38 @@ public async Task TestCommandLine(Type hostConfiguratorType)
}

[Fact]
[Trait("Category", "TestDetachableChannel")]
public async Task TestDetachableChannel()
[Trait("Category", "TestDetachableConnection")]
public async Task TestDetachableConnection()
{
IHostConfigurator hostConfigurator = new RegularHostConfigurator();

await TestDetachableChannelInternal(hostConfigurator, (_, socket) =>
await TestDetachableConnectionInternal(hostConfigurator, (_, socket) =>
new StreamPipeConnection(
hostConfigurator.GetClientStream(socket).Result,
socket.RemoteEndPoint,
socket.LocalEndPoint,
new ConnectionOptions
{
Logger = DefaultLoggerFactory.CreateLogger(nameof(TestDetachableChannel)),
Logger = DefaultLoggerFactory.CreateLogger(nameof(TestDetachableConnection)),
ReadAsDemand = true
})
);

/* KestrelPipeConnection doesn't support Detach right now.
await TestDetachableChannelInternal(new KestralConnectionHostConfigurator(), (server, socket) =>
await TestDetachableConnectionInternal(new KestralConnectionHostConfigurator(), (server, socket) =>
new KestrelPipeConnection(
server.ServiceProvider.GetService<SocketConnectionContextFactory>().Create(socket),
new ConnectionOptions
{
Logger = DefaultLoggerFactory.CreateLogger(nameof(TestDetachableChannel)),
Logger = DefaultLoggerFactory.CreateLogger(nameof(TestDetachableConnection)),
ReadAsDemand = false
}
)
);
*/
}

async Task TestDetachableChannelInternal(IHostConfigurator hostConfigurator, Func<IServer, Socket, IConnection> connectionFactory)
async Task TestDetachableConnectionInternal(IHostConfigurator hostConfigurator, Func<IServer, Socket, IConnection> connectionFactory)
{
using (var server = CreateSocketServerBuilder<TextPackageInfo, LinePipelineFilter>(hostConfigurator)
.UsePackageHandler(async (s, p) =>
Expand Down
63 changes: 63 additions & 0 deletions test/SuperSocket.Tests/SessionTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,69 @@ public async Task TestCloseReason(Type hostConfiguratorType)
}
}

[Theory]
[InlineData(typeof(RegularHostConfigurator), 198)]
[InlineData(typeof(RegularHostConfigurator), 255)]
public async Task TestCustomCloseReason(Type hostConfiguratorType, int closeReasonCode)
{
var hostConfigurator = CreateObject<IHostConfigurator>(hostConfiguratorType);

IAppSession session = null;

CloseReason closeReason = CloseReason.Unknown;

var resetEvent = new AutoResetEvent(true);

using (var server = CreateSocketServerBuilder<TextPackageInfo, LinePipelineFilter>(hostConfigurator)
.ConfigureAppConfiguration((HostBuilder, configBuilder) =>
{
configBuilder.AddInMemoryCollection(new Dictionary<string, string>
{
{ "serverOptions:maxPackageLength", "8" }
});
})
.UseSessionHandler(
onConnected: (s) =>
{
session = s;
resetEvent.Set();
return ValueTask.CompletedTask;
},
onClosed: (s, e) =>
{
closeReason = e.Reason;
resetEvent.Set();
return ValueTask.CompletedTask;
})
.BuildAsServer())
{
Assert.Equal("TestServer", server.Name);

Assert.True(await server.StartAsync());
OutputHelper.WriteLine("Started.");

using (var socket = CreateClient(hostConfigurator))
using (var socketStream = await hostConfigurator.GetClientStream(socket))
{
resetEvent.WaitOne(1000);

// LocalClosing
closeReason = CloseReason.Unknown;

var closeReasonRequested = (CloseReason)closeReasonCode;

await session.CloseAsync(closeReasonRequested);

resetEvent.WaitOne(1000);

Assert.Equal(SessionState.Closed, session.State);
Assert.Equal(closeReasonRequested, closeReason);
}

await server.StopAsync();
}
}

[Fact]
public async Task TestConsoleProtocol()
{
Expand Down
2 changes: 1 addition & 1 deletion unlist.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@ nuget delete SuperSocket.WebSocket "$version" -source nuget.org -NonInteractive
nuget delete SuperSocket.Server "$version" -source nuget.org -NonInteractive
nuget delete SuperSocket.SessionContainer "$version" -source nuget.org -NonInteractive
nuget delete SuperSocket.Command "$version" -source nuget.org -NonInteractive
nuget delete SuperSocket.Channel "$version" -source nuget.org -NonInteractive
nuget delete SuperSocket.Connection "$version" -source nuget.org -NonInteractive
nuget delete SuperSocket.Primitives "$version" -source nuget.org -NonInteractive
nuget delete SuperSocket.ProtoBase "$version" -source nuget.org -NonInteractive

0 comments on commit aa17cab

Please sign in to comment.