LibUv Networking (#65)
This commit is contained in:
parent
ec6629fbe9
commit
5e2be2d7b6
69 changed files with 5612 additions and 586 deletions
54
Projects/Server/LibUv/Internal/UvLoopHandle.cs
Normal file
54
Projects/Server/LibUv/Internal/UvLoopHandle.cs
Normal file
|
|
@ -0,0 +1,54 @@
|
|||
// Copyright (c) .NET Foundation. All rights reserved.
|
||||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
||||
|
||||
using System;
|
||||
using System.Threading;
|
||||
|
||||
namespace Libuv.Internal
|
||||
{
|
||||
public class UvLoopHandle : UvMemory
|
||||
{
|
||||
public UvLoopHandle(ILibuvTrace logger) : base(logger)
|
||||
{
|
||||
}
|
||||
|
||||
public void Init(LibuvFunctions uv)
|
||||
{
|
||||
CreateMemory(
|
||||
uv,
|
||||
Thread.CurrentThread.ManagedThreadId,
|
||||
uv.loop_size());
|
||||
|
||||
_uv.loop_init(this);
|
||||
}
|
||||
|
||||
public void Run(int mode = 0)
|
||||
{
|
||||
_uv.run(this, mode);
|
||||
}
|
||||
|
||||
public void Stop()
|
||||
{
|
||||
_uv.stop(this);
|
||||
}
|
||||
|
||||
public long Now() => _uv.now(this);
|
||||
|
||||
protected override unsafe bool ReleaseHandle()
|
||||
{
|
||||
var memory = handle;
|
||||
if (memory != IntPtr.Zero)
|
||||
{
|
||||
// loop_close clears the gcHandlePtr
|
||||
var gcHandlePtr = *(IntPtr*)memory;
|
||||
|
||||
_uv.loop_close(this);
|
||||
handle = IntPtr.Zero;
|
||||
|
||||
DestroyMemory(memory, gcHandlePtr);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue