Skip to content

Commit

Permalink
- to support il2cpp
Browse files Browse the repository at this point in the history
  • Loading branch information
bingcongni committed May 17, 2021
1 parent f79d65b commit a68170c
Show file tree
Hide file tree
Showing 10 changed files with 74 additions and 15 deletions.
14 changes: 13 additions & 1 deletion src/DotNetty.Transport.Libuv/Native/Async.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,14 @@
* Licensed under the MIT license. See LICENSE file in the project root for full license information.
*/

using System;

public class MonoPInvokeCallbackAttribute : System.Attribute
{
private Type type;
public MonoPInvokeCallbackAttribute(Type t) { type = t; }
}

namespace DotNetty.Transport.Libuv.Native
{
using System;
Expand All @@ -34,7 +42,11 @@ namespace DotNetty.Transport.Libuv.Native

sealed unsafe class Async : NativeHandle
{
static readonly uv_work_cb WorkCallback = h => OnWorkCallback(h);
[MonoPInvokeCallback(typeof(uv_work_cb))]
static void WorkCallback(IntPtr h)
{
OnWorkCallback(h);
}

readonly Action<object> _callback;
readonly object _state;
Expand Down
7 changes: 6 additions & 1 deletion src/DotNetty.Transport.Libuv/Native/ConnectRequest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,12 @@ namespace DotNetty.Transport.Libuv.Native

abstract class ConnectRequest : NativeRequest
{
protected static readonly uv_watcher_cb WatcherCallback = (h, s) => OnWatcherCallback(h, s);
[MonoPInvokeCallback(typeof(uv_watcher_cb))]
protected static void WatcherCallback(IntPtr h, int s)
{
OnWatcherCallback(h, s);
}


OperationException _error;

Expand Down
7 changes: 5 additions & 2 deletions src/DotNetty.Transport.Libuv/Native/Loop.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,11 @@ namespace DotNetty.Transport.Libuv.Native
sealed unsafe class Loop : IDisposable
{
private static readonly IInternalLogger Logger = InternalLoggerFactory.GetInstance<Loop>();
private static readonly uv_walk_cb WalkCallback = (h, s) => OnWalkCallback(h, s);

[MonoPInvokeCallback(typeof(uv_walk_cb))]
private static void WalkCallback(IntPtr h, IntPtr s)
{
OnWalkCallback(h, s);
}
private IntPtr _handle;

public Loop()
Expand Down
6 changes: 5 additions & 1 deletion src/DotNetty.Transport.Libuv/Native/NativeHandle.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,11 @@ namespace DotNetty.Transport.Libuv.Native
public abstract unsafe class NativeHandle : IDisposable
{
protected static readonly IInternalLogger Logger = InternalLoggerFactory.GetInstance<NativeHandle>();
private static readonly uv_close_cb CloseCallback = h => OnCloseHandle(h);
[MonoPInvokeCallback(typeof(uv_close_cb))]
private static void CloseCallback(IntPtr h)
{
OnCloseHandle(h);
}
internal readonly uv_handle_type HandleType;
internal IntPtr Handle;

Expand Down
18 changes: 15 additions & 3 deletions src/DotNetty.Transport.Libuv/Native/Pipe.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,16 @@ namespace DotNetty.Transport.Libuv.Native
/// </summary>
sealed unsafe class Pipe : PipeHandle
{
static readonly uv_alloc_cb AllocateCallback = OnAllocateCallback;
static readonly uv_read_cb ReadCallback = OnReadCallback;
[MonoPInvokeCallback(typeof(uv_alloc_cb))]
private static void AllocateCallback(IntPtr h, IntPtr s, out uv_buf_t b)
{
OnAllocateCallback(h, s, out b);
}
[MonoPInvokeCallback(typeof(uv_read_cb))]
private static void ReadCallback(IntPtr h, IntPtr s, ref uv_buf_t b)
{
OnReadCallback(h, s, ref b);
}

readonly Scratch _scratch;

Expand Down Expand Up @@ -170,7 +178,11 @@ public void Dispose()

sealed class Ping : NativeRequest
{
internal static readonly uv_watcher_cb WriteCallback = (h, s) => OnWriteCallback(h, s);
[MonoPInvokeCallback(typeof(uv_watcher_cb))]
internal static void WriteCallback(IntPtr h, int s)
{
OnWriteCallback(h, s);
}
static readonly byte[] PingBuf = TextEncodings.UTF8NoBOM.GetBytes("PING");

readonly NativeHandle _sentHandle;
Expand Down
6 changes: 5 additions & 1 deletion src/DotNetty.Transport.Libuv/Native/PipeListener.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,11 @@ namespace DotNetty.Transport.Libuv.Native
sealed class PipeListener : PipeHandle
{
private const int DefaultPipeBacklog = 128;
private static readonly uv_watcher_cb ConnectionCallback = (h, s) => OnConnectionCallback(h, s);
[MonoPInvokeCallback(typeof(uv_watcher_cb))]
private static void ConnectionCallback(IntPtr h, int s)
{
OnConnectionCallback(h, s);
}

private readonly Action<Pipe, int> _onReadAction;
private readonly List<Pipe> _pipes;
Expand Down
12 changes: 10 additions & 2 deletions src/DotNetty.Transport.Libuv/Native/Tcp.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,16 @@ namespace DotNetty.Transport.Libuv.Native

public sealed class Tcp : TcpHandle
{
static readonly uv_alloc_cb AllocateCallback = OnAllocateCallback;
static readonly uv_read_cb ReadCallback = OnReadCallback;
[MonoPInvokeCallback(typeof(uv_alloc_cb))]
private static void AllocateCallback(IntPtr h, IntPtr s, out uv_buf_t b)
{
OnAllocateCallback(h, s, out b);
}
[MonoPInvokeCallback(typeof(uv_read_cb))]
private static void ReadCallback(IntPtr h, IntPtr s, ref uv_buf_t b)
{
OnReadCallback(h, s, ref b);
}

readonly ReadOperation _pendingRead;
INativeUnsafe _nativeUnsafe;
Expand Down
7 changes: 5 additions & 2 deletions src/DotNetty.Transport.Libuv/Native/TcpListener.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,11 @@ namespace DotNetty.Transport.Libuv.Native

sealed class TcpListener : TcpHandle
{
static readonly uv_watcher_cb ConnectionCallback = (h, s) => OnConnectionCallback(h, s);

[MonoPInvokeCallback(typeof(uv_watcher_cb))]
static void ConnectionCallback(IntPtr h, int s)
{
OnConnectionCallback(h, s);
}
IServerNativeUnsafe _nativeUnsafe;

public TcpListener(Loop loop, uint flags) : base(loop, flags)
Expand Down
6 changes: 5 additions & 1 deletion src/DotNetty.Transport.Libuv/Native/Timer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,11 @@ namespace DotNetty.Transport.Libuv.Native

sealed class Timer : NativeHandle
{
static readonly uv_work_cb WorkCallback = h => OnWorkCallback(h);
[MonoPInvokeCallback(typeof(uv_work_cb))]
static void WorkCallback(IntPtr h)
{
OnWorkCallback(h);
}

readonly Action<object> _callback;
readonly object _state;
Expand Down
6 changes: 5 additions & 1 deletion src/DotNetty.Transport.Libuv/Native/WriteRequest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,11 @@ namespace DotNetty.Transport.Libuv.Native
sealed class WriteRequest : NativeRequest, ChannelOutboundBuffer.IMessageProcessor
{
private static readonly int BufferSize;
private static readonly uv_watcher_cb WriteCallback = (h, s) => OnWriteCallback(h, s);
[MonoPInvokeCallback(typeof(uv_watcher_cb))]
internal static void WriteCallback(IntPtr h, int s)
{
OnWriteCallback(h, s);
}

private const int MaximumBytes = int.MaxValue;
private const int MaximumLimit = 64;
Expand Down

0 comments on commit a68170c

Please sign in to comment.