public override async Task <byte[]> ReadBlockSizeAsync(PipeNetworkStream stream, int count)
#endif
        {
            List <byte> bytes        = new List <byte>();
            int         lengthReaded = 0;

            while (lengthReaded < count)
            {
                int countToRead = count;
                if (lengthReaded + countToRead > count)
                {
                    countToRead = count - lengthReaded;
                }
                //#if (!PORTABLE)
                //                Console.WriteLine("countToRead: " + countToRead);
                //#endif
                byte[] readBytes = new byte[countToRead];
#if (NET35 || NET40)
                int readCount = stream.Read(readBytes, countToRead);
#else
                int readCount = await stream.ReadAsync(readBytes, countToRead);
#endif
                if (readCount <= 0)
                {
                    throw new Exception("read zero buffer! client disconnected: " + readCount);
                }
                lengthReaded += readCount;
                bytes.AddRange(readBytes.ToList().GetRange(0, readCount));
            }
            return(bytes.ToArray());
        }
        public virtual async Task <byte[]> ReadBlockSizeAsync(PipeNetworkStream stream, int count)
        {
            List <byte> bytes        = new List <byte>();
            int         lengthReaded = 0;

            while (lengthReaded < count)
            {
                int countToRead = count;
                if (lengthReaded + countToRead > count)
                {
                    countToRead = count - lengthReaded;
                }
                byte[] readBytes = new byte[countToRead];
                int    readCount = await stream.ReadAsync(readBytes, countToRead);

                if (readCount <= 0)
                {
                    throw new Exception("read zero buffer! client disconnected: " + readCount);
                }
                lengthReaded += readCount;
                bytes.AddRange(readBytes.ToList().GetRange(0, readCount));
            }
            return(bytes.ToArray());
        }
Ejemplo n.º 3
0
        public override async Task <int> ReadAsync(byte[] buffer, int offset, int count, CancellationToken cancellationToken)
        {
            int readCount = await _pipeNetworkStream.ReadAsync(buffer, count);

            return(readCount);
        }