Move handle creation to constructor

This commit is contained in:
Ben Adams 2015-11-04 22:44:30 +00:00
parent 5cef608e52
commit 3e7969cefe
1 changed files with 4 additions and 9 deletions

View File

@ -18,11 +18,13 @@ namespace Microsoft.AspNet.Server.Kestrel.Http
public abstract class ListenerSecondary : ListenerContext, IDisposable public abstract class ListenerSecondary : ListenerContext, IDisposable
{ {
private string _pipeName; private string _pipeName;
private IntPtr _ptr = IntPtr.Zero; private IntPtr _ptr;
private Libuv.uv_buf_t _buf; private Libuv.uv_buf_t _buf;
protected ListenerSecondary(ServiceContext serviceContext) : base(serviceContext) protected ListenerSecondary(ServiceContext serviceContext) : base(serviceContext)
{ {
_ptr = Marshal.AllocHGlobal(4);
_buf = Thread.Loop.Libuv.buf_init(_ptr, 4);
} }
UvPipeHandle DispatchPipe { get; set; } UvPipeHandle DispatchPipe { get; set; }
@ -88,9 +90,6 @@ namespace Microsoft.AspNet.Server.Kestrel.Http
try try
{ {
_ptr = Marshal.AllocHGlobal(4);
_buf = Thread.Loop.Libuv.buf_init(_ptr, 4);
DispatchPipe.ReadStart( DispatchPipe.ReadStart(
(handle, status2, state) => ((ListenerSecondary)state)._buf, (handle, status2, state) => ((ListenerSecondary)state)._buf,
(handle, status2, state) => (handle, status2, state) =>
@ -153,11 +152,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http
public void Dispose() public void Dispose()
{ {
if (_ptr != IntPtr.Zero) Marshal.FreeHGlobal(_ptr);
{
Marshal.FreeHGlobal(_ptr);
_ptr = IntPtr.Zero;
}
// Ensure the event loop is still running. // Ensure the event loop is still running.
// If the event loop isn't running and we try to wait on this Post // If the event loop isn't running and we try to wait on this Post