public static unsafe Task <bool> SendKickToUser(string frontendId, string serverType, KickMsg kick) { return(_rpcTaskFactory.StartNew(() => { bool ok = false; MemoryBuffer inMemBuf = new MemoryBuffer(); MemoryBuffer *outMemBufPtr = null; var retError = new Error(); try { var data = kick.ToByteArray(); fixed(byte *p = data) { inMemBuf.data = (IntPtr)p; inMemBuf.size = data.Length; IntPtr inMemBufPtr = new StructWrapper(inMemBuf); ok = KickInternal(frontendId, serverType, inMemBufPtr, &outMemBufPtr, ref retError); if (!ok) // error { Logger.Error($"Push failed: ({retError.code}: {retError.msg})"); return false; } var kickAns = new KickAnswer(); kickAns.MergeFrom(new CodedInputStream(outMemBufPtr->GetData())); return kickAns.Kicked; } } finally { if (outMemBufPtr != null) { FreeMemoryBufferInternal(outMemBufPtr); } } })); }
public Task SendKickToUser(string frontendId, string serverKind, KickMsg kick) { return(Task.Run(() => { var context = new CallbackContext <bool> { t = new TaskCompletionSource <bool>(), serializer = _serializer, }; var handle = GCHandle.Alloc(context, GCHandleType.Normal); unsafe { var data = kick.ToByteArray(); fixed(byte *p = data) { IntPtr kickBuffer = PitayaCluster.pitaya_buffer_new((IntPtr)p, data.Length); PitayaCluster.pitaya_send_kick(_pitaya, frontendId, serverKind, kickBuffer, kickCallback, GCHandle.ToIntPtr(handle)); } } return context.t.Task; })); }