close
Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
0be4706
custom alloc free custom awaitable
maksimkim Feb 22, 2018
ff944b2
ChannelFuture -> ValueTask
maksimkim Mar 10, 2018
2b6f37d
tls fixes
maksimkim Mar 10, 2018
47ff644
single callback per future + callback execution on executor
maksimkim Mar 10, 2018
4f8f30e
uv changes
maksimkim Mar 10, 2018
c70594a
continuations and recycle are inlined
maksimkim Mar 10, 2018
eef526d
test fixes
maksimkim Mar 11, 2018
8abd878
revert libuv changes
maksimkim Mar 11, 2018
cd0b11e
cleanup
maksimkim Mar 11, 2018
1cef415
update packages
maksimkim Mar 12, 2018
5bed79f
multi continuation support returned back
maksimkim Mar 12, 2018
d0836b0
using nuget.config on pkg restore
maksimkim Mar 12, 2018
ed79cce
add nuget.org source
maksimkim Mar 12, 2018
208e69c
rename
maksimkim Mar 13, 2018
c9d0c8a
execution and sync context preservation
maksimkim Mar 14, 2018
67b306b
context propagation fixes
maksimkim Mar 22, 2018
619bfb8
post rebase fixes
maksimkim Mar 22, 2018
baa5e3a
multicontinuation fix for timeout handler
maksimkim Mar 22, 2018
3428e2f
switch to nuget.org for tasks.extensions package
maksimkim Apr 10, 2018
eb5ab1b
default WriteAndFlushAsync returns Task
maksimkim Apr 11, 2018
4dcb8bb
post rebase fixes
maksimkim Apr 12, 2018
78ec006
remove nuget config
maksimkim Apr 12, 2018
fc447d7
upgrade packages to stable version
maksimkim Jun 5, 2018
03e7b1d
ws fixes
maksimkim Oct 9, 2018
5fab149
bump up package versions
maksimkim Oct 10, 2018
6c99f3a
http test fixes
maksimkim Oct 10, 2018
05e4aa6
fix keep alive implementation
maksimkim Oct 10, 2018
7f08e1d
disable configureawait
maksimkim Oct 10, 2018
c1c9865
package version fixes
maksimkim Oct 10, 2018
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
continuations and recycle are inlined
  • Loading branch information
maksimkim committed Oct 10, 2018
commit c70594a31a9a5b64b60c1af818d67f90ceb4aa86
6 changes: 2 additions & 4 deletions src/DotNetty.Common/Concurrency/AbstractPromise.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,7 @@ public abstract class AbstractPromise : IPromise, IValueTaskSource

static readonly Exception CanceledException = new OperationCanceledException();
static readonly Exception CompletedNoException = new Exception();

protected IEventExecutor executor;

protected Exception exception;

Action<object> callback;
Expand Down Expand Up @@ -131,8 +130,7 @@ bool TryExecuteCallback()

try
{
Contract.Requires(this.executor != null);
this.executor.Execute(this.callback, this.callbackState);
this.callback(this.callbackState);
return true;
}
finally
Expand Down
14 changes: 3 additions & 11 deletions src/DotNetty.Common/Concurrency/AbstractRecyclablePromise.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,31 +40,28 @@ protected override bool TryComplete0(Exception exception)
}
catch
{
this.executor.Execute(this.Recycle);
this.Recycle();
throw;
}

if (completed)
{
this.executor.Execute(this.Recycle);
this.Recycle();
}

return completed;
}

protected void Init(IEventExecutor executor)
protected void Init()
{
this.executor = executor;
this.recycled = false;
}

protected virtual void Recycle()
{
this.executor = null;
this.exception = null;
this.ClearCallback();
this.recycled = true;

this.handle.Release(this);
}

Expand All @@ -81,11 +78,6 @@ void ThrowIfRecycled()
{
throw new InvalidOperationException("Attempt to use recycled channel promise");
}

if (this.executor == null)
{
throw new InvalidOperationException("Attempt to use recyclable channel promise without executor");
}
}
}
}
2 changes: 2 additions & 0 deletions src/DotNetty.Transport/Channels/AbstractChannel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,8 @@ public IChannel Read()
public ValueTask WriteAsync(object msg) => this.pipeline.WriteAsync(msg);

public ValueTask WriteAndFlushAsync(object message) => this.pipeline.WriteAndFlushAsync(message);

