protected override bool Read(IntPtr dataOut, int bytesToRead, out int bytesRead, CefResourceReadCallback callback) { bytesRead = 0; //We don't need the callback, as it's an unmanaged resource we should dispose it (could wrap it in a using statement). callback.Dispose(); if (Stream is null) { return(false); } //Data out represents an underlying unmanaged buffer (typically 64kb in size). //We reuse a temp buffer where possible if (tempBuffer is null || tempBuffer.Length < bytesToRead) { tempBuffer = new byte[bytesToRead]; } //Only read the number of bytes that can be written to dataOut bytesRead = Stream.Read(tempBuffer, 0, bytesToRead); // To indicate response completion set bytesRead to 0 and return false if (bytesRead == 0) { return(false); } using (var safeBuffer = new CefSafeBuffer(dataOut, (ulong)bytesRead)) using (var dataOutStream = new UnmanagedMemoryStream(safeBuffer, 0, bytesRead, FileAccess.Write)) { //We need to use bytesRead instead of tempbuffer.Length otherwise //garbage from the previous copy would be written to dataOut dataOutStream.Write(tempBuffer, 0, bytesRead); } return(bytesRead > 0); }
protected override unsafe bool Read(IntPtr dataOut, int bytesToRead, out int bytesRead, CefResourceReadCallback callback) { var byteSpan = new Span <byte>((void *)dataOut, bytesToRead); bytesRead = _stream.Read(byteSpan); return(bytesRead != 0); }
protected override bool Read(IntPtr dataOut, int bytesToRead, out int bytesRead, CefResourceReadCallback callback) { // Backwards compatibility. ReadResponse will be called. callback.Dispose(); bytesRead = -1; return(false); }
protected internal sealed override bool Read(IntPtr dataOut, int bytesToRead, ref int bytesRead, CefResourceReadCallback callback) { if (bytesToRead < 0) { bytesRead = (int)CefErrorCode.Failed; return(false); } int offset = _offset; bytesRead = Math.Min(_data.Length - offset, bytesToRead); if (bytesRead == 0) { return(false); } Marshal.Copy(_data, offset, dataOut, bytesRead); _offset = offset + bytesRead; return(true); }
public override bool Read(IntPtr dataOut, int bytesToRead, ref int bytesRead, CefResourceReadCallback callback) { return(_implementation.Read(dataOut, bytesToRead, ref bytesRead, callback)); }
protected override bool Read(IntPtr dataOut, int bytesToRead, out int bytesRead, CefResourceReadCallback callback) { bytesRead = -1; return(false); }
protected override bool Read(IntPtr dataOut, int bytesToRead, out int bytesRead, CefResourceReadCallback callback) { bytesRead = Math.Min(bytesToRead, blob.Length - offset); System.Runtime.InteropServices.Marshal.Copy(this.blob, this.offset, dataOut, bytesRead); offset += bytesRead; if (bytesRead == 0) { return(false); } return(true); }
protected override bool Read(IntPtr dataOut, int bytesToRead, out int bytesRead, CefResourceReadCallback callback) { var total = _resourceResponse?.Length ?? 0; var bytesToCopy = (int)(total - _readStreamOffset); if (total == 0 || bytesToCopy <= 0) { bytesRead = 0; return(false); } //if (bytesToCopy > bytesToRead) //{ // bytesToCopy = bytesToRead; //} bytesToCopy = Math.Min(bytesToCopy, bytesToRead); var buff = new byte[bytesToCopy]; _resourceResponse.ContentStream.Position = _readStreamOffset; _resourceResponse.ContentStream.Read(buff, 0, bytesToCopy); Marshal.Copy(buff, 0, dataOut, bytesToCopy); _readStreamOffset += bytesToCopy; bytesRead = bytesToCopy; if (_readStreamOffset == _resourceResponse.Length) { if (WinFormium.Runtime.IsDebuggingMode) { lock (Logger) { Logger.Debug($"[{this.GetType().Namespace}]:"); Logger.Verbose($" -> {string.Join(" ", Infos)}"); } } _resourceResponse.Dispose(); _gcHandle.Free(); } return(true); }
protected override bool Read(Stream outResponse, int bytesToRead, out int bytesRead, CefResourceReadCallback callback) { var buffer = new byte[bytesToRead]; bytesRead = Response?.Read(buffer, 0, buffer.Length) ?? 0; if (bytesRead == 0) { return(false); } outResponse.Write(buffer, 0, bytesRead); return(bytesRead > 0); }
protected internal unsafe override bool Read(IntPtr dataOut, int bytesToRead, ref int bytesRead, CefResourceReadCallback callback) { return(_implementation.Read(dataOut, bytesToRead, ref bytesRead, callback)); }
protected override bool Read(IntPtr dataOut, int bytesToRead, out int bytesRead, CefResourceReadCallback callback) { if (bytesToRead > 0) { bytesRead = bytesToRead; callback.Continue(bytesRead); return(true); } bytesRead = 0; return(false); }
protected override bool Read(IntPtr dataOut, int bytesToRead, out int bytesRead, CefResourceReadCallback callback) { throw new NotImplementedException(); }
protected internal sealed unsafe override bool Read(IntPtr dataOut, int bytesToRead, ref int bytesRead, CefResourceReadCallback callback) { if (bytesToRead < 0) { bytesRead = (int)CefErrorCode.Failed; return(false); } #if NET5_0_OR_GREATER || NETSTANDARD2_1 if (_stream is MemoryStream || _stream is UnmanagedMemoryStream) { bytesRead = _stream.Read(new Span <byte>((void *)dataOut, bytesToRead)); return(bytesRead != 0); } else #endif { var ums = new UnmanagedMemoryStream((byte *)dataOut, bytesToRead, bytesToRead, FileAccess.Write); var limitedStream = new LimitedReadOnlyStream(_stream, bytesToRead); try { limitedStream.CopyToAsync(ums, this.BufferSize, _cancellation.Token).ContinueWith(InvokeReadCallback, new ReadState { BytesToRead = bytesToRead, Stream = limitedStream, Callback = callback, }, _cancellation.Token, TaskContinuationOptions.ExecuteSynchronously | TaskContinuationOptions.DenyChildAttach, TaskScheduler.Default); } catch (AccessViolationException) { throw; } catch { bytesRead = (int)CefErrorCode.Failed; return(false); } bytesRead = 0; } return(true); }