Change Exception to UvException where possible (#1833)
This commit is contained in:
parent
41f1922502
commit
9ab09dbe48
|
|
@ -15,11 +15,11 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal
|
||||||
|
|
||||||
private Action _callback;
|
private Action _callback;
|
||||||
|
|
||||||
private Exception _exception;
|
private UvException _exception;
|
||||||
|
|
||||||
private int _status;
|
private int _status;
|
||||||
|
|
||||||
public static readonly Action<TRequest, int, Exception, object> Callback = (req, status, error, state) =>
|
public static readonly Action<TRequest, int, UvException, object> Callback = (req, status, error, state) =>
|
||||||
{
|
{
|
||||||
var awaitable = (LibuvAwaitable<TRequest>)state;
|
var awaitable = (LibuvAwaitable<TRequest>)state;
|
||||||
|
|
||||||
|
|
@ -71,9 +71,9 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal
|
||||||
public struct UvWriteResult
|
public struct UvWriteResult
|
||||||
{
|
{
|
||||||
public int Status { get; }
|
public int Status { get; }
|
||||||
public Exception Error { get; }
|
public UvException Error { get; }
|
||||||
|
|
||||||
public UvWriteResult(int status, Exception error)
|
public UvWriteResult(int status, UvException error)
|
||||||
{
|
{
|
||||||
Status = status;
|
Status = status;
|
||||||
Error = error;
|
Error = error;
|
||||||
|
|
|
||||||
|
|
@ -93,7 +93,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void ConnectionCallback(UvStreamHandle stream, int status, Exception error, object state)
|
private static void ConnectionCallback(UvStreamHandle stream, int status, UvException error, object state)
|
||||||
{
|
{
|
||||||
var listener = (Listener)state;
|
var listener = (Listener)state;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -73,7 +73,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal
|
||||||
(pipe, status, error, state) => ((ListenerPrimary)state).OnListenPipe(pipe, status, error), this);
|
(pipe, status, error, state) => ((ListenerPrimary)state).OnListenPipe(pipe, status, error), this);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void OnListenPipe(UvStreamHandle pipe, int status, Exception error)
|
private void OnListenPipe(UvStreamHandle pipe, int status, UvException error)
|
||||||
{
|
{
|
||||||
if (status < 0)
|
if (status < 0)
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -78,13 +78,13 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void ConnectCallback(UvConnectRequest connect, int status, Exception error, TaskCompletionSource<int> tcs)
|
private static void ConnectCallback(UvConnectRequest connect, int status, UvException error, TaskCompletionSource<int> tcs)
|
||||||
{
|
{
|
||||||
var listener = (ListenerSecondary)tcs.Task.AsyncState;
|
var listener = (ListenerSecondary)tcs.Task.AsyncState;
|
||||||
listener.ConnectedCallback(connect, status, error, tcs);
|
listener.ConnectedCallback(connect, status, error, tcs);
|
||||||
}
|
}
|
||||||
|
|
||||||
private async void ConnectedCallback(UvConnectRequest connect, int status, Exception error, TaskCompletionSource<int> tcs)
|
private async void ConnectedCallback(UvConnectRequest connect, int status, UvException error, TaskCompletionSource<int> tcs)
|
||||||
{
|
{
|
||||||
connect.Dispose();
|
connect.Dispose();
|
||||||
if (error != null)
|
if (error != null)
|
||||||
|
|
@ -133,8 +133,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal
|
||||||
{
|
{
|
||||||
if (status != LibuvConstants.EOF)
|
if (status != LibuvConstants.EOF)
|
||||||
{
|
{
|
||||||
Exception ex;
|
Thread.Loop.Libuv.Check(status, out var ex);
|
||||||
Thread.Loop.Libuv.Check(status, out ex);
|
|
||||||
Log.LogError(0, ex, "DispatchPipe.ReadStart");
|
Log.LogError(0, ex, "DispatchPipe.ReadStart");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -82,7 +82,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal.Networkin
|
||||||
throw GetError(statusCode);
|
throw GetError(statusCode);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Check(int statusCode, out Exception error)
|
public void Check(int statusCode, out UvException error)
|
||||||
{
|
{
|
||||||
// Note: method is explicitly small so the success case is easily inlined
|
// Note: method is explicitly small so the success case is easily inlined
|
||||||
error = statusCode < 0 ? GetError(statusCode) : null;
|
error = statusCode < 0 ? GetError(statusCode) : null;
|
||||||
|
|
@ -345,14 +345,14 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal.Networkin
|
||||||
|
|
||||||
protected delegate int uv_ip4_addr_func(string ip, int port, out SockAddr addr);
|
protected delegate int uv_ip4_addr_func(string ip, int port, out SockAddr addr);
|
||||||
protected uv_ip4_addr_func _uv_ip4_addr;
|
protected uv_ip4_addr_func _uv_ip4_addr;
|
||||||
public void ip4_addr(string ip, int port, out SockAddr addr, out Exception error)
|
public void ip4_addr(string ip, int port, out SockAddr addr, out UvException error)
|
||||||
{
|
{
|
||||||
Check(_uv_ip4_addr(ip, port, out addr), out error);
|
Check(_uv_ip4_addr(ip, port, out addr), out error);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected delegate int uv_ip6_addr_func(string ip, int port, out SockAddr addr);
|
protected delegate int uv_ip6_addr_func(string ip, int port, out SockAddr addr);
|
||||||
protected uv_ip6_addr_func _uv_ip6_addr;
|
protected uv_ip6_addr_func _uv_ip6_addr;
|
||||||
public void ip6_addr(string ip, int port, out SockAddr addr, out Exception error)
|
public void ip6_addr(string ip, int port, out SockAddr addr, out UvException error)
|
||||||
{
|
{
|
||||||
Check(_uv_ip6_addr(ip, port, out addr), out error);
|
Check(_uv_ip6_addr(ip, port, out addr), out error);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -13,7 +13,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal.Networkin
|
||||||
{
|
{
|
||||||
private readonly static LibuvFunctions.uv_connect_cb _uv_connect_cb = (req, status) => UvConnectCb(req, status);
|
private readonly static LibuvFunctions.uv_connect_cb _uv_connect_cb = (req, status) => UvConnectCb(req, status);
|
||||||
|
|
||||||
private Action<UvConnectRequest, int, Exception, object> _callback;
|
private Action<UvConnectRequest, int, UvException, object> _callback;
|
||||||
private object _state;
|
private object _state;
|
||||||
|
|
||||||
public UvConnectRequest(ILibuvTrace logger) : base (logger)
|
public UvConnectRequest(ILibuvTrace logger) : base (logger)
|
||||||
|
|
@ -39,7 +39,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal.Networkin
|
||||||
public void Connect(
|
public void Connect(
|
||||||
UvPipeHandle pipe,
|
UvPipeHandle pipe,
|
||||||
string name,
|
string name,
|
||||||
Action<UvConnectRequest, int, Exception, object> callback,
|
Action<UvConnectRequest, int, UvException, object> callback,
|
||||||
object state)
|
object state)
|
||||||
{
|
{
|
||||||
_callback = callback;
|
_callback = callback;
|
||||||
|
|
@ -58,7 +58,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal.Networkin
|
||||||
var state = req._state;
|
var state = req._state;
|
||||||
req._state = null;
|
req._state = null;
|
||||||
|
|
||||||
Exception error = null;
|
UvException error = null;
|
||||||
if (status < 0)
|
if (status < 0)
|
||||||
{
|
{
|
||||||
req.Libuv.Check(status, out error);
|
req.Libuv.Check(status, out error);
|
||||||
|
|
|
||||||
|
|
@ -14,7 +14,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal.Networkin
|
||||||
private readonly static LibuvFunctions.uv_alloc_cb _uv_alloc_cb = (IntPtr handle, int suggested_size, out LibuvFunctions.uv_buf_t buf) => UvAllocCb(handle, suggested_size, out buf);
|
private readonly static LibuvFunctions.uv_alloc_cb _uv_alloc_cb = (IntPtr handle, int suggested_size, out LibuvFunctions.uv_buf_t buf) => UvAllocCb(handle, suggested_size, out buf);
|
||||||
private readonly static LibuvFunctions.uv_read_cb _uv_read_cb = (IntPtr handle, int status, ref LibuvFunctions.uv_buf_t buf) => UvReadCb(handle, status, ref buf);
|
private readonly static LibuvFunctions.uv_read_cb _uv_read_cb = (IntPtr handle, int status, ref LibuvFunctions.uv_buf_t buf) => UvReadCb(handle, status, ref buf);
|
||||||
|
|
||||||
private Action<UvStreamHandle, int, Exception, object> _listenCallback;
|
private Action<UvStreamHandle, int, UvException, object> _listenCallback;
|
||||||
private object _listenState;
|
private object _listenState;
|
||||||
private GCHandle _listenVitality;
|
private GCHandle _listenVitality;
|
||||||
|
|
||||||
|
|
@ -40,7 +40,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal.Networkin
|
||||||
return base.ReleaseHandle();
|
return base.ReleaseHandle();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Listen(int backlog, Action<UvStreamHandle, int, Exception, object> callback, object state)
|
public void Listen(int backlog, Action<UvStreamHandle, int, UvException, object> callback, object state)
|
||||||
{
|
{
|
||||||
if (_listenVitality.IsAllocated)
|
if (_listenVitality.IsAllocated)
|
||||||
{
|
{
|
||||||
|
|
@ -123,8 +123,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal.Networkin
|
||||||
{
|
{
|
||||||
var stream = FromIntPtr<UvStreamHandle>(handle);
|
var stream = FromIntPtr<UvStreamHandle>(handle);
|
||||||
|
|
||||||
Exception error;
|
stream.Libuv.Check(status, out var error);
|
||||||
stream.Libuv.Check(status, out error);
|
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -33,13 +33,11 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal.Networkin
|
||||||
SockAddr addr;
|
SockAddr addr;
|
||||||
var addressText = endPoint.Address.ToString();
|
var addressText = endPoint.Address.ToString();
|
||||||
|
|
||||||
Exception error1;
|
_uv.ip4_addr(addressText, endPoint.Port, out addr, out var error1);
|
||||||
_uv.ip4_addr(addressText, endPoint.Port, out addr, out error1);
|
|
||||||
|
|
||||||
if (error1 != null)
|
if (error1 != null)
|
||||||
{
|
{
|
||||||
Exception error2;
|
_uv.ip6_addr(addressText, endPoint.Port, out addr, out var error2);
|
||||||
_uv.ip6_addr(addressText, endPoint.Port, out addr, out error2);
|
|
||||||
if (error2 != null)
|
if (error2 != null)
|
||||||
{
|
{
|
||||||
throw error1;
|
throw error1;
|
||||||
|
|
|
||||||
|
|
@ -19,7 +19,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal.Networkin
|
||||||
|
|
||||||
private IntPtr _bufs;
|
private IntPtr _bufs;
|
||||||
|
|
||||||
private Action<UvWriteReq, int, Exception, object> _callback;
|
private Action<UvWriteReq, int, UvException, object> _callback;
|
||||||
private object _state;
|
private object _state;
|
||||||
private const int BUFFER_COUNT = 4;
|
private const int BUFFER_COUNT = 4;
|
||||||
|
|
||||||
|
|
@ -64,7 +64,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal.Networkin
|
||||||
private unsafe void Write(
|
private unsafe void Write(
|
||||||
UvStreamHandle handle,
|
UvStreamHandle handle,
|
||||||
ReadableBuffer buffer,
|
ReadableBuffer buffer,
|
||||||
Action<UvWriteReq, int, Exception, object> callback,
|
Action<UvWriteReq, int, UvException, object> callback,
|
||||||
object state)
|
object state)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
|
|
@ -136,7 +136,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal.Networkin
|
||||||
private void Write(
|
private void Write(
|
||||||
UvStreamHandle handle,
|
UvStreamHandle handle,
|
||||||
ArraySegment<ArraySegment<byte>> bufs,
|
ArraySegment<ArraySegment<byte>> bufs,
|
||||||
Action<UvWriteReq, int, Exception, object> callback,
|
Action<UvWriteReq, int, UvException, object> callback,
|
||||||
object state)
|
object state)
|
||||||
{
|
{
|
||||||
WriteArraySegmentInternal(handle, bufs, sendHandle: null, callback: callback, state: state);
|
WriteArraySegmentInternal(handle, bufs, sendHandle: null, callback: callback, state: state);
|
||||||
|
|
@ -146,7 +146,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal.Networkin
|
||||||
UvStreamHandle handle,
|
UvStreamHandle handle,
|
||||||
ArraySegment<ArraySegment<byte>> bufs,
|
ArraySegment<ArraySegment<byte>> bufs,
|
||||||
UvStreamHandle sendHandle,
|
UvStreamHandle sendHandle,
|
||||||
Action<UvWriteReq, int, Exception, object> callback,
|
Action<UvWriteReq, int, UvException, object> callback,
|
||||||
object state)
|
object state)
|
||||||
{
|
{
|
||||||
WriteArraySegmentInternal(handle, bufs, sendHandle, callback, state);
|
WriteArraySegmentInternal(handle, bufs, sendHandle, callback, state);
|
||||||
|
|
@ -156,7 +156,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal.Networkin
|
||||||
UvStreamHandle handle,
|
UvStreamHandle handle,
|
||||||
ArraySegment<ArraySegment<byte>> bufs,
|
ArraySegment<ArraySegment<byte>> bufs,
|
||||||
UvStreamHandle sendHandle,
|
UvStreamHandle sendHandle,
|
||||||
Action<UvWriteReq, int, Exception, object> callback,
|
Action<UvWriteReq, int, UvException, object> callback,
|
||||||
object state)
|
object state)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
|
|
@ -237,7 +237,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal.Networkin
|
||||||
var state = req._state;
|
var state = req._state;
|
||||||
req._state = null;
|
req._state = null;
|
||||||
|
|
||||||
Exception error = null;
|
UvException error = null;
|
||||||
if (status < 0)
|
if (status < 0)
|
||||||
{
|
{
|
||||||
req.Libuv.Check(status, out error);
|
req.Libuv.Check(status, out error);
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue