本文整理汇总了C#中IChannelHandlerContext.Flush方法的典型用法代码示例。如果您正苦于以下问题:C# IChannelHandlerContext.Flush方法的具体用法?C# IChannelHandlerContext.Flush怎么用?C# IChannelHandlerContext.Flush使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IChannelHandlerContext
的用法示例。
在下文中一共展示了IChannelHandlerContext.Flush方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: Flush
public virtual void Flush(IChannelHandlerContext context) => context.Flush();
示例3: 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();
}
示例4: ChannelReadComplete
public override void ChannelReadComplete(IChannelHandlerContext context)
{
context.Flush();
}
示例5: ExecuteStep
void ExecuteStep(IChannelHandlerContext context, TestScenarioStep currentStep)
{
if (!context.Channel.Open)
{
// todo: dispose scheduled work in case of channel closure instead?
return;
}
Task lastTask = null;
object lastMessage = null;
foreach (object message in currentStep.Messages)
{
lastMessage = message;
var writeTimeoutCts = new CancellationTokenSource();
Task task = context.WriteAsync(message);
object timeoutExcMessage = message;
context.Channel.EventLoop.Schedule(
() => this.completion.TrySetException(new TimeoutException(string.Format("Sending of message did not complete in time: {0}", timeoutExcMessage))),
this.sendTimeout,
writeTimeoutCts.Token);
task.ContinueWith(
t => writeTimeoutCts.Cancel(),
TaskContinuationOptions.OnlyOnRanToCompletion | TaskContinuationOptions.ExecuteSynchronously);
task.OnFault(t => this.completion.TrySetException(t.Exception));
lastTask = task;
}
if (currentStep.WaitForFeedback)
{
if (this.responseTimeout > TimeSpan.Zero)
{
this.responseTimeoutCts = new CancellationTokenSource();
if (lastTask == null)
{
this.ScheduleReadTimeoutCheck(context, null);
}
else
{
lastTask.ContinueWith(
t => this.ScheduleReadTimeoutCheck(context, lastMessage),
TaskContinuationOptions.OnlyOnRanToCompletion | TaskContinuationOptions.ExecuteSynchronously);
}
}
}
context.Flush();
if (!currentStep.WaitForFeedback)
{
context.Channel.EventLoop.Execute(
ctx => this.ContinueScenarioExecution((IChannelHandlerContext)ctx),
context);
}
}
示例6: Flush
public void Flush(IChannelHandlerContext context)
{
context.Flush();
}
示例7: ProcessPendingSubscriptionChanges
async void ProcessPendingSubscriptionChanges(IChannelHandlerContext context)
{
try
{
do
{
ISessionState newState = this.sessionState.Copy();
Queue<Packet> queue = this.SubscriptionChangeQueue;
var acks = new List<Packet>(queue.Count);
foreach (Packet packet in queue) // todo: if can queue be null here, don't force creation
{
switch (packet.PacketType)
{
case PacketType.SUBSCRIBE:
acks.Add(Util.AddSubscriptions(newState, (SubscribePacket)packet, this.maxSupportedQosToClient));
break;
case PacketType.UNSUBSCRIBE:
acks.Add(Util.RemoveSubscriptions(newState, (UnsubscribePacket)packet));
break;
default:
throw new ArgumentOutOfRangeException();
}
}
queue.Clear();
if (!this.sessionState.IsTransient)
{
// save updated session state, make it current once successfully set
await this.sessionStateManager.SetAsync(this.deviceId, newState);
}
this.sessionState = newState;
// release ACKs
var tasks = new List<Task>(acks.Count);
foreach (Packet ack in acks)
{
tasks.Add(context.WriteAsync(ack));
}
context.Flush();
await Task.WhenAll(tasks);
PerformanceCounters.PacketsSentPerSecond.IncrementBy(acks.Count);
}
while (this.subscriptionChangeQueue.Count > 0);
this.ResetState(StateFlags.ChangingSubscriptions);
}
catch (Exception ex)
{
ShutdownOnError(context, "-> UN/SUBSCRIBE", ex);
}
}
示例8: Flush
public override void Flush(IChannelHandlerContext ctx)
{
if (this.Logger.IsEnabled(this.InternalLevel))
{
this.Logger.Log(this.InternalLevel, this.Format(ctx, "FLUSH"));
}
ctx.Flush();
}
示例9: ChannelActive
public override void ChannelActive(IChannelHandlerContext context)
{
// write a large enough blob of data that it has to be split into multiple writes
var channel = context.Channel;
_tasks.Enqueue(
context.WriteAsync(context.Allocator.Buffer().WriteZero(1048576))
.ContinueWith(tr => channel.CloseAsync(),
TaskContinuationOptions.ExecuteSynchronously | TaskContinuationOptions.OnlyOnRanToCompletion)
.Unwrap());
_tasks.Enqueue(context.WriteAsync(context.Allocator.Buffer().WriteZero(1048576)));
context.Flush();
_tasks.Enqueue(context.WriteAsync(context.Allocator.Buffer().WriteZero(1048576)));
context.Flush();
}
示例10: ReadTimedOut
/// <summary>
/// Is called when a read timeout was detected.
/// </summary>
/// <param name="context">Context.</param>
protected virtual void ReadTimedOut(IChannelHandlerContext context)
{
if(!this.closed)
{
context.FireExceptionCaught(ReadTimeoutException.Instance);
context.Flush();
this.closed = true;
}
}