本文整理汇总了C#中IChannelHandlerContext.CloseAsync方法的典型用法代码示例。如果您正苦于以下问题:C# IChannelHandlerContext.CloseAsync方法的具体用法?C# IChannelHandlerContext.CloseAsync怎么用?C# IChannelHandlerContext.CloseAsync使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IChannelHandlerContext
的用法示例。
在下文中一共展示了IChannelHandlerContext.CloseAsync方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ContinueScenarioExecution
void ContinueScenarioExecution(IChannelHandlerContext context)
{
if (!this.testScenario.MoveNext())
{
context.CloseAsync()
.ContinueWith(
t => this.completion.TrySetException(t.Exception),
TaskContinuationOptions.OnlyOnFaulted | TaskContinuationOptions.ExecuteSynchronously);
this.completion.TryComplete();
return;
}
foreach (object message in this.testScenario.Current.SendMessages)
{
context.WriteAsync(message)
.ContinueWith(
t => this.completion.TrySetException(t.Exception),
TaskContinuationOptions.OnlyOnFaulted | TaskContinuationOptions.ExecuteSynchronously);
}
context.Flush();
}
示例2: ContinueScenarioExecution
void ContinueScenarioExecution(IChannelHandlerContext context)
{
if (!this.testScenario.MoveNext())
{
context.CloseAsync()
.ContinueWith(
t => this.completion.TrySetException(t.Exception),
TaskContinuationOptions.OnlyOnFaulted | TaskContinuationOptions.ExecuteSynchronously);
this.completion.TryComplete();
return;
}
TestScenarioStep currentStep = this.testScenario.Current;
if (currentStep.Delay > TimeSpan.Zero)
{
context.Channel.EventLoop.Schedule((ctx, state) => this.ExecuteStep((IChannelHandlerContext)ctx, (TestScenarioStep)state), context, currentStep, currentStep.Delay);
}
else
{
this.ExecuteStep(context, currentStep);
}
}
示例3: CloseAsync
public virtual Task CloseAsync(IChannelHandlerContext context) => context.CloseAsync();
示例4: NotifyHandshakeFailure
public static void NotifyHandshakeFailure(IChannelHandlerContext ctx, Exception cause)
{
// We have may haven written some parts of data before an exception was thrown so ensure we always flush.
// See https://github.com/netty/netty/issues/3900#issuecomment-172481830
ctx.Flush();
ctx.FireUserEventTriggered(new TlsHandshakeCompletionEvent(cause));
ctx.CloseAsync();
}
示例5: ExceptionCaught
public override void ExceptionCaught(IChannelHandlerContext context, Exception exception)
{
Console.WriteLine("Exception: " + exception);
context.CloseAsync();
}
示例6: ExceptionCaught
public override void ExceptionCaught(IChannelHandlerContext context, Exception exception)
{
this.completion.TrySetException(exception);
context.CloseAsync();
}
示例7: ChannelRead
public override void ChannelRead(IChannelHandlerContext context, object message)
{
_event.Signal();
context.CloseAsync();
}
示例8: ExceptionCaught
//---------------------------------------------------------------------
public override void ExceptionCaught(IChannelHandlerContext context, Exception exception)
{
context.CloseAsync();
}
示例9: Shutdown
async void Shutdown(IChannelHandlerContext context)
{
if (this.IsInState(StateFlags.Closed))
{
return;
}
try
{
this.stateFlags |= StateFlags.Closed; // "or" not to interfere with ongoing logic which has to honor Closed state when it's right time to do (case by case)
this.CloseIotHubConnection();
await context.CloseAsync();
}
catch
{
// ignored
}
}
示例10: Shutdown
/// <summary>
/// Closes channel
/// </summary>
/// <param name="context"></param>
/// <param name="graceful"></param>
async void Shutdown(IChannelHandlerContext context, bool graceful)
{
if (this.IsInState(StateFlags.Closed))
{
return;
}
try
{
this.stateFlags |= StateFlags.Closed; // "or" not to interfere with ongoing logic which has to honor Closed state when it's right time to do (case by case)
PerformanceCounters.ConnectionsCurrent.Decrement();
Queue<Packet> connectQueue = this.connectPendingQueue;
if (connectQueue != null)
{
while (connectQueue.Count > 0)
{
Packet packet = connectQueue.Dequeue();
ReferenceCountUtil.Release(packet);
}
}
PublishPacket will = !graceful && this.IsInState(StateFlags.Connected) ? this.willPacket : null;
if (will != null)
{
// try publishing will message before shutting down IoT Hub connection
try
{
this.publishProcessor.Post(context, will);
}
catch (Exception ex)
{
MqttIotHubAdapterEventSource.Log.Warning("Failed sending Will Message.", ex);
}
}
this.CloseIotHubConnection();
await context.CloseAsync();
}
catch (Exception ex)
{
MqttIotHubAdapterEventSource.Log.Warning("Error occurred while shutting down the channel.", ex);
}
}
示例11: CloseAsync
public override Task CloseAsync(IChannelHandlerContext ctx)
{
if (this.Logger.IsEnabled(this.InternalLevel))
{
this.Logger.Log(this.InternalLevel, this.Format(ctx, "CLOSE"));
}
return ctx.CloseAsync();
}
示例12: ExceptionCaught
public override void ExceptionCaught(IChannelHandlerContext context, Exception exception)
{
base.ExceptionCaught(context, exception);
NotifyListener(new Disassociated(DisassociateInfo.Unknown));
context.CloseAsync(); // close the channel
}
示例13: ShutdownOnError
static async void ShutdownOnError(IChannelHandlerContext context, Exception exception)
{
var self = (MqttIotHubAdapter)context.Handler;
if (!self.IsInState(StateFlags.Closed))
{
self.stateFlags |= StateFlags.Closed;
self.subscribeCompletion?.TrySetException(exception);
self.deviceBoundOneWayProcessor.Abort(exception);
self.deviceBoundTwoWayProcessor.Abort(exception);
self.serviceBoundOneWayProcessor.Abort(exception);
self.serviceBoundTwoWayProcessor.Abort(exception);
self.onError(exception);
try
{
await context.CloseAsync();
}
catch (Exception ex) when (!ex.IsFatal())
{
//ignored
}
}
}
示例14: ExceptionCaught
public override void ExceptionCaught(IChannelHandlerContext context, Exception exception)
{
if (!(exception is ObjectDisposedException))
log.Warn($"Exception in NettyServerHandler {context.Channel.Id.AsShortText()}: {exception.Message}");
context.CloseAsync();
}
示例15: ExceptionCaught
public override void ExceptionCaught(IChannelHandlerContext context, Exception exception)
{
log.Warn($"Exception in NettyClientHandler: {exception.Message}");
context.CloseAsync();
}