コード例 #1
0
        // This is the call that the AsyncCallBack delegate will reference.
        public void ReadAsyncCallBack(IAsyncResult ar)
        {
            while (failed_lock == true)
            {
                Thread.Sleep(1);
            }

            lock (this)
            {
                ReadAsyncDelegate del    = (ReadAsyncDelegate)((AsyncResult)ar).AsyncDelegate;
                PadInt            padInt = (PadInt)ar.AsyncState;

                int value = del.EndInvoke(ar);

                //In case the server never responds -> force kill
                if (value == Int32.MinValue)
                {
                    State = TransactionState.ABORTED;

                    failed_lock = false;
                    freeze_lock[(int)padInt.UID] = true;

                    return;
                }
                AddValue((int)padInt.UID, value);

                freeze_lock[(int)padInt.UID] = true;
            }
        }
コード例 #2
0
ファイル: HttpReader.cs プロジェクト: henricj/phonesm
        public HttpReader(ReadAsyncDelegate readAsync, Encoding encoding)
        {
            if (null == readAsync)
                throw new ArgumentNullException(nameof(readAsync));

            _readAsync = readAsync;
            _encoding = encoding;
        }
コード例 #3
0
        static NullableHandler()
        {
            UnderlyingType = Nullable.GetUnderlyingType(typeof(T));

            if (UnderlyingType == null)
            {
                return;
            }

            Read                 = NullableHandler.CreateDelegate <ReadDelegate <T> >(UnderlyingType, NullableHandler.ReadMethod);
            ReadAsync            = NullableHandler.CreateDelegate <ReadAsyncDelegate <T> >(UnderlyingType, NullableHandler.ReadAsyncMethod);
            ValidateAndGetLength = NullableHandler.CreateDelegate <ValidateAndGetLengthDelegate <T> >(UnderlyingType, NullableHandler.ValidateMethod);
            WriteAsync           = NullableHandler.CreateDelegate <WriteAsyncDelegate <T> >(UnderlyingType, NullableHandler.WriteAsyncMethod);
        }
コード例 #4
0
        public async Task AsStreamReturnsPipeReaderStream(ReadAsyncDelegate readAsync)
        {
            byte[] helloBytes = Encoding.ASCII.GetBytes("Hello World");
            var    pipe       = new Pipe();
            await pipe.Writer.WriteAsync(helloBytes);

            pipe.Writer.Complete();

            Stream stream = pipe.Reader.AsStream();

            var buffer = new byte[1024];
            int read   = await readAsync(stream, buffer);

            Assert.Equal(helloBytes, buffer.AsSpan(0, read).ToArray());
            pipe.Reader.Complete();
        }
コード例 #5
0
        public async Task ReadingFromPipeReaderStreamReadsFromUnderlyingPipeReader(ReadAsyncDelegate readAsync)
        {
            byte[] helloBytes = "Hello World" u8.ToArray();
            var    pipe       = new Pipe();
            await pipe.Writer.WriteAsync(helloBytes);

            pipe.Writer.Complete();

            var stream = new PipeReaderStream(pipe.Reader, leaveOpen: false);

            var buffer = new byte[1024];
            int read   = await readAsync(stream, buffer);

            Assert.Equal(helloBytes, buffer.AsSpan(0, read).ToArray());
            pipe.Reader.Complete();
        }
コード例 #6
0
        internal int Read(PadInt padInt)
        {
            if (State.Equals(TransactionState.ABORTED))
            {
                // Some server failed
                Console.WriteLine("Trying to access padint uid=" + padInt.UID + " denied because of server failure");
                return(-1);
            }
            string remotePadIntURL = padInt.URL + "RemotePadInt";
            int    uid             = padInt.UID;

            freeze_lock.Add(uid, false);

            IRemotePadInt remote = (IRemotePadInt)Activator.GetObject(
                typeof(IRemotePadInt), remotePadIntURL);

            ReadAsyncDelegate RemoteDel      = new ReadAsyncDelegate(remote.Read);
            AsyncCallback     RemoteCallback = new AsyncCallback(ReadAsyncCallBack);

            try
            {
                IAsyncResult RemAr = RemoteDel.BeginInvoke(uid, TXID, PadiDstm.Client_Url, RemoteCallback, padInt);
            }
            catch (TxException t) { Console.WriteLine("TXEXCEPTION" + t.msg); }

            timerAlive(padInt.URL);
            while (!freeze_lock[uid])
            {
                Thread.Sleep(1);
            }
            resetTimer();
            lock (freeze_lock) { freeze_lock.Remove(uid); }

            if (State.Equals(TransactionState.ABORTED))
            {
                // Some server failed
                Console.WriteLine("Trying to access padint uid=" + padInt.UID + " denied because of server failure");
                return(-1);
            }
            return(values[uid]);
        }