Inheritance: IAsyncDataSource, IAsyncDataWriter
Esempio n. 1
0
        public override void SetUp()
        {
            base.SetUp();
            var adapter = new StreamDataAdapter(this.Stream);

            Writer = new AsyncTextWriter(adapter, Encoding.ASCII);
        }
Esempio n. 2
0
        public void SetUp()
        {
            var dataPath = System.IO.Path.GetFullPath(System.IO.Directory.GetCurrentDirectory() + @"\..\..\data\");
            var testFile = dataPath + "test.py";

            Stream = System.IO.File.OpenRead(testFile);
            var encoding = Util.IO.DetectStreamEncoding(Stream);
            var adapter  = new StreamDataAdapter(Stream);

            Reader = new AsyncTextReader(adapter, encoding);
        }
Esempio n. 3
0
        public void TestFlushStream()
        {
            var stream  = new MockStream();
            var adapter = new StreamDataAdapter(stream, true);

            Assert.AreEqual(0, stream._FlushCount);

            var f = adapter.Flush();

            f.GetCompletionEvent().Wait();
            Assert.AreEqual(1, stream._FlushCount);

            adapter.Dispose();
        }
Esempio n. 4
0
 public static AsyncTextWriter GetResponseWriter(this HttpListenerContext context, Encoding encoding)
 {
     var adapter = new StreamDataAdapter(context.Response.OutputStream, true);
     var result = new AsyncTextWriter(adapter, encoding);
     result.AutoFlush = true;
     return result;
 }
Esempio n. 5
0
 public static AsyncTextReader GetRequestReader(this HttpListenerContext context)
 {
     var encoding = context.Request.ContentEncoding ?? Encoding.UTF8;
     var adapter = new StreamDataAdapter(context.Request.InputStream, true);
     var result = new AsyncTextReader(adapter, encoding);
     return result;
 }
Esempio n. 6
0
        public void TestFlushStream()
        {
            var stream = new MockStream();
            var adapter = new StreamDataAdapter(stream, true);
            Assert.AreEqual(0, stream._FlushCount);

            var f = adapter.Flush();
            f.GetCompletionEvent().Wait();
            Assert.AreEqual(1, stream._FlushCount);

            adapter.Dispose();
        }
Esempio n. 7
0
 public override void SetUp()
 {
     base.SetUp();
     var adapter = new StreamDataAdapter(this.Stream);
     Writer = new AsyncTextWriter(adapter, Encoding.ASCII);
 }
Esempio n. 8
0
 public void SetUp () {
     var dataPath = System.IO.Path.GetFullPath(System.IO.Directory.GetCurrentDirectory() + @"\..\..\data\");
     var testFile = dataPath + "test.py";
     Stream = System.IO.File.OpenRead(testFile);
     var encoding = Util.IO.DetectStreamEncoding(Stream);
     var adapter = new StreamDataAdapter(Stream);
     Reader = new AsyncTextReader(adapter, encoding);
 }
Esempio n. 9
0
            private IEnumerator<object> SendResponseTask(Stream source, int? count)
            {
                var length = Math.Min(
                    (int)source.Length,
                    count.GetValueOrDefault(int.MaxValue)
                );
                ContentLength = length;

                if (!HeadersSent) {
                    HeadersSent = true;
                    yield return SendHeadersTask();
                }

                ResponseSent = true;

                const int blockSize = 1024 * 128;
                var bytesLeft = length;

                using (var sda = new StreamDataAdapter(source, false))
                using (var buffer = BufferPool<byte>.Allocate(blockSize))
                while (bytesLeft > 0) {
                    var readSize = Math.Min(blockSize, bytesLeft);
                    var fBlock = sda.Read(buffer.Data, 0, blockSize);
                    yield return fBlock;

                    bytesLeft -= fBlock.Result;

                    yield return Adapter.Write(buffer.Data, 0, fBlock.Result);
                }
            }