Exemple #1
0
        public Task StartAsync(CancellationToken ct = default)
        {
            var d   = PipeOptions.Default;
            var opt = new PipeOptions(
                d.Pool,
                d.ReaderScheduler,
                d.WriterScheduler,
                _resumeWriterThreshole,
                d.ResumeWriterThreshold,
                d.MinimumSegmentSize,
                d.UseSynchronizationContext);
            var pipe = new Pipe(opt);

            Console.WriteLine("开始一个推送");
            //接收
            var t1 = Producer(_socket, pipe.Writer, ct);
            var t2 = Consumer(pipe.Reader, ct);
            //发送
            var t3 = Writer(ct);

            ct.Register(() =>
            {
                ChunkStreamContext?.Dispose();
                ChunkStreamContext = null;
            });

            var           tcs          = new TaskCompletionSource <int>();
            Action <Task> setException = t =>
            {
                tcs.TrySetException(t.Exception.InnerException);
            };
            Action <Task> setCanceled = _ =>
            {
                tcs.TrySetCanceled();
            };
            Action <Task> setResult = t =>
            {
                tcs.TrySetResult(1);
            };


            t1.ContinueWith(setException, TaskContinuationOptions.OnlyOnFaulted);
            t2.ContinueWith(setException, TaskContinuationOptions.OnlyOnFaulted);
            t3.ContinueWith(setException, TaskContinuationOptions.OnlyOnFaulted);
            t1.ContinueWith(setCanceled, TaskContinuationOptions.OnlyOnCanceled);
            t2.ContinueWith(setCanceled, TaskContinuationOptions.OnlyOnCanceled);
            t3.ContinueWith(setCanceled, TaskContinuationOptions.OnlyOnCanceled);
            t1.ContinueWith(setResult, TaskContinuationOptions.OnlyOnRanToCompletion);
            t2.ContinueWith(setResult, TaskContinuationOptions.OnlyOnRanToCompletion);
            t3.ContinueWith(setResult, TaskContinuationOptions.OnlyOnRanToCompletion);
            return(tcs.Task);
        }
Exemple #2
0
        protected virtual void Dispose(bool disposing)
        {
            if (!disposedValue)
            {
                if (disposing)
                {
                    _handshakeContext?.Dispose();
                    ChunkStreamContext?.Dispose();
                    _socket.Dispose();
                    _writerSignal.Dispose();
                }


                disposedValue = true;
            }
        }
Exemple #3
0
 internal void OnHandshakeSuccessful()
 {
     _handshakeContext = null;
     _bufferProcessors.Clear();
     ChunkStreamContext = new ChunkStreamContext(this);
 }