Public Types | |
enum | Flags { MarshalWritesToThreadPool = 0x01, ExecuteWritesOnCallingThread = 0x02, MarshallingFlagsMask = 0x0F, NoBuffering = 0x10, WriteThrough = 0x20, PreExtendFile = 0x40, BufferingFlagsMask = 0xF0 } |
typedef unsigned long | DataLength |
Public Member Functions | |
CAsyncFileWriter (const JetByteTools::Core::_tstring &filename, Callback &callback, IIOPool &pool, ILimitPendingWrites &writeLimiter=CPendingWriteLimiter::NoLimitLimiter, long flags=MarshalWritesToThreadPool, const LARGE_INTEGER &fileSize=DoNotPreExtendFile) | |
Write to the specified file asynchronously using overlapped I/O via the threads in the supplied IIOPool using buffers provided by the caller and push any errors that occur to the CAsyncFileWriter::Callback interface. Limits the maximum number of pending writes to the supplied limit to prevent uncontrolled 'non paged pool' memory usage if log messages are produced at a rate faster than they can be written to the disk. Note that once the limit is reached all writes become synchronous until the number of pending writes has dropped below the limit again. Sets the file size to the supplied value in the constructor and then trims the file to the actual size of the written bytes when the file is closed; this allows us to work around the fact that file systems extend files synchronously. | |
CAsyncFileWriter (const JetByteTools::Core::_tstring &filename, Callback &callback, IIOPool &pool, IMonitorAsyncFileWriter &monitor, ILimitPendingWrites &writeLimiter=CPendingWriteLimiter::NoLimitLimiter, long flags=MarshalWritesToThreadPool, const LARGE_INTEGER &fileSize=DoNotPreExtendFile) | |
Write to the specified file asynchronously using overlapped I/O via the threads in the supplied IIOPool using buffers provided by the caller and push any errors that occur to the CAsyncFileWriter::Callback interface. Monitor write progress using the supplied monitor. Limits the maximum number of pending writes to the supplied limit to prevent uncontrolled 'non paged pool' memory usage if log messages are produced at a rate faster than they can be written to the disk. Note that once the limit is reached all writes become synchronous until the number of pending writes has dropped below the limit again. Sets the file size to the supplied value in the constructor and then trims the file to the actual size of the written bytes when the file is closed; this allows us to work around the fact that file systems extend files synchronously. | |
CAsyncFileWriter (const JetByteTools::Core::_tstring &filename, JetByteTools::Win32::CSmartHandle &file, Callback &callback, IIOPool &pool, ILimitPendingWrites &writeLimiter=CPendingWriteLimiter::NoLimitLimiter, long flags=MarshalWritesToThreadPool, const LARGE_INTEGER &fileSize=DoNotPreExtendFile) | |
Write to the specified file asynchronously using overlapped I/O via the threads in the supplied IIOPool using buffers provided by the caller and push any errors that occur to the CAsyncFileWriter::Callback interface. Note: that the file MUST have been opened in overlapped mode! Note: takes ownership of the file, the handle will be closed when the object is destroyed. Limits the maximum number of pending writes to the supplied limit to prevent uncontrolled 'non paged pool' memory usage if log messages are produced at a rate faster than they can be written to the disk. Note that once the limit is reached all writes become synchronous until the number of pending writes has dropped below the limit again. Sets the file size to the supplied value in the constructor and then trims the file to the actual size of the written bytes when the file is closed; this allows us to work around the fact that file systems extend files synchronously. | |
CAsyncFileWriter (const JetByteTools::Core::_tstring &filename, JetByteTools::Win32::CSmartHandle &file, Callback &callback, IIOPool &pool, IMonitorAsyncFileWriter &monitor, ILimitPendingWrites &writeLimiter=CPendingWriteLimiter::NoLimitLimiter, long flags=MarshalWritesToThreadPool, const LARGE_INTEGER &fileSize=DoNotPreExtendFile) | |
Write to the specified file asynchronously using overlapped I/O via the threads in the supplied IIOPool using buffers provided by the caller and push any errors that occur to the CAsyncFileWriter::Callback interface. Monitor write progress using the supplied monitor. Note: that the file MUST have been opened in overlapped mode! Note: takes ownership of the file, the handle will be closed when the object is destroyed. Limits the maximum number of pending writes to the supplied limit to prevent uncontrolled 'non paged pool' memory usage if log messages are produced at a rate faster than they can be written to the disk. Note that once the limit is reached all writes become synchronous until the number of pending writes has dropped below the limit again. Sets the file size to the supplied value in the constructor and then trims the file to the actual size of the written bytes when the file is closed; this allows us to work around the fact that file systems extend files synchronously. | |
CAsyncFileWriter (JetByteTools::Win32::CSmartHandle &file, Callback &callback, IIOPool &pool, ILimitPendingWrites &writeLimiter=CPendingWriteLimiter::NoLimitLimiter, long flags=MarshalWritesToThreadPool, const LARGE_INTEGER &fileSize=DoNotPreExtendFile) | |
Write to the specified file asynchronously using overlapped I/O via the threads in the supplied IIOPool using buffers provided by the caller and push any errors that occur to the CAsyncFileWriter::Callback interface. Note: that the file MUST have been opened in overlapped mode! Note: takes ownership of the file, the handle will be closed when the object is destroyed. Limits the maximum number of pending writes to the supplied limit to prevent uncontrolled 'non paged pool' memory usage if log messages are produced at a rate faster than they can be written to the disk. Note that once the limit is reached all writes become synchronous until the number of pending writes has dropped below the limit again. Sets the file size to the supplied value in the constructor and then trims the file to the actual size of the written bytes when the file is closed; this allows us to work around the fact that file systems extend files synchronously. | |
CAsyncFileWriter (JetByteTools::Win32::CSmartHandle &file, Callback &callback, IIOPool &pool, IMonitorAsyncFileWriter &monitor, ILimitPendingWrites &writeLimiter=CPendingWriteLimiter::NoLimitLimiter, long flags=MarshalWritesToThreadPool, const LARGE_INTEGER &fileSize=DoNotPreExtendFile) | |
Write to the specified file asynchronously using overlapped I/O via the threads in the supplied IIOPool using buffers provided by the caller and push any errors that occur to the CAsyncFileWriter::Callback interface. Monitor write progress using the supplied monitor. Note: that the file MUST have been opened in overlapped mode! Note: takes ownership of the file, the handle will be closed when the object is destroyed. Limits the maximum number of pending writes to the supplied limit to prevent uncontrolled 'non paged pool' memory usage if log messages are produced at a rate faster than they can be written to the disk. Note that once the limit is reached all writes become synchronous until the number of pending writes has dropped below the limit again. Sets the file size to the supplied value in the constructor and then trims the file to the actual size of the written bytes when the file is closed; this allows us to work around the fact that file systems extend files synchronously. | |
CAsyncFileWriter (const CAsyncFileWriter &rhs) | |
~CAsyncFileWriter () override | |
CAsyncFileWriter & | operator= (const CAsyncFileWriter &rhs) |
bool | PerformWritesOnThisThread () const |
Returns true if writes are issued directly from the calling thread and false if they are marshalled to the thread pool. | |
void | Write (CSmartBuffer &buffer) |
Write the contents of the IBuffer to the file. | |
void | Close () |
Close the file. | |
void | NotifyOnNoWrites (bool notifyNowIfNoWritesPending=true) |
Causes the file writer to call Callback::OnLastWrite() when the count of pending writes reaches zero. If you call this and pass true for notifyNowIfNoWritesPending and there currently no outstanding writes then the callback is called immediately. Note: You may get multiple calls to OnLastWrite() for a single 'last write' completion as we don't bother to guard against the race condition between this call and the actual write completions. It's best to call this when you would otherwise call Wait(), i.e. after the last write that you intend to issue on this file writer. | |
const JetByteTools::Core::_tstring & | GetFilenameIfKnown () const |
Returns the name of the file if the file writer was created from a file name and an empty string if the file writer was created from a file handle. | |
__int64 | GetFileSize () const |
Returns the current size of the file in bytes. | |
HANDLE | GetWaitHandle () const override |
void | Wait () const override |
bool | Wait (Milliseconds timeout) const override |
Static Public Member Functions | |
static JetByteTools::Win32::CSmartHandle | OpenSuitableFile (const JetByteTools::Core::_tstring &filename, long flags=0) |
static JetByteTools::Win32::CSmartHandle | CreateSuitableFile (const JetByteTools::Core::_tstring &filename, long flags=0) |
static JetByteTools::Win32::CSmartHandle | TryCreateSuitableFile (const JetByteTools::Core::_tstring &filename, long flags=0) |
Static Public Attributes | |
static const LARGE_INTEGER | DoNotPreExtendFile |
Used to specify to the constructors that you do not wish to extend the size of the file during construction and then trim it to the correct size when all data has been written. Note that file systems extend files synchronously (See Richter 2008). By specifying a file size during construction we can extend the size of the file and allow the actual data writes to occur asynchronously. | |
Protected Member Functions | |
void | GetNextWriteOffset (LARGE_INTEGER &offset, DataLength dataLength) |
void | RequestWrite (CSmartBuffer &buffer) |
Classes | |
class | Callback |
An interface for users of the CAsyncFileWriter to be notified of any errors that occur during the asynchronous write operations on the file. More... |
typedef unsigned long DataLength |
Reimplemented in CAsyncFileWriterEx.
enum Flags |
CAsyncFileWriter | ( | const JetByteTools::Core::_tstring & | filename, | |
Callback & | callback, | |||
IIOPool & | pool, | |||
ILimitPendingWrites & | writeLimiter = CPendingWriteLimiter::NoLimitLimiter , |
|||
long | flags = MarshalWritesToThreadPool , |
|||
const LARGE_INTEGER & | fileSize = DoNotPreExtendFile | |||
) |
Write to the specified file asynchronously using overlapped I/O via the threads in the supplied IIOPool using buffers provided by the caller and push any errors that occur to the CAsyncFileWriter::Callback interface. Limits the maximum number of pending writes to the supplied limit to prevent uncontrolled 'non paged pool' memory usage if log messages are produced at a rate faster than they can be written to the disk. Note that once the limit is reached all writes become synchronous until the number of pending writes has dropped below the limit again. Sets the file size to the supplied value in the constructor and then trims the file to the actual size of the written bytes when the file is closed; this allows us to work around the fact that file systems extend files synchronously.
CAsyncFileWriter | ( | const JetByteTools::Core::_tstring & | filename, | |
Callback & | callback, | |||
IIOPool & | pool, | |||
IMonitorAsyncFileWriter & | monitor, | |||
ILimitPendingWrites & | writeLimiter = CPendingWriteLimiter::NoLimitLimiter , |
|||
long | flags = MarshalWritesToThreadPool , |
|||
const LARGE_INTEGER & | fileSize = DoNotPreExtendFile | |||
) |
Write to the specified file asynchronously using overlapped I/O via the threads in the supplied IIOPool using buffers provided by the caller and push any errors that occur to the CAsyncFileWriter::Callback interface. Monitor write progress using the supplied monitor. Limits the maximum number of pending writes to the supplied limit to prevent uncontrolled 'non paged pool' memory usage if log messages are produced at a rate faster than they can be written to the disk. Note that once the limit is reached all writes become synchronous until the number of pending writes has dropped below the limit again. Sets the file size to the supplied value in the constructor and then trims the file to the actual size of the written bytes when the file is closed; this allows us to work around the fact that file systems extend files synchronously.
CAsyncFileWriter | ( | const JetByteTools::Core::_tstring & | filename, | |
JetByteTools::Win32::CSmartHandle & | file, | |||
Callback & | callback, | |||
IIOPool & | pool, | |||
ILimitPendingWrites & | writeLimiter = CPendingWriteLimiter::NoLimitLimiter , |
|||
long | flags = MarshalWritesToThreadPool , |
|||
const LARGE_INTEGER & | fileSize = DoNotPreExtendFile | |||
) |
Write to the specified file asynchronously using overlapped I/O via the threads in the supplied IIOPool using buffers provided by the caller and push any errors that occur to the CAsyncFileWriter::Callback interface. Note: that the file MUST have been opened in overlapped mode! Note: takes ownership of the file, the handle will be closed when the object is destroyed. Limits the maximum number of pending writes to the supplied limit to prevent uncontrolled 'non paged pool' memory usage if log messages are produced at a rate faster than they can be written to the disk. Note that once the limit is reached all writes become synchronous until the number of pending writes has dropped below the limit again. Sets the file size to the supplied value in the constructor and then trims the file to the actual size of the written bytes when the file is closed; this allows us to work around the fact that file systems extend files synchronously.
CAsyncFileWriter | ( | const JetByteTools::Core::_tstring & | filename, | |
JetByteTools::Win32::CSmartHandle & | file, | |||
Callback & | callback, | |||
IIOPool & | pool, | |||
IMonitorAsyncFileWriter & | monitor, | |||
ILimitPendingWrites & | writeLimiter = CPendingWriteLimiter::NoLimitLimiter , |
|||
long | flags = MarshalWritesToThreadPool , |
|||
const LARGE_INTEGER & | fileSize = DoNotPreExtendFile | |||
) |
Write to the specified file asynchronously using overlapped I/O via the threads in the supplied IIOPool using buffers provided by the caller and push any errors that occur to the CAsyncFileWriter::Callback interface. Monitor write progress using the supplied monitor. Note: that the file MUST have been opened in overlapped mode! Note: takes ownership of the file, the handle will be closed when the object is destroyed. Limits the maximum number of pending writes to the supplied limit to prevent uncontrolled 'non paged pool' memory usage if log messages are produced at a rate faster than they can be written to the disk. Note that once the limit is reached all writes become synchronous until the number of pending writes has dropped below the limit again. Sets the file size to the supplied value in the constructor and then trims the file to the actual size of the written bytes when the file is closed; this allows us to work around the fact that file systems extend files synchronously.
CAsyncFileWriter | ( | JetByteTools::Win32::CSmartHandle & | file, | |
Callback & | callback, | |||
IIOPool & | pool, | |||
ILimitPendingWrites & | writeLimiter = CPendingWriteLimiter::NoLimitLimiter , |
|||
long | flags = MarshalWritesToThreadPool , |
|||
const LARGE_INTEGER & | fileSize = DoNotPreExtendFile | |||
) |
Write to the specified file asynchronously using overlapped I/O via the threads in the supplied IIOPool using buffers provided by the caller and push any errors that occur to the CAsyncFileWriter::Callback interface. Note: that the file MUST have been opened in overlapped mode! Note: takes ownership of the file, the handle will be closed when the object is destroyed. Limits the maximum number of pending writes to the supplied limit to prevent uncontrolled 'non paged pool' memory usage if log messages are produced at a rate faster than they can be written to the disk. Note that once the limit is reached all writes become synchronous until the number of pending writes has dropped below the limit again. Sets the file size to the supplied value in the constructor and then trims the file to the actual size of the written bytes when the file is closed; this allows us to work around the fact that file systems extend files synchronously.
CAsyncFileWriter | ( | JetByteTools::Win32::CSmartHandle & | file, | |
Callback & | callback, | |||
IIOPool & | pool, | |||
IMonitorAsyncFileWriter & | monitor, | |||
ILimitPendingWrites & | writeLimiter = CPendingWriteLimiter::NoLimitLimiter , |
|||
long | flags = MarshalWritesToThreadPool , |
|||
const LARGE_INTEGER & | fileSize = DoNotPreExtendFile | |||
) |
Write to the specified file asynchronously using overlapped I/O via the threads in the supplied IIOPool using buffers provided by the caller and push any errors that occur to the CAsyncFileWriter::Callback interface. Monitor write progress using the supplied monitor. Note: that the file MUST have been opened in overlapped mode! Note: takes ownership of the file, the handle will be closed when the object is destroyed. Limits the maximum number of pending writes to the supplied limit to prevent uncontrolled 'non paged pool' memory usage if log messages are produced at a rate faster than they can be written to the disk. Note that once the limit is reached all writes become synchronous until the number of pending writes has dropped below the limit again. Sets the file size to the supplied value in the constructor and then trims the file to the actual size of the written bytes when the file is closed; this allows us to work around the fact that file systems extend files synchronously.
CAsyncFileWriter | ( | const CAsyncFileWriter & | rhs | ) |
~CAsyncFileWriter | ( | ) | [override] |
static JetByteTools::Win32::CSmartHandle OpenSuitableFile | ( | const JetByteTools::Core::_tstring & | filename, | |
long | flags = 0 | |||
) | [static] |
static JetByteTools::Win32::CSmartHandle CreateSuitableFile | ( | const JetByteTools::Core::_tstring & | filename, | |
long | flags = 0 | |||
) | [static] |
static JetByteTools::Win32::CSmartHandle TryCreateSuitableFile | ( | const JetByteTools::Core::_tstring & | filename, | |
long | flags = 0 | |||
) | [static] |
CAsyncFileWriter& operator= | ( | const CAsyncFileWriter & | rhs | ) |
bool PerformWritesOnThisThread | ( | ) | const |
Returns true if writes are issued directly from the calling thread and false if they are marshalled to the thread pool.
void Write | ( | CSmartBuffer & | buffer | ) |
Write the contents of the IBuffer to the file.
void Close | ( | ) |
Close the file.
void NotifyOnNoWrites | ( | bool | notifyNowIfNoWritesPending = true |
) |
Causes the file writer to call Callback::OnLastWrite() when the count of pending writes reaches zero. If you call this and pass true for notifyNowIfNoWritesPending and there currently no outstanding writes then the callback is called immediately. Note: You may get multiple calls to OnLastWrite() for a single 'last write' completion as we don't bother to guard against the race condition between this call and the actual write completions. It's best to call this when you would otherwise call Wait(), i.e. after the last write that you intend to issue on this file writer.
const _tstring & GetFilenameIfKnown | ( | ) | const |
Returns the name of the file if the file writer was created from a file name and an empty string if the file writer was created from a file handle.
__int64 GetFileSize | ( | ) | const |
Returns the current size of the file in bytes.
HANDLE GetWaitHandle | ( | ) | const [override] |
void Wait | ( | ) | const [override] |
bool Wait | ( | Milliseconds | timeout | ) | const [override] |
void GetNextWriteOffset | ( | LARGE_INTEGER & | offset, | |
DataLength | dataLength | |||
) | [protected] |
void RequestWrite | ( | CSmartBuffer & | buffer | ) | [protected] |
const LARGE_INTEGER DoNotPreExtendFile [static] |
Used to specify to the constructors that you do not wish to extend the size of the file during construction and then trim it to the correct size when all data has been written. Note that file systems extend files synchronously (See Richter 2008). By specifying a file size during construction we can extend the size of the file and allow the actual data writes to occur asynchronously.