public static MutableString /*!*/ ReadNoBlock(RubyIO /*!*/ self, [DefaultProtocol] int bytes, [DefaultProtocol, Optional] MutableString buffer) { var stream = self.GetReadableStream(); try { stream.ReadTimeout = 0; } catch (InvalidOperationException) { throw RubyExceptions.CreateEBADF(); } return(Read(self, bytes, buffer)); }
public static MutableString /*!*/ SystemRead(RubyIO /*!*/ self, [DefaultProtocol] int bytes, [DefaultProtocol, Optional] MutableString buffer) { var stream = self.GetReadableStream(); if (stream.DataBuffered) { throw RubyExceptions.CreateIOError("sysread for buffered IO"); } // We use Flush to simulate non-buffered IO. // A better approach would be to create a parallel FileStream with // System.IO.FileOptions.WriteThrough (which corresponds to FILE_FLAG_NO_BUFFERING), and also maybe // System.IO.FileOptions.SequentialScan (FILE_FLAG_SEQUENTIAL_SCAN). // TODO: sysopen does that? stream.Flush(); var result = Read(self, bytes, buffer); if (result == null) { throw new EOFError("end of file reached"); } return(result); }
public static MutableString ReadNoBlock(RubyIO/*!*/ self, [DefaultProtocol]int bytes, [DefaultProtocol, Optional]MutableString buffer) { var stream = self.GetReadableStream(); MutableString result = null; self.NonBlockingOperation(() => result = Read(self, bytes, buffer), true); return result; }
public static MutableString/*!*/ SystemRead(RubyIO/*!*/ self, [DefaultProtocol]int bytes, [DefaultProtocol, Optional]MutableString buffer) { var stream = self.GetReadableStream(); if (stream.DataBuffered) { throw RubyExceptions.CreateIOError("sysread for buffered IO"); } // We use Flush to simulate non-buffered IO. // A better approach would be to create a parallel FileStream with // System.IO.FileOptions.WriteThrough (which corresponds to FILE_FLAG_NO_BUFFERING), and also maybe // System.IO.FileOptions.SequentialScan (FILE_FLAG_SEQUENTIAL_SCAN). // TODO: sysopen does that? stream.Flush(); var result = Read(self, bytes, buffer); if (result == null) { throw new EOFError("end of file reached"); } return result; }
public static MutableString/*!*/ ReadNoBlock(RubyIO/*!*/ self, [DefaultProtocol]int bytes, [DefaultProtocol, Optional]MutableString buffer) { var stream = self.GetReadableStream(); try { stream.ReadTimeout = 0; } catch (InvalidOperationException) { throw RubyExceptions.CreateEBADF(); } return Read(self, bytes, buffer); }