예제 #1
0
파일: StreamWriter.cs 프로젝트: xyuan/Dryad
        private async Task CloseInternal()
        {
            lock (this)
            {
                List <Buffer> remaining = writes.Shutdown();
                if (remaining.Count > 0)
                {
                    throw new ApplicationException("Got end write buffer with buffers still in the queue");
                }
                writes = null;
            }

            log.LogInformation("Closing write stream");

            try
            {
                error = await Close();

                if (error != null)
                {
                    errorType = ErrorType.Close;
                }
            }
            catch (Exception e)
            {
                log.LogError("Got exception closing stream " + e.ToString());
                error     = e.ToString();
                errorType = ErrorType.Close;
            }
        }
예제 #2
0
        private async Task Worker()
        {
            bool errorState = false;

            try
            {
                await Open();
            }
            catch (Exception e)
            {
                SendError(e, ErrorType.Open);
                errorState = true;
            }
            await DataLoop(errorState);

            List <Buffer> discard;

            lock (this)
            {
                discard     = queue.Shutdown();
                interrupted = true;
                queue       = null;
            }

            foreach (var buffer in discard.Where(b => b != null))
            {
                client.DiscardBuffer(buffer);
            }

            await OnFinishedRead();
        }