Example #1
0
        public void Start(Func<ArraySegment<byte>, Action<Exception>, TempEnum> write, Action<Exception> end, CancellationToken cancellationToken)
        {
            bodyStream = new BodyStream(write, end, cancellationToken);

            Action start = () =>
            {
                try
                {
                    if (bodyStream.CanSend())
                    {
                        var bytes = encoding.GetBytes(text);
                        var segment = new ArraySegment<byte>(bytes);

                        // Not buffered.
                        bodyStream.SendBytes(segment, null, null);

                        bodyStream.Finish();
                    }
                }
                catch (Exception ex)
                {
                    bodyStream.End(ex);
                }
            };

            bodyStream.Start(start, null);
        }
Example #2
0
        void Start(Func<ArraySegment<byte>, bool> write, Func<Action, bool> flush, Action<Exception> end, CancellationToken cancellationToken)
        {
            bodyStream = new BodyStream(write, flush, end, cancellationToken);

            Action start = () =>
            {
                try
                {
                    var rangeLength = range.Item2 - range.Item1 + 1;
                    SendFile(rangeLength);
                }
                catch (Exception ex)
                {
                    bodyStream.End(ex);
                }
            };

            Action dispose = () =>
            {
                if (fileStream != null)
                {
                    fileStream.Close();
                    fileStream.Dispose();
                    fileStream = null;
                }
            };

            bodyStream.Start(start, dispose);
        }