Exemplo n.º 1
0
        private void AsyncRead(Handle handle, Result result, byte[] buf,
                               ulong bytesRequested, ulong bytesRead)
        {
            if (result == Result.Ok)
            {
                Array.Copy(buf, 0, buffer, offset + count - bytesRemaining, (int)bytesRead);
                bytesRemaining -= (int)bytesRead;
                if (bytesRemaining > 0)
                {
                    buf = new byte[bytesRemaining];
                    Async.Read(handle, out buf[0], (uint)bytesRemaining,
                               new AsyncReadCallback(AsyncRead));
                }
                else if (cback != null)
                {
                    asyncResult.SetComplete(null, count);
                    cback(asyncResult);
                }
            }
            else if (result == Result.ErrorEof)
            {
                Array.Copy(buf, 0, buffer, offset + count - bytesRemaining, (int)bytesRead);
                bytesRemaining -= (int)bytesRead;
                asyncResult.SetComplete(null, count - bytesRemaining);

                if (cback != null)
                {
                    cback(asyncResult);
                }
            }
            else if (cback != null)
            {
                Exception e = new IOException(Vfs.ResultToString(result));
                asyncResult.SetComplete(e, -1);
                cback(asyncResult);
            }
        }