コード例 #1
0
        /// <summary>
        /// Waits for response PSObject to be set and then returns it. Returns null
        /// if wait was aborted.
        /// </summary>
        /// <param name="callId">
        /// </param>
        /// <param name="defaultValue">
        /// default return value (in case the remote end did not send response).
        /// </param>
        internal T GetResponse(long callId, T defaultValue)
        {
            // Note: Only GetResponse removes records.

            AsyncObject <T> responseAsyncObject = null;

            lock (_responseAsyncObjects)
            {
                responseAsyncObject = GetResponseAsyncObject(callId);
            }

            // This will block until Value is set on this AsyncObject.
            T remoteHostResponse = responseAsyncObject.Value;

            // Remove table entry to conserve memory: this table could be alive for a long time.
            lock (_responseAsyncObjects)
            {
                _responseAsyncObjects.Remove(callId);
            }

            // return caller specified value in case there is no response
            // from remote end.
            if (remoteHostResponse == null)
            {
                return(defaultValue);
            }

            return(remoteHostResponse);
        }
コード例 #2
0
        /// <summary>
        /// Get response async object.
        /// </summary>
        private AsyncObject <T> GetResponseAsyncObject(long callId)
        {
            AsyncObject <T> responseAsyncObject = null;

            Dbg.Assert(_responseAsyncObjects.ContainsKey(callId), "Expected _responseAsyncObjects.ContainsKey(callId)");
            responseAsyncObject = _responseAsyncObjects[callId];
            Dbg.Assert(responseAsyncObject != null, "Expected responseAsyncObject != null");
            return(responseAsyncObject);
        }
コード例 #3
0
        internal long CreateNewCallId()
        {
            long            key         = Interlocked.Increment(ref this._nextCallId);
            AsyncObject <T> asyncObject = new AsyncObject <T>();

            lock (this._responseAsyncObjects)
                this._responseAsyncObjects[key] = asyncObject;
            return(key);
        }
コード例 #4
0
ファイル: DispatchTable!1.cs プロジェクト: modulexcite/pash-1
        internal long CreateNewCallId()
        {
            long            num  = Interlocked.Increment(ref this._nextCallId);
            AsyncObject <T> obj2 = new AsyncObject <T>();

            lock (this._responseAsyncObjects)
            {
                this._responseAsyncObjects[num] = obj2;
            }
            return(num);
        }
コード例 #5
0
        internal T GetResponse(long callId, T defaultValue)
        {
            AsyncObject <T> asyncObject = (AsyncObject <T>)null;

            lock (this._responseAsyncObjects)
                asyncObject = this.GetResponseAsyncObject(callId);
            T obj = asyncObject.Value;

            lock (this._responseAsyncObjects)
                this._responseAsyncObjects.Remove(callId);
            return((object)obj == null ? defaultValue : obj);
        }
コード例 #6
0
        /// <summary>
        /// Abort call.
        /// </summary>
        private void AbortCall(long callId)
        {
            // The response-async-object might not exist if the call was already aborted.
            if (!_responseAsyncObjects.ContainsKey(callId))
            {
                return;
            }

            // Releases blocked thread by setting null as return value, which should be detected by caller of GetResponse.
            AsyncObject <T> responseAsyncObject = GetResponseAsyncObject(callId);

            responseAsyncObject.Value = null;
        }
コード例 #7
0
        /// <summary>
        /// Create new call id.
        /// </summary>
        internal long CreateNewCallId()
        {
            // Note: Only CreateNewCallId adds new records.

            long            callId = Interlocked.Increment(ref _nextCallId);
            AsyncObject <T> responseAsyncObject = new AsyncObject <T>();

            lock (_responseAsyncObjects)
            {
                _responseAsyncObjects[callId] = responseAsyncObject;
            }

            return(callId);
        }
コード例 #8
0
        /// <summary>
        /// Set response.
        /// </summary>
        internal void SetResponse(long callId, T remoteHostResponse)
        {
            Dbg.Assert(remoteHostResponse != null, "Expected remoteHostResponse != null");
            lock (_responseAsyncObjects)
            {
                // The response-async-object might not exist if the call was aborted by Ctrl-C or if
                // the call had a void return and no return value was expected.
                if (!_responseAsyncObjects.ContainsKey(callId))
                {
                    return;
                }

                // Unblock the AsyncObject by setting its value.
                AsyncObject <T> responseAsyncObject = GetResponseAsyncObject(callId);
                responseAsyncObject.Value = remoteHostResponse;
            }
        }
コード例 #9
0
ファイル: DispatchTable!1.cs プロジェクト: modulexcite/pash-1
        internal T GetResponse(long callId, T defaultValue)
        {
            AsyncObject <T> responseAsyncObject = null;

            lock (this._responseAsyncObjects)
            {
                responseAsyncObject = this.GetResponseAsyncObject(callId);
            }
            T local = responseAsyncObject.Value;

            lock (this._responseAsyncObjects)
            {
                this._responseAsyncObjects.Remove(callId);
            }
            if (local == null)
            {
                return(defaultValue);
            }
            return(local);
        }