示例#1
0
 /// <summary>
 /// Asynchronously write to a <see cref="Stream"/>.
 /// </summary>
 /// <param name="stream">Target <see cref="Stream"/>.</param>
 /// <param name="buffer">Byte array to write to the target.</param>
 /// <param name="offset">Position in buffer to start reading from.</param>
 /// <param name="count">Number of bytes to read from buffer.</param>
 /// <param name="result">The <see cref="Result"/> instance to be returned by the call.</param>
 /// <returns>Synchronization handle for the number of bytes read.</returns>
 public static Result Write(this Stream stream, byte[] buffer, int offset, int count, Result result)
 {
     if (SysUtil.UseAsyncIO)
     {
         return(AsyncUtil.From(stream.BeginWrite, stream.EndWrite, buffer, offset, count, null, result));
     }
     return(AsyncUtil.Fork(() => stream.Write(buffer, offset, count), result));
 }
示例#2
0
 /// <summary>
 /// Asynchronously read from a <see cref="Stream"/>
 /// </summary>
 /// <param name="stream">Source <see cref="Stream"/></param>
 /// <param name="buffer">Byte array to fill from the source</param>
 /// <param name="offset">Position in buffer to start writing to</param>
 /// <param name="count">Number of bytes to read from the <see cref="Stream"/></param>
 /// <param name="result">The <see cref="Result"/> instance to be returned by the call.</param>
 /// <returns>Synchronization handle for the number of bytes read.</returns>
 public static Result <int> Read(this Stream stream, byte[] buffer, int offset, int count, Result <int> result)
 {
     if (SysUtil.UseAsyncIO)
     {
         return(AsyncUtil.From(stream.BeginRead, stream.EndRead, buffer, offset, count, null, result));
     }
     return(AsyncUtil.Fork(() => SyncRead_Helper(stream, buffer, offset, count), result));
 }