public ValueTask WriteAndFlushAsync(object message, bool notifyComplete) => this.pipeline.WriteAndFlushAsync(message, notifyComplete);

public Task CloseCompletion => this.closeFuture.Task;

Expand Down
52 changes: 32 additions & 20 deletions src/DotNetty.Transport/Channels/AbstractChannelHandlerContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -797,7 +797,7 @@ public ValueTask WriteAsync(object msg)
{
Contract.Requires(msg != null);
// todo: check for cancellation
return this.WriteAsync(msg, false);
return this.WriteAsync(msg, FlushMode.NoFlush);
}

ValueTask InvokeWriteAsync(object msg) => this.Added ? this.InvokeWriteAsync0(msg) : this.WriteAsync(msg);
Expand Down Expand Up @@ -853,41 +853,45 @@ void InvokeFlush0()
}
}

public ValueTask WriteAndFlushAsync(object message)
public ValueTask WriteAndFlushAsync(object message) => this.WriteAndFlushAsync(message, true);

public ValueTask WriteAndFlushAsync(object message, bool notifyComplete)
{
Contract.Requires(message != null);
// todo: check for cancellation

return this.WriteAsync(message, true);
return this.WriteAsync(message, notifyComplete ? FlushMode.Flush : FlushMode.VoidFlush);
}

ValueTask InvokeWriteAndFlushAsync(object msg)
ValueTask InvokeWriteAndFlushAsync(object msg, bool notifyComplete)
{
if (this.Added)
{
ValueTask task = this.InvokeWriteAsync0(msg);
//flush can synchronously complete write, hence Task allocation required to capture result
task = notifyComplete ? task.Preserve() : default(ValueTask);
this.InvokeFlush0();
return task;
}
return this.WriteAndFlushAsync(msg);
}

