aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/csharp/GrpcCore/Internal
diff options
context:
space:
mode:
authorGravatar Jan Tattermusch <jtattermusch@google.com>2015-02-12 12:45:52 -0800
committerGravatar Jan Tattermusch <jtattermusch@google.com>2015-02-12 14:18:03 -0800
commit61f93b2b0643edb1b460aba080e4ea1d2b5cfea3 (patch)
tree477305bf87f76509ae0ca0e7b5cb4c5f35ccb796 /src/csharp/GrpcCore/Internal
parentc9562b6c4bc2290de7611ec0d998005f4f98a34e (diff)
Fixed Timespec to work on Windows, fixes in ServerSafeHandle
Diffstat (limited to 'src/csharp/GrpcCore/Internal')
-rw-r--r--src/csharp/GrpcCore/Internal/ServerSafeHandle.cs34
-rw-r--r--src/csharp/GrpcCore/Internal/Timespec.cs15
2 files changed, 25 insertions, 24 deletions
diff --git a/src/csharp/GrpcCore/Internal/ServerSafeHandle.cs b/src/csharp/GrpcCore/Internal/ServerSafeHandle.cs
index 82587c88b7..391a1acd01 100644
--- a/src/csharp/GrpcCore/Internal/ServerSafeHandle.cs
+++ b/src/csharp/GrpcCore/Internal/ServerSafeHandle.cs
@@ -10,31 +10,31 @@ namespace Google.GRPC.Core.Internal
/// </summary>
internal sealed class ServerSafeHandle : SafeHandleZeroIsInvalid
{
- [DllImport("grpc_csharp_ext.dll", EntryPoint = "grpc_server_request_call_old")]
- static extern GRPCCallError grpc_server_request_call_old_CALLBACK(ServerSafeHandle server, [MarshalAs(UnmanagedType.FunctionPtr)] EventCallbackDelegate callback);
+ [DllImport("grpc_csharp_ext.dll", EntryPoint = "grpcsharp_server_request_call_old")]
+ static extern GRPCCallError grpcsharp_server_request_call_old_CALLBACK(ServerSafeHandle server, [MarshalAs(UnmanagedType.FunctionPtr)] EventCallbackDelegate callback);
[DllImport("grpc_csharp_ext.dll")]
- static extern ServerSafeHandle grpc_server_create(CompletionQueueSafeHandle cq, IntPtr args);
+ static extern ServerSafeHandle grpcsharp_server_create(CompletionQueueSafeHandle cq, IntPtr args);
// TODO: check int representation size
[DllImport("grpc_csharp_ext.dll")]
- static extern int grpc_server_add_http2_port(ServerSafeHandle server, string addr);
+ static extern int grpcsharp_server_add_http2_port(ServerSafeHandle server, string addr);
// TODO: check int representation size
[DllImport("grpc_csharp_ext.dll")]
- static extern int grpc_server_add_secure_http2_port(ServerSafeHandle server, string addr);
+ static extern int grpcsharp_server_add_secure_http2_port(ServerSafeHandle server, string addr);
[DllImport("grpc_csharp_ext.dll")]
- static extern void grpc_server_start(ServerSafeHandle server);
+ static extern void grpcsharp_server_start(ServerSafeHandle server);
[DllImport("grpc_csharp_ext.dll")]
- static extern void grpc_server_shutdown(ServerSafeHandle server);
+ static extern void grpcsharp_server_shutdown(ServerSafeHandle server);
- [DllImport("grpc_csharp_ext.dll", EntryPoint = "grpc_server_shutdown_and_notify")]
- static extern void grpc_server_shutdown_and_notify_CALLBACK(ServerSafeHandle server, [MarshalAs(UnmanagedType.FunctionPtr)] EventCallbackDelegate callback);
+ [DllImport("grpc_csharp_ext.dll", EntryPoint = "grpcsharp_server_shutdown_and_notify")]
+ static extern void grpcsharp_server_shutdown_and_notify_CALLBACK(ServerSafeHandle server, [MarshalAs(UnmanagedType.FunctionPtr)] EventCallbackDelegate callback);
[DllImport("grpc_csharp_ext.dll")]
- static extern void grpc_server_destroy(IntPtr server);
+ static extern void grpcsharp_server_destroy(IntPtr server);
private ServerSafeHandle()
{
@@ -43,38 +43,38 @@ namespace Google.GRPC.Core.Internal
public static ServerSafeHandle NewServer(CompletionQueueSafeHandle cq, IntPtr args)
{
// TODO: also grpc_secure_server_create...
- return grpc_server_create(cq, args);
+ return grpcsharp_server_create(cq, args);
}
public int AddPort(string addr)
{
// TODO: also grpc_server_add_secure_http2_port...
- return grpc_server_add_http2_port(this, addr);
+ return grpcsharp_server_add_http2_port(this, addr);
}
public void Start()
{
- grpc_server_start(this);
+ grpcsharp_server_start(this);
}
public void Shutdown()
{
- grpc_server_shutdown(this);
+ grpcsharp_server_shutdown(this);
}
public void ShutdownAndNotify(EventCallbackDelegate callback)
{
- grpc_server_shutdown_and_notify_CALLBACK(this, callback);
+ grpcsharp_server_shutdown_and_notify_CALLBACK(this, callback);
}
public GRPCCallError RequestCall(EventCallbackDelegate callback)
{
- return grpc_server_request_call_old_CALLBACK(this, callback);
+ return grpcsharp_server_request_call_old_CALLBACK(this, callback);
}
protected override bool ReleaseHandle()
{
- grpc_server_destroy(handle);
+ grpcsharp_server_destroy(handle);
return true;
}
}
diff --git a/src/csharp/GrpcCore/Internal/Timespec.cs b/src/csharp/GrpcCore/Internal/Timespec.cs
index c069829d8c..c45926707f 100644
--- a/src/csharp/GrpcCore/Internal/Timespec.cs
+++ b/src/csharp/GrpcCore/Internal/Timespec.cs
@@ -22,10 +22,11 @@ namespace Google.GRPC.Core.Internal
[DllImport("grpc_csharp_ext.dll")]
static extern int gprsharp_sizeof_timespec();
- // TODO: this only works on 64bit linux, can we autoselect the right size of ints?
- // perhaps using IntPtr would work.
- public System.Int64 tv_sec;
- public System.Int64 tv_nsec;
+ // TODO: revisit this.
+ // NOTE: on linux 64bit sizeof(gpr_timespec) = 16, on windows 32bit sizeof(gpr_timespec) = 8
+ // so IntPtr seems to have the right size to work on both.
+ public System.IntPtr tv_sec;
+ public System.IntPtr tv_nsec;
/// <summary>
/// Timespec a long time in the future.
@@ -67,12 +68,12 @@ namespace Google.GRPC.Core.Internal
}
public Timespec Add(TimeSpan timeSpan) {
- long nanos = tv_nsec + (timeSpan.Ticks % TimeSpan.TicksPerSecond) * nanosPerTick;
+ long nanos = tv_nsec.ToInt64() + (timeSpan.Ticks % TimeSpan.TicksPerSecond) * nanosPerTick;
long overflow_sec = (nanos > nanosPerSecond) ? 1 : 0;
Timespec result;
- result.tv_nsec = nanos % nanosPerSecond;
- result.tv_sec = tv_sec + (timeSpan.Ticks / TimeSpan.TicksPerSecond) + overflow_sec;
+ result.tv_nsec = new IntPtr(nanos % nanosPerSecond);
+ result.tv_sec = new IntPtr(tv_sec.ToInt64() + (timeSpan.Ticks / TimeSpan.TicksPerSecond) + overflow_sec);
return result;
}
}