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 byte[] ReadBlockSize(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 = stream.Read(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());
        }
示例#3
0
        public override int Read(byte[] buffer, int offset, int count)
        {
            int readCount = _pipeNetworkStream.Read(buffer, count);

            return(readCount);
        }