diff options
author | Leszek 'skolima' Ciesielski <skolima@gmail.com> | 2010-01-22 13:31:04 +0300 |
---|---|---|
committer | Leszek 'skolima' Ciesielski <skolima@gmail.com> | 2010-01-22 13:31:04 +0300 |
commit | 3dd68a17ca9ec168788bc9f2fd7d3fc8ef5f6d3f (patch) | |
tree | ea577c9802f0430f91c62d8c380f743e7708bb88 /mcs | |
parent | 1496e4136cb7bcb6592adc5556d2f73bac3c1f19 (diff) |
2010-01-22 Leszek Ciesielski <skolima@gmail.com>
* SerialPortStream.cs: Check for error on every native call
svn path=/trunk/mcs/; revision=150062
Diffstat (limited to 'mcs')
-rw-r--r-- | mcs/class/System/System.IO.Ports/ChangeLog | 4 | ||||
-rw-r--r-- | mcs/class/System/System.IO.Ports/SerialPortStream.cs | 27 |
2 files changed, 24 insertions, 7 deletions
diff --git a/mcs/class/System/System.IO.Ports/ChangeLog b/mcs/class/System/System.IO.Ports/ChangeLog index a8d34d71df7..1ac0a1e1227 100644 --- a/mcs/class/System/System.IO.Ports/ChangeLog +++ b/mcs/class/System/System.IO.Ports/ChangeLog @@ -1,3 +1,7 @@ +2010-01-22 Leszek Ciesielski <skolima@gmail.com> + + * SerialPortStream.cs: Check for error on every native call + 2009-11-28 Carlos Alberto Cortez <calberto.cortez@gmail.com> * WinSerialStream.cs: Make CommStat a struct instead of a class to diff --git a/mcs/class/System/System.IO.Ports/SerialPortStream.cs b/mcs/class/System/System.IO.Ports/SerialPortStream.cs index b67912279e1..608f18afb53 100644 --- a/mcs/class/System/System.IO.Ports/SerialPortStream.cs +++ b/mcs/class/System/System.IO.Ports/SerialPortStream.cs @@ -147,7 +147,10 @@ namespace System.IO.Ports throw new TimeoutException(); } - return read_serial (fd, buffer, offset, count); + if (read_serial (fd, buffer, offset, count) == -1) + ThrowIOException (); + + return count; } public override long Seek (long offset, SeekOrigin origin) @@ -176,6 +179,7 @@ namespace System.IO.Ports throw new ArgumentException ("offset+count", "The size of the buffer is less than offset + count."); + // FIXME: this reports every write error as timeout if (write_serial (fd, buffer, offset, count, write_timeout) < 0) throw new TimeoutException("The operation has timed-out"); } @@ -229,27 +233,35 @@ namespace System.IO.Ports public int BytesToRead { get { - return get_bytes_in_buffer (fd, 1); + int result = get_bytes_in_buffer (fd, 1); + if (result == -1) + ThrowIOException (); + return result; } } public int BytesToWrite { get { - return get_bytes_in_buffer (fd, 0); + int result = get_bytes_in_buffer (fd, 0); + if (result == -1) + ThrowIOException (); + return result; } } [DllImport ("MonoPosixHelper", SetLastError = true)] - static extern void discard_buffer (int fd, bool inputBuffer); + static extern int discard_buffer (int fd, bool inputBuffer); public void DiscardInBuffer () { - discard_buffer (fd, true); + if (discard_buffer (fd, true) != 0) + ThrowIOException(); } public void DiscardOutBuffer () { - discard_buffer (fd, false); + if (discard_buffer (fd, false) != 0) + ThrowIOException(); } [DllImport ("MonoPosixHelper", SetLastError = true)] @@ -286,7 +298,8 @@ namespace System.IO.Ports public void SetBreakState (bool value) { if (value) - breakprop (fd); + if (breakprop (fd) == -1) + ThrowIOException (); } [DllImport ("libc")] |