Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Netstandard2 multi target #382

Open
wants to merge 3 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
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
4 changes: 2 additions & 2 deletions examples/Examples.Common/ExampleHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@ public static string ProcessDirectory
{
get
{
#if NETSTANDARD1_3
#if NETSTANDARD1_3 || NETSTANDARD2_0
return AppContext.BaseDirectory;
#else
return AppDomain.CurrentDomain.BaseDirectory;
return AppDomain.CurrentDomain.BaseDirectory;
#endif
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/DotNetty.Buffers/UnsafeByteBufferUtil .cs
Original file line number Diff line number Diff line change
Expand Up @@ -352,7 +352,7 @@ internal static void SetZero(byte* addr, int length)

internal static string GetString(byte* src, int length, Encoding encoding)
{
#if NETSTANDARD1_3
#if NETSTANDARD1_3 || NETSTANDARD2_0
return encoding.GetString(src, length);
#else
int charCount = encoding.GetCharCount(src, length);
Expand Down
6 changes: 3 additions & 3 deletions src/DotNetty.Handlers/Tls/SniHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -214,9 +214,9 @@ protected override void Decode(IChannelHandlerContext context, IByteBuffer input
};

hostname = idn.GetAscii(hostname);
#if NETSTANDARD1_3
// TODO: netcore does not have culture sensitive tolower()
hostname = hostname.ToLowerInvariant();
#if NETSTANDARD1_3 || NETSTANDARD2_0
// TODO: netcore does not have culture sensitive tolower()
hostname = hostname.ToLowerInvariant();
#else
hostname = hostname.ToLower(new CultureInfo("en-US"));
#endif
Expand Down
16 changes: 8 additions & 8 deletions src/DotNetty.Handlers/Tls/TlsHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -665,8 +665,8 @@ sealed class MediationStream : Stream
int inputLength;
TaskCompletionSource<int> readCompletionSource;
ArraySegment<byte> sslOwnedBuffer;
#if NETSTANDARD1_3
int readByteCount;
#if NETSTANDARD1_3 || NETSTANDARD2_0
int readByteCount;
#else
SynchronousAsyncResult<int> syncReadResult;
AsyncCallback readCallback;
Expand Down Expand Up @@ -710,8 +710,8 @@ public void ExpandSource(int count)

ArraySegment<byte> sslBuffer = this.sslOwnedBuffer;

#if NETSTANDARD1_3
this.readByteCount = this.ReadFromInput(sslBuffer.Array, sslBuffer.Offset, sslBuffer.Count);
#if NETSTANDARD1_3 || NETSTANDARD2_0
this.readByteCount = this.ReadFromInput(sslBuffer.Array, sslBuffer.Offset, sslBuffer.Count);
// hack: this tricks SslStream's continuation to run synchronously instead of dispatching to TP. Remove once Begin/EndRead are available.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Begin/End Read/Write in already added in NETSTANDARD2_0, so maybe override them in this class(and the one in test)?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@yyjdelete Exactly! There are things need to be cleaned up specifically for netstandard 2.0 before we officially support it. Supporting both 1.3 and 2.0 would make some part of code much harder to maintain. Plus, there are so many things we can take advantage of in netstandard 2.0

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can attempt to help with that transition, but I'm not all that familiar with the internals of DotNetty or what specifically netstandard 2.0 added (other than a lot).
To me it seems like a larger project that should be broken out into pieces (perhaps starting with multi-target as the community works on the rest). It also seems that DotNetty is due for a release before that project gets started (would be really nice to get that http pr merged).

new Task(
ms =>
Expand All @@ -731,8 +731,8 @@ public void ExpandSource(int count)
#endif
}

#if NETSTANDARD1_3
public override Task<int> ReadAsync(byte[] buffer, int offset, int count, CancellationToken cancellationToken)
#if NETSTANDARD1_3 || NETSTANDARD2_0
public override Task<int> ReadAsync(byte[] buffer, int offset, int count, CancellationToken cancellationToken)
{
if (this.inputLength - this.inputOffset > 0)
{
Expand Down Expand Up @@ -805,8 +805,8 @@ IAsyncResult PrepareSyncReadResult(int readBytes, object state)
public override Task WriteAsync(byte[] buffer, int offset, int count, CancellationToken cancellationToken)
=> this.owner.FinishWrapNonAppDataAsync(buffer, offset, count);

#if !NETSTANDARD1_3
static readonly Action<Task, object> WriteCompleteCallback = HandleChannelWriteComplete;
#if !NETSTANDARD1_3 && !NETSTANDARD2_0
static readonly Action<Task, object> WriteCompleteCallback = HandleChannelWriteComplete;

public override IAsyncResult BeginWrite(byte[] buffer, int offset, int count, AsyncCallback callback, object state)
{
Expand Down
12 changes: 6 additions & 6 deletions src/DotNetty.Transport.Libuv/Native/NativeMethods.cs
Original file line number Diff line number Diff line change
Expand Up @@ -331,8 +331,8 @@ internal static IPEndPoint TcpGetSocketName(IntPtr handle)
{
Debug.Assert(handle != IntPtr.Zero);

#if NETSTANDARD1_3
int namelen = Marshal.SizeOf<sockaddr>();
#if NETSTANDARD1_3 || NETSTANDARD2_0
int namelen = Marshal.SizeOf<sockaddr>();
#else
int namelen = Marshal.SizeOf(typeof(sockaddr));
#endif
Expand All @@ -344,8 +344,8 @@ internal static IPEndPoint TcpGetPeerName(IntPtr handle)
{
Debug.Assert(handle != IntPtr.Zero);

#if NETSTANDARD1_3
int namelen = Marshal.SizeOf<sockaddr>();
#if NETSTANDARD1_3 || NETSTANDARD2_0
int namelen = Marshal.SizeOf<sockaddr>();
#else
int namelen = Marshal.SizeOf(typeof(sockaddr));
#endif
Expand All @@ -354,8 +354,8 @@ internal static IPEndPoint TcpGetPeerName(IntPtr handle)
return sockaddr.GetIPEndPoint();
}

#if NETSTANDARD1_3
internal static IntPtr Allocate(int size) => Marshal.AllocCoTaskMem(size);
#if NETSTANDARD1_3 || NETSTANDARD2_0
internal static IntPtr Allocate(int size) => Marshal.AllocCoTaskMem(size);

internal static void FreeMemory(IntPtr ptr) => Marshal.FreeCoTaskMem(ptr);
#else
Expand Down
4 changes: 2 additions & 2 deletions src/DotNetty.Transport.Libuv/Native/WindowsApi.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ public void DetachFromIOCP(NativeHandle handle)
IntPtr socket = IntPtr.Zero;
NativeMethods.uv_fileno(handle.Handle, ref socket);

#if NETSTANDARD1_3
uint len = (uint)Marshal.SizeOf<FILE_COMPLETION_INFORMATION>();
#if NETSTANDARD1_3 || NETSTANDARD2_0
uint len = (uint)Marshal.SizeOf<FILE_COMPLETION_INFORMATION>();
#else
uint len = (uint)Marshal.SizeOf(typeof(FILE_COMPLETION_INFORMATION));
#endif
Expand Down
4 changes: 2 additions & 2 deletions src/DotNetty.Transport.Libuv/Native/WriteRequest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ sealed class WriteRequest : NativeRequest, ChannelOutboundBuffer.IMessageProcess

static WriteRequest()
{
#if NETSTANDARD1_3
BufferSize = Marshal.SizeOf<uv_buf_t>();
#if NETSTANDARD1_3 || NETSTANDARD2_0
BufferSize = Marshal.SizeOf<uv_buf_t>();
#else
BufferSize = Marshal.SizeOf(typeof(uv_buf_t));
#endif
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -154,8 +154,8 @@ protected override void ScheduleSocketRead()
{
SocketChannelAsyncOperation operation = this.ReadOperation;
bool pending;
#if NETSTANDARD1_3
pending = this.Socket.ReceiveAsync(operation);
#if NETSTANDARD1_3 || NETSTANDARD2_0
pending = this.Socket.ReceiveAsync(operation);
#else
if (ExecutionContext.IsFlowSuppressed())
{
Expand Down Expand Up @@ -309,8 +309,8 @@ protected bool IncompleteWrite(bool scheduleAsync, SocketChannelAsyncOperation o
this.SetState(StateFlags.WriteScheduled);
bool pending;

#if NETSTANDARD1_3
pending = this.Socket.SendAsync(operation);
#if NETSTANDARD1_3 || NETSTANDARD2_0
pending = this.Socket.SendAsync(operation);
#else
if (ExecutionContext.IsFlowSuppressed())
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,8 +115,8 @@ protected override void ScheduleSocketRead()
operation.SetBuffer(bytes.Array, bytes.Offset, bytes.Count);

bool pending;
#if NETSTANDARD1_3
pending = this.Socket.ReceiveFromAsync(operation);
#if NETSTANDARD1_3 || NETSTANDARD2_0
pending = this.Socket.ReceiveFromAsync(operation);
#else
if (ExecutionContext.IsFlowSuppressed())
{
Expand Down