EndRead() 개인적인 메소드

private EndRead ( HttpWebRequest request, IAsyncResult result ) : int
request HttpWebRequest
result IAsyncResult
리턴 int
예제 #1
0
        public override int EndRead(IAsyncResult r)
        {
            WebAsyncResult result = (WebAsyncResult)r;

            if (result.EndCalled)
            {
                int xx = result.NBytes;
                return((xx >= 0) ? xx : 0);
            }

            result.EndCalled = true;

            if (!result.IsCompleted)
            {
                int nbytes = -1;
                try {
                    nbytes = cnc.EndRead(request, result);
                } catch (Exception exc) {
                    lock (locker) {
                        pendingReads--;
                        if (pendingReads == 0)
                        {
                            pending.Set();
                        }
                    }

                    nextReadCalled = true;
                    cnc.Close(true);
                    result.SetCompleted(false, exc);
                    result.DoCallback();
                    throw;
                }

                if (nbytes < 0)
                {
                    nbytes   = 0;
                    read_eof = true;
                }

                totalRead += nbytes;
                result.SetCompleted(false, nbytes + result.NBytes);
                result.DoCallback();
                if (nbytes == 0)
                {
                    contentLength = totalRead;
                }
            }

            lock (locker) {
                pendingReads--;
                if (pendingReads == 0)
                {
                    pending.Set();
                }
            }

            if (totalRead >= contentLength && !nextReadCalled)
            {
                ReadAll();
            }

            int nb = result.NBytes;

            return((nb >= 0) ? nb : 0);
        }
예제 #2
0
        public override int EndRead(IAsyncResult r)
        {
            WebAsyncResult webAsyncResult = (WebAsyncResult)r;

            if (webAsyncResult.EndCalled)
            {
                int nBytes = webAsyncResult.NBytes;
                return((nBytes >= 0) ? nBytes : 0);
            }
            webAsyncResult.EndCalled = true;
            if (!webAsyncResult.IsCompleted)
            {
                int num = -1;
                try
                {
                    num = cnc.EndRead(request, webAsyncResult);
                }
                catch (Exception e)
                {
                    lock (locker)
                    {
                        pendingReads--;
                        if (pendingReads == 0)
                        {
                            pending.Set();
                        }
                    }
                    nextReadCalled = true;
                    cnc.Close(sendNext: true);
                    webAsyncResult.SetCompleted(synch: false, e);
                    webAsyncResult.DoCallback();
                    throw;
                    IL_00bb :;
                }
                if (num < 0)
                {
                    num      = 0;
                    read_eof = true;
                }
                totalRead += num;
                webAsyncResult.SetCompleted(synch: false, num + webAsyncResult.NBytes);
                webAsyncResult.DoCallback();
                if (num == 0)
                {
                    contentLength = totalRead;
                }
            }
            lock (locker)
            {
                pendingReads--;
                if (pendingReads == 0)
                {
                    pending.Set();
                }
            }
            if (totalRead >= contentLength && !nextReadCalled)
            {
                ReadAll();
            }
            int nBytes2 = webAsyncResult.NBytes;

            return((nBytes2 >= 0) ? nBytes2 : 0);
        }