public override void Write (byte [] buffer, int offset, int count)
{
CheckDisposed ();
if (buffer == null)
throw new ArgumentNullException ("buffer");
if (offset < 0 || count < 0)
throw new ArgumentOutOfRangeException ();
if (buffer.Length - offset < count)
throw new ArgumentException ("offset+count",
"The size of the buffer is less than offset + count.");
int bytes_written = 0;
unsafe {
fixed (byte* ptr = buffer) {
if (WriteFile (handle, ptr + offset, count, out bytes_written, write_overlapped))
return;
if (Marshal.GetLastWin32Error() != FileIOPending)
ReportIOError (null);
if (!GetOverlappedResult(handle, write_overlapped, ref bytes_written, true))
ReportIOError (null);
}
}
// If the operation timed out, then
// we transfered less bytes than the requested ones
if (bytes_written < count)
throw new TimeoutException ();
}