ValueTask WriteAsync(object msg, bool flush)
ValueTask WriteAsync(object msg, FlushMode mode)
{
AbstractChannelHandlerContext next = this.FindContextOutbound();
object m = this.pipeline.Touch(msg, next);
IEventExecutor nextExecutor = next.Executor;
if (nextExecutor.InEventLoop)
{
return flush
? next.InvokeWriteAndFlushAsync(m)
: next.InvokeWriteAsync(m);
return mode == FlushMode.NoFlush
? next.InvokeWriteAsync(m)
: next.InvokeWriteAndFlushAsync(m, mode == FlushMode.Flush);
}
else
{
AbstractWriteTask task = flush
? WriteAndFlushTask.NewInstance(next, m)
: (AbstractWriteTask)WriteTask.NewInstance(next, m);
AbstractWriteTask task = mode == FlushMode.NoFlush
? WriteTask.NewInstance(next, m)
: (AbstractWriteTask)WriteAndFlushTask.NewInstance(next, m, mode == FlushMode.Flush);
SafeExecuteOutbound(nextExecutor, task, msg);
return task;
}
Expand Down Expand Up @@ -974,6 +978,13 @@ static void SafeExecuteOutbound(IEventExecutor executor, AbstractWriteTask task,

public override string ToString() => $"{typeof(IChannelHandlerContext).Name} ({this.Name}, {this.Channel})";

enum FlushMode : byte
{
NoFlush = 0,
VoidFlush = 1,
Flush = 2
}

abstract class AbstractWriteTask : AbstractRecyclablePromise, IRunnable
{
static readonly bool EstimateTaskSizeOnSubmit =
Expand All @@ -989,7 +1000,7 @@ abstract class AbstractWriteTask : AbstractRecyclablePromise, IRunnable

protected static void Init(AbstractWriteTask task, AbstractChannelHandlerContext ctx, object msg)
{
task.Init(ctx.Executor);
task.Init();
task.ctx = ctx;
task.msg = msg;

Expand Down Expand Up @@ -1047,7 +1058,7 @@ public void Run()
}
}

protected virtual ValueTask WriteAsync(AbstractChannelHandlerContext ctx, object msg) => ctx.InvokeWriteAsync(msg);
protected abstract ValueTask WriteAsync(AbstractChannelHandlerContext ctx, object msg);

/*public override void Recycle()
{
Expand All @@ -1072,30 +1083,31 @@ public static WriteTask NewInstance(AbstractChannelHandlerContext ctx, object ms
: base(handle)
{
}

protected override ValueTask WriteAsync(AbstractChannelHandlerContext ctx, object msg) => ctx.InvokeWriteAsync(msg);
}

sealed class WriteAndFlushTask : AbstractWriteTask
{
bool notifyComplete;

static readonly ThreadLocalPool<WriteAndFlushTask> Recycler = new ThreadLocalPool<WriteAndFlushTask>(handle => new WriteAndFlushTask(handle));

public static WriteAndFlushTask NewInstance(AbstractChannelHandlerContext ctx, object msg)
public static WriteAndFlushTask NewInstance(AbstractChannelHandlerContext ctx, object msg, bool notifyComplete)
{
WriteAndFlushTask task = Recycler.Take();
Init(task, ctx, msg);
task.notifyComplete = notifyComplete;
return task;
}

WriteAndFlushTask(ThreadLocalPool.Handle handle)
: base(handle)
{
}

protected override ValueTask WriteAsync(AbstractChannelHandlerContext ctx, object msg) => ctx.InvokeWriteAndFlushAsync(msg, this.notifyComplete);

protected override ValueTask WriteAsync(AbstractChannelHandlerContext ctx, object msg)
{
ValueTask result = base.WriteAsync(ctx, msg);
ctx.InvokeFlush();
return result;
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -334,7 +334,7 @@ sealed class PendingWrite : AbstractRecyclablePromise
public static PendingWrite NewInstance(IEventExecutor executor, object msg, int size)
{
PendingWrite write = Pool.Take();
write.Init(executor);
write.Init();
write.Add(msg, size);
return write;
}
Expand Down
2 changes: 1 addition & 1 deletion src/DotNetty.Transport/Channels/ChannelOutboundBuffer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -808,7 +808,7 @@ sealed class Entry : AbstractRecyclablePromise
public static Entry NewInstance(IEventExecutor executor, object msg, int size)
{
Entry entry = Pool.Take();
entry.Init(executor);
entry.Init();
entry.Message = msg;
entry.PendingSize = size;
return entry;
Expand Down
2 changes: 2 additions & 0 deletions src/DotNetty.Transport/Channels/DefaultChannelPipeline.cs
Original file line number Diff line number Diff line change
Expand Up @@ -831,6 +831,8 @@ public IChannelPipeline Flush()
}

public ValueTask WriteAndFlushAsync(object msg) => this.tail.WriteAndFlushAsync(msg);

public ValueTask WriteAndFlushAsync(object msg, bool notifyComplete) => this.tail.WriteAndFlushAsync(msg, notifyComplete);

string FilterName(string name, IChannelHandler handler)
{
Expand Down
2 changes: 2 additions & 0 deletions src/DotNetty.Transport/Channels/IChannel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -67,5 +67,7 @@ public interface IChannel : IAttributeMap, IComparable<IChannel>
IChannel Flush();

ValueTask WriteAndFlushAsync(object message);

ValueTask WriteAndFlushAsync(object message, bool notifyComplete);
}
}
2 changes: 2 additions & 0 deletions src/DotNetty.Transport/Channels/IChannelHandlerContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,8 @@ public interface IChannelHandlerContext : IAttributeMap
IChannelHandlerContext Flush();

ValueTask WriteAndFlushAsync(object message);

ValueTask WriteAndFlushAsync(object message, bool notifyComplete);

/// <summary>
/// Request to bind to the given <see cref="EndPoint"/>.
Expand Down
2 changes: 2 additions & 0 deletions src/DotNetty.Transport/Channels/IChannelPipeline.cs
Original file line number Diff line number Diff line change
Expand Up @@ -695,5 +695,7 @@ public interface IChannelPipeline : IEnumerable<IChannelHandler>
/// Shortcut for calling both <see cref="WriteAsync"/> and <see cref="Flush"/>.
/// </summary>
ValueTask WriteAndFlushAsync(object msg);

ValueTask WriteAndFlushAsync(object msg, bool notifyComplete);
}
}
2 changes: 1 addition & 1 deletion src/DotNetty.Transport/Channels/PendingWriteQueue.cs
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,7 @@ sealed class PendingWrite : AbstractRecyclablePromise
public static PendingWrite NewInstance(IEventExecutor executor, object msg, int size)
{
PendingWrite write = Pool.Take();
write.Init(executor);
write.Init();
write.Size = size;
write.Msg = msg;
return write;
Expand Down