allow return value from native callbacks

pull/18327/head
Jan Tattermusch 6 years ago
parent 5a65985bf8
commit 83b6a98872
  1. 13
      src/csharp/Grpc.Core/Internal/NativeCallbackDispatcher.cs
  2. 3
      src/csharp/Grpc.Core/Internal/NativeMetadataCredentialsPlugin.cs
  3. 2
      src/csharp/ext/grpc_csharp_ext.c

@ -27,9 +27,9 @@ using Grpc.Core.Logging;
namespace Grpc.Core.Internal
{
internal delegate void UniversalNativeCallback(IntPtr arg0, IntPtr arg1, IntPtr arg2, IntPtr arg3, IntPtr arg4, IntPtr arg5);
internal delegate int UniversalNativeCallback(IntPtr arg0, IntPtr arg1, IntPtr arg2, IntPtr arg3, IntPtr arg4, IntPtr arg5);
internal delegate void NativeCallbackDispatcherCallback(IntPtr tag, IntPtr arg0, IntPtr arg1, IntPtr arg2, IntPtr arg3, IntPtr arg4, IntPtr arg5);
internal delegate int NativeCallbackDispatcherCallback(IntPtr tag, IntPtr arg0, IntPtr arg1, IntPtr arg2, IntPtr arg3, IntPtr arg4, IntPtr arg5);
internal class NativeCallbackDispatcher
{
@ -81,7 +81,7 @@ namespace Grpc.Core.Internal
}
[MonoPInvokeCallback(typeof(NativeCallbackDispatcherCallback))]
private static void HandleDispatcherCallback(IntPtr tag, IntPtr arg0, IntPtr arg1, IntPtr arg2, IntPtr arg3, IntPtr arg4, IntPtr arg5)
private static int HandleDispatcherCallback(IntPtr tag, IntPtr arg0, IntPtr arg1, IntPtr arg2, IntPtr arg3, IntPtr arg4, IntPtr arg5)
{
try
{
@ -89,13 +89,15 @@ namespace Grpc.Core.Internal
if (!TryGetCallback(tag, out callback))
{
Logger.Error("No native callback handler registered for tag {0}.", tag);
return 0;
}
callback(arg0, arg1, arg2, arg3, arg4, arg5);
return callback(arg0, arg1, arg2, arg3, arg4, arg5);
}
catch (Exception e)
{
// eat the exception, we must not throw when inside callback from native code.
Logger.Error(e, "Caught exception inside callback from native callback.");
return 0;
}
}
}
@ -103,9 +105,8 @@ namespace Grpc.Core.Internal
internal class NativeCallbackRegistration : IDisposable
{
readonly IntPtr tag;
readonly Action disposeAction;
public NativeCallbackRegistration(IntPtr tag, Action disposeAction)
public NativeCallbackRegistration(IntPtr tag)
{
this.tag = tag;
}

@ -46,9 +46,10 @@ namespace Grpc.Core.Internal
get { return credentials; }
}
private void HandleUniversalCallback(IntPtr arg0, IntPtr arg1, IntPtr arg2, IntPtr arg3, IntPtr arg4, IntPtr arg5)
private int HandleUniversalCallback(IntPtr arg0, IntPtr arg1, IntPtr arg2, IntPtr arg3, IntPtr arg4, IntPtr arg5)
{
NativeMetadataInterceptorHandler(arg0, arg1, arg2, arg3, arg4 != IntPtr.Zero);
return 0;
}
private void NativeMetadataInterceptorHandler(IntPtr serviceUrlPtr, IntPtr methodNamePtr, IntPtr callbackPtr, IntPtr userDataPtr, bool isDestroy)

@ -1012,7 +1012,7 @@ grpcsharp_composite_call_credentials_create(grpc_call_credentials* creds1,
/* Native callback dispatcher */
typedef void(GPR_CALLTYPE* grpcsharp_native_callback_dispatcher_func)(
typedef int(GPR_CALLTYPE* grpcsharp_native_callback_dispatcher_func)(
void* tag, void* arg0, void* arg1, void* arg2, void* arg3, void* arg4, void *arg5);
static grpcsharp_native_callback_dispatcher_func native_callback_dispatcher = NULL;

Loading…
Cancel
Save