Ejemplo n.º 1
0
        private void AsyncWrite(Handle handle, Result result, byte[] buffer,
                                ulong bytesRequested, ulong bytesWritten)
        {
            if (result == Result.Ok)
            {
                bytesRemaining -= (int)bytesWritten;
                if (bytesRemaining > 0)
                {
                    Async.Write(handle, out buffer[offset + count - bytesRemaining],
                                (uint)bytesRemaining, new AsyncWriteCallback(AsyncWrite));
                }
                else if (cback != null)
                {
                    asyncResult.SetComplete(null, count);
                    cback(asyncResult);
                }
            }
            else if (result == Result.ErrorEof)
            {
                bytesRemaining -= (int)bytesWritten;
                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);
            }
        }
Ejemplo n.º 2
0
        public override void Write(byte[] buffer, int offset, int count)
        {
            if (buffer == null)
            {
                throw new ArgumentNullException("buffer");
            }
            else if (offset < 0)
            {
                throw new ArgumentOutOfRangeException("offset", "Must be >= 0");
            }
            else if (count < 0)
            {
                throw new ArgumentOutOfRangeException("count", "Must be >= 0");
            }
            else if (count > buffer.Length - offset)
            {
                throw new ArgumentException("Buffer too small, count/offset wrong");
            }
            else if (!CanWrite)
            {
                throw new NotSupportedException("The stream does not support writing");
            }

            ulong  bytesWritten;
            Result result;

            if (async)
            {
                Async.Write(handle, out buffer[offset], (uint)count, writeCallback);
                Wait();
                result       = asyncResult;
                bytesWritten = asyncBytesWritten;
            }
            else
            {
                result = Sync.Write(handle, out buffer[offset], (ulong)count, out bytesWritten);
            }
            Vfs.ThrowException(Uri, result);
        }
Ejemplo n.º 3
0
        public override void WriteByte(byte value)
        {
            if (!CanWrite)
            {
                throw new NotSupportedException("The stream does not support writing");
            }

            byte[] buffer = new byte[1];
            buffer[0] = value;
            ulong  bytesWritten;
            Result result;

            if (async)
            {
                Async.Write(handle, out buffer[0], 1, writeCallback);
                Wait();
                result = asyncResult;
            }
            else
            {
                result = Sync.Write(handle, out buffer[0], 1UL, out bytesWritten);
            }
            Vfs.ThrowException(Uri, result);
        }
Ejemplo n.º 4
0
 public VfsStreamAsyncResult BeginWrite()
 {
     asyncResult = new VfsStreamAsyncResult(state);
     Async.Write(handle, out buffer[offset], (uint)count, new AsyncWriteCallback(AsyncWrite));
     return(asyncResult);
 }