/// <summary> /// Polls for an Rpc request from a client /// </summary> /// <param name="blocking">True to block waiting for a request</param> /// <param name="timeout">Timeout to wait for if blocking</param> /// <param name="callInfo">The info for the call request</param> /// <returns>True if an Rpc call has been requested, otherwise false</returns> public static bool PollRpc(bool blocking, TimeSpan timeout, out RpcCallInfo callInfo) { #if CORE Func <RpcCallInfo?> func = () => { RpcCallInfo info; bool success = PollRpc(true, out info); if (success) { return(info); } return(null); }; var task = Task.Run(func); var completed = task.Wait(timeout); if (completed) { if (task.Result.HasValue) { callInfo = task.Result.Value; return(true); } } callInfo = new RpcCallInfo(); return(false); #else return(RpcServer.Instance.PollRpc(blocking, timeout, out callInfo)); #endif }
/// <summary> /// Polls for an Rpc request from a client /// </summary> /// <param name="blocking">True to block waiting for a request</param> /// <param name="timeout">Timeout to wait for if blocking</param> /// <param name="callInfo">The info for the call request</param> /// <returns>True if an Rpc call has been requested, otherwise false</returns> public static bool PollRpc(bool blocking, TimeSpan timeout, out RpcCallInfo callInfo) { #if CORE return(CoreMethods.PollRpc(blocking, timeout, out callInfo)); #else return(RpcServer.Instance.PollRpc(blocking, timeout, out callInfo)); #endif }
public async Task <RpcCallInfo?> PollRpcAsync(CancellationToken token) { IDisposable monitor = null; try { monitor = await m_lockObject.LockAsync(token).ConfigureAwait(false); while (m_pollQueue.Count == 0) { if (m_terminating) { return(null); } await m_pollCond.WaitAsync(token).ConfigureAwait(false); if (token.IsCancellationRequested) { return(null); } if (m_terminating) { return(null); } } var item = m_pollQueue.Dequeue(); uint callUid; if (item.ConnId != 0xffff) { callUid = (item.ConnId << 16) | item.Msg.SeqNumUid; } else { callUid = item.Msg.SeqNumUid; } if (!item.Msg.Val.IsRpc()) { return(null); } RpcCallInfo callInfo = new RpcCallInfo(item.Msg.Id, callUid, item.Name, item.Msg.Val.GetRpc()); m_responseMap.Add(new ImmutablePair <uint, uint>(item.Msg.Id, callUid), item.SendResponse); return(callInfo); } catch (OperationCanceledException) { // Operation canceled. Return null. return(null); } finally { monitor?.Dispose(); } }
public bool PollRpc(bool blocking, TimeSpan timeout, out RpcCallInfo callInfo) { IDisposable monitor = null; try { monitor = m_lockObject.Lock(); while (m_pollQueue.Count == 0) { if (!blocking || m_terminating) { callInfo = default(RpcCallInfo); return(false); } CancellationTokenSource source = new CancellationTokenSource(); var task = m_pollCond.WaitAsync(source.Token); bool success = task.Wait(timeout); if (!success || m_terminating) { source.Cancel(); callInfo = default(RpcCallInfo); return(false); } } var item = m_pollQueue.Dequeue(); uint callUid; if (item.ConnId != 0xffff) { callUid = (item.ConnId << 16) | item.Msg.SeqNumUid; } else { callUid = item.Msg.SeqNumUid; } if (!item.Msg.Val.IsRpc()) { callInfo = default(RpcCallInfo); return(false); } callInfo = new RpcCallInfo(item.Msg.Id, callUid, item.Name, item.Msg.Val.GetRpc()); m_responseMap.Add(new ImmutablePair <uint, uint>(item.Msg.Id, callUid), item.SendResponse); return(true); } finally { monitor?.Dispose(); } }
/// <summary> /// Polls for an Rpc request from a client /// </summary> /// <param name="blocking">True to block waiting for a request</param> /// <param name="callInfo">The info for the call request</param> /// <returns>True if an Rpc call has been requested, otherwise false</returns> public static bool PollRpc(bool blocking, out RpcCallInfo callInfo) { #if CORE NtRpcCallInfo nativeInfo; int retVal = Interop.NT_PollRpc(blocking ? 1 : 0, out nativeInfo); if (retVal == 0) { callInfo = new RpcCallInfo(); return(false); } callInfo = nativeInfo.ToManaged(); return(retVal != 0); #else return(RpcServer.Instance.PollRpc(blocking, out callInfo)); #endif }
public bool PollRpc(bool blocking, out RpcCallInfo callInfo) { return(PollRpc(blocking, Timeout.InfiniteTimeSpan, out callInfo)); }