-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use value tasks for async network stream (closes #4)
- Loading branch information
Showing
12 changed files
with
700 additions
and
111 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,41 @@ | ||
using System; | ||
using Microsoft.Extensions.Logging; | ||
using Microsoft.Extensions.Logging.Console; | ||
|
||
namespace Codestellation.SolarWind.Tests | ||
{ | ||
public static class TestContext | ||
{ | ||
public static readonly ILoggerFactory LoggerFactory = | ||
new LoggerFactory(new ILoggerProvider[] {new ConsoleLoggerProvider((s, level) => true, false)}); | ||
public static readonly ILoggerFactory LoggerFactory = new ConsoleLoggerFactory(); | ||
|
||
public class ConsoleLoggerFactory : ILoggerFactory | ||
{ | ||
public void Dispose() => throw new NotImplementedException(); | ||
|
||
public ILogger CreateLogger(string categoryName) | ||
=> ConsoleLogger.Instance; | ||
|
||
public void AddProvider(ILoggerProvider provider) => throw new NotImplementedException(); | ||
} | ||
|
||
public class ConsoleLogger : ILogger | ||
{ | ||
public static readonly ConsoleLogger Instance = new ConsoleLogger(); | ||
|
||
private ConsoleLogger() | ||
{ | ||
} | ||
|
||
public void Log<TState>( | ||
LogLevel logLevel, | ||
EventId eventId, | ||
TState state, | ||
Exception exception, | ||
Func<TState, Exception, string> formatter) | ||
=> Console.WriteLine(formatter(state, exception)); | ||
|
||
public bool IsEnabled(LogLevel logLevel) => true; | ||
|
||
public IDisposable BeginScope<TState>(TState state) => throw new NotImplementedException(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
using System; | ||
using System.Net.Sockets; | ||
using System.Runtime.CompilerServices; | ||
using System.Threading.Tasks; | ||
using System.Threading.Tasks.Sources; | ||
using Codestellation.SolarWind.Threading; | ||
|
||
namespace Codestellation.SolarWind.Internals | ||
{ | ||
internal class CompletionSourceAsyncEventArgs : SocketAsyncEventArgs, IValueTaskSource | ||
{ | ||
private SyncValueTaskSourceCore _valueSource = new SyncValueTaskSourceCore(); | ||
|
||
public ValueTask Task | ||
{ | ||
[MethodImpl(MethodImplOptions.AggressiveInlining)] | ||
get => new ValueTask(this, _valueSource.Version); | ||
} | ||
|
||
public void Reset() | ||
=> _valueSource.Reset(); | ||
|
||
public void SetException(Exception exception) | ||
=> _valueSource.SetException(exception); | ||
|
||
public void SetResult() | ||
=> _valueSource.SetResult(); | ||
|
||
public ValueTaskSourceStatus GetStatus(short token) | ||
=> _valueSource.GetStatus(token); | ||
|
||
public void OnCompleted(Action<object> continuation, object state, short token, ValueTaskSourceOnCompletedFlags flags) | ||
=> _valueSource.OnCompleted(continuation, state, token, flags); | ||
|
||
public void GetResult(short token) | ||
=> _valueSource.GetResult(token); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.