private void CheckHandle() { if (_handle == null) { InternalResources.FileNotOpen(); } }
// Flush dumps the contents of the serial driver's internal read and write buffers. // We actually expose the functionality for each, but fulfilling Stream's contract // requires a Flush() method. Fails if handle closed. // Note: Serial driver's write buffer is *already* attempting to write it, so we can only wait until it finishes. public override void Flush() { if (_handle == null) { InternalResources.FileNotOpen(); } Interop.Termios.TermiosDiscard(_handle, Interop.Termios.Queue.AllQueues); }
internal void SetBufferSizes(int readBufferSize, int writeBufferSize) { if (_handle == null) { InternalResources.FileNotOpen(); } // Ignore for now. }
internal void DiscardOutBuffer() { if (_handle == null) { InternalResources.FileNotOpen(); } // This may or may not work depending on hardware. Interop.Termios.TermiosDiscard(_handle, Interop.Termios.Queue.SendQueue); }
private void FinishPendingIORequests(Interop.ErrorInfo?error = null) { while (_readQueue.TryDequeue(out SerialStreamIORequest r)) { r.Complete(error.HasValue ? Interop.GetIOException(error.Value) : InternalResources.FileNotOpenException()); } while (_writeQueue.TryDequeue(out SerialStreamIORequest r)) { r.Complete(error.HasValue ? Interop.GetIOException(error.Value) : InternalResources.FileNotOpenException()); } }
// Flush dumps the contents of the serial driver's internal read and write buffers. // We actually expose the functionality for each, but fulfilling Stream's contract // requires a Flush() method. Fails if handle closed. // Note: Serial driver's write buffer is *already* attempting to write it, so we can only wait until it finishes. public override void Flush() { if (_handle == null) { InternalResources.FileNotOpen(); } SpinWait sw = default; while (!_writeQueue.IsEmpty) { sw.SpinOnce(); } Interop.Termios.TermiosDrain(_handle); }
private void CheckReadWriteArguments(byte[] array, int offset, int count) { if (array == null) { throw new ArgumentNullException(nameof(array)); } if (offset < 0) { throw new ArgumentOutOfRangeException(nameof(offset), SR.ArgumentOutOfRange_NeedNonNegNumRequired); } if (count < 0) { throw new ArgumentOutOfRangeException(nameof(count), SR.ArgumentOutOfRange_NeedNonNegNumRequired); } if (array.Length - offset < count) { throw new ArgumentException(SR.Argument_InvalidOffLen); } if (_handle == null) { InternalResources.FileNotOpen(); } }