Exemplo n.º 1
0
        public static async Task ReadFullImpl(IMyStream myStream, BytesSegment bs)
        {
            int pos = 0;

            if (myStream is IMyStreamReadR r)
            {
                while (pos < bs.Len)
                {
                    var read = await r.ReadAsyncR(bs.Sub(pos));

                    if (read == 0)
                    {
                        throw new DisconnectedException($"unexpected EOF while ReadFull() (count={bs.Len}, pos={pos})");
                    }
                    pos += read;
                }
                return;
            }
            while (pos < bs.Len)
            {
                var read = await myStream.ReadAsync(bs.Sub(pos)).CAF();

                if (read == 0)
                {
                    throw new DisconnectedException($"unexpected EOF while ReadFull() (count={bs.Len}, pos={pos})");
                }
                pos += read;
            }
        }
Exemplo n.º 2
0
 public static AwaitableWrapper <int> ReadAsyncR(this IMyStream myStream, BytesSegment bs)
 {
     if (myStream is IMyStreamReadR myStreamReuse)
     {
         return(myStreamReuse.ReadAsyncR(bs));
     }
     return(new AwaitableWrapper <int>(myStream.ReadAsync(bs)));
 }
Exemplo n.º 3
0
 public static int Read(this IMyStream myStream, byte[] buf, int offset, int count)
 {
     if (myStream is IMyStreamSync sync)
     {
         return(sync.Read(new BytesSegment(buf, offset, count)));
     }
     else
     {
         return(myStream.ReadAsync(buf, offset, count).RunSync());
     }
 }
Exemplo n.º 4
0
 public static Task <int> ReadAsync(this IMyStream myStream, byte[] buf, int offset, int count)
 {
     return(myStream.ReadAsync(new BytesSegment(buf, offset, count)));
 }