예제 #1
0
        internal bool FlushInput()
        {
            //Discarded unreachable code: IL_0091
            if (!HasEntityBody)
            {
                return(true);
            }
            int num = 2048;

            if (_contentLength > 0)
            {
                num = (int)Math.Min(_contentLength, num);
            }
            byte[] buffer = new byte[num];
            while (true)
            {
                try
                {
                    IAsyncResult asyncResult = InputStream.BeginRead(buffer, 0, num, null, null);
                    if (!asyncResult.IsCompleted && !asyncResult.AsyncWaitHandle.WaitOne(100))
                    {
                        return(false);
                    }
                    if (InputStream.EndRead(asyncResult) <= 0)
                    {
                        return(true);
                    }
                }
                catch
                {
                    return(false);
                }
            }
        }
예제 #2
0
        // returns true is the stream could be reused.
        internal bool FlushInput()
        {
            if (!HasEntityBody)
            {
                return(true);
            }

            int length = 2048;

            if (content_length > 0)
            {
                length = (int)Math.Min(content_length, (long)length);
            }

            byte [] bytes = new byte [length];
            while (true)
            {
                // TODO: test if MS has a timeout when doing this
                try {
                    IAsyncResult ares = InputStream.BeginRead(bytes, 0, length, null, null);
                    if (!ares.IsCompleted && !ares.AsyncWaitHandle.WaitOne(1000))
                    {
                        return(false);
                    }
                    if (InputStream.EndRead(ares) <= 0)
                    {
                        return(true);
                    }
                } catch {
                    return(false);
                }
            }
        }
        // Returns true is the stream could be reused.
        internal bool FlushInput()
        {
            if (!HasEntityBody)
            {
                return(true);
            }

            var length = 2048;

            if (_contentLength > 0)
            {
                length = (int)Math.Min(_contentLength, (long)length);
            }

            var buffer = new byte [length];

            while (true)
            {
                // TODO: Test if MS has a timeout when doing this.
                try {
                    var ares = InputStream.BeginRead(buffer, 0, length, null, null);
                    if (!ares.IsCompleted && !ares.AsyncWaitHandle.WaitOne(100))
                    {
                        return(false);
                    }

                    if (InputStream.EndRead(ares) <= 0)
                    {
                        return(true);
                    }
                } catch {
                    return(false);
                }
            }
        }
예제 #4
0
        // returns true is the stream could be reused.
        internal bool FlushInput()
        {
            if (!HasEntityBody)
            {
                return(true);
            }

            var length = 2048;

            if (ContentLength64 > 0)
            {
                length = (int)Math.Min(ContentLength64, length);
            }

            var bytes = new byte[length];

            while (true)
            {
                // TODO: test if MS has a timeout when doing this
                try
                {
                    var ares = InputStream.BeginRead(bytes, 0, length, null, null);
                    if (!ares.IsCompleted && !ares.AsyncWaitHandle.WaitOne(1000))
                    {
                        return(false);
                    }
                    if (InputStream.EndRead(ares) <= 0)
                    {
                        return(true);
                    }
                }
                catch (ObjectDisposedException)
                {
                    _inputStream = null;
                    return(true);
                }
                catch
                {
                    return(false);
                }
            }
        }
예제 #5
0
        internal bool FlushInput()
        {
            if (!HasEntityBody)
            {
                return(true);
            }

            var len = 2048;

            if (_contentLength > 0 && _contentLength < len)
            {
                len = (int)_contentLength;
            }

            var buff = new byte[len];

            while (true)
            {
                try
                {
                    var ares = InputStream.BeginRead(buff, 0, len, null, null);
                    if (!ares.IsCompleted)
                    {
                        var timeout = 100;
                        if (!ares.AsyncWaitHandle.WaitOne(timeout))
                        {
                            return(false);
                        }
                    }

                    if (InputStream.EndRead(ares) <= 0)
                    {
                        return(true);
                    }
                }
                catch
                {
                    return(false);
                }
            }
        }
        // returns true is the stream could be reused.
        internal bool FlushInput()
        {
            if (!HasEntityBody)
            {
                return(true);
            }

            int length = 2048;

            if (_contentLength > 0)
            {
                length = (int)Math.Min(_contentLength, (long)length);
            }

            byte[] bytes = new byte[length];
            while (true)
            {
                try
                {
                    IAsyncResult ares = InputStream.BeginRead(bytes, 0, length, null, null);
                    if (!ares.IsCompleted && !ares.AsyncWaitHandle.WaitOne(1000))
                    {
                        return(false);
                    }
                    if (InputStream.EndRead(ares) <= 0)
                    {
                        return(true);
                    }
                }
                catch (ObjectDisposedException)
                {
                    _inputStream = null;
                    return(true);
                }
                catch
                {
                    return(false);
                }
            }
        }
예제 #7
0
        public void OnCompleteRead(IAsyncResult asyncResult)
        {
            //异步读取一个快,接收数据
            int bytesRead = InputStream.EndRead(asyncResult);

            //如果没有任何字节,则流已达文件结尾
            if (bytesRead > 0)
            {
                //暂停以对模拟对数据块的处理
                Debug.WriteLine("异步线程:已读取一块内容");
                var datastr = Encoding.GetEncoding("gb2312").GetString(buffer, 0, buffer.Length);
                ReadValue.Append(datastr);
                //
                Thread.Sleep(TimeSpan.FromMilliseconds(20));
                //开始读取下一块
                InputStream.BeginRead(buffer, 0, buffer.Length, OnCompleteRead, null);
            }
            else
            {
                //操作结束
                Debug.WriteLine("   异步线程:读取文件结束");
                OnIsReturnEvent();
            }
        }
예제 #8
0
 private void ProcessRecv()
 {
     if (recvResult != null && recvResult.IsCompleted)
     {
         try {
             int bytes = InputStream.EndRead(recvResult);
             if (bytes > 0)
             {
                 recvBytesCounter.Add(bytes);
                 recvStream.Seek(0, SeekOrigin.End);
                 recvStream.Write(recvBuffer, 0, bytes);
                 recvStream.Seek(0, SeekOrigin.Begin);
             }
             else if (bytes < 0)
             {
                 OnError();
             }
         }
         catch (ObjectDisposedException) {}
         catch (IOException) {
             OnError();
         }
         recvResult = null;
     }
     if (!HasError && recvResult == null)
     {
         try {
             recvResult = InputStream.BeginRead(recvBuffer, 0, recvBuffer.Length, null, null);
         }
         catch (ObjectDisposedException) {
         }
         catch (IOException) {
             OnError();
         }
     }
 }
예제 #9
0
        /// <summary>开始异步读操作</summary>
        /// <param name="buffer"></param>
        /// <param name="offset"></param>
        /// <param name="count"></param>
        /// <param name="callback"></param>
        /// <param name="state"></param>
        /// <returns></returns>
        public override IAsyncResult BeginRead(byte[] buffer, int offset, int count, AsyncCallback callback, object state)
        {
            CheckArgument(buffer, offset, count);

            return(InputStream.BeginRead(buffer, offset, count, callback, state));
        }