private void Callback(IAsyncResult ar) { if (access == StreamAccessOptions.Read) { int count = stream.EndRead(ar); if (count > 0) { if (count != buffer.Length) { // TODO: improve streams var buf = new byte[count]; Buffer.BlockCopy(buffer, 0, buf, 0, count); phpStream.WriteBytes(buf); } else { phpStream.WriteBytes(buffer); } stream.BeginRead(buffer, 0, buffer.Length, callback, ar.AsyncState); } else { phpStream.Flush(); stream.Dispose(); } } else { buffer = phpStream.ReadBytes(BufferSize); if (buffer != null) { stream.BeginWrite(buffer, 0, buffer.Length, callback, ar.AsyncState); } else { stream.EndWrite(ar); stream.Dispose(); } } }
/// <summary> /// Flushes the output to a file. /// </summary> /// <param name="handle">A PhpResource passed to the PHP function.</param> /// <returns>True if successful.</returns> public static bool fflush(PhpResource handle) { PhpStream stream = PhpStream.GetValid(handle); return(stream != null && stream.Flush()); }