libmoost
|
async_writer is a class that simplifies the mechanics of writing to a file asynchronously. More...
#include <async_writer.hpp>
Public Member Functions | |
async_writer (const std::string &base_path, const TRolloverPolicy &rollover_policy=TRolloverPolicy(), size_t max_queue=0, size_t enqueue_timeout=0) | |
Constructs an async_writer. | |
~async_writer () | |
void | stop () |
Protected Member Functions | |
void | do_work (TWork &work) |
Override this method and do your work here. | |
Private Member Functions | |
void | reload_out () |
open a new file to write | |
Private Attributes | |
std::string | m_base_path |
TRolloverPolicy | m_rollover_policy |
std::ofstream | m_out |
async_writer is a class that simplifies the mechanics of writing to a file asynchronously.
To use it, you must provide a template parameter, and the template type must implement the method: write(std::ostream & out)
Definition at line 140 of file async_writer.hpp.
moost::io::async_writer< TWork, TRolloverPolicy >::async_writer | ( | const std::string & | base_path, |
const TRolloverPolicy & | rollover_policy = TRolloverPolicy() , |
||
size_t | max_queue = 0 , |
||
size_t | enqueue_timeout = 0 |
||
) | [inline] |
Constructs an async_writer.
base_path | the base path name for file creation (unix time is appended) |
max_queue | the maximum length the queue may grow before further enqueue's begin to wait (default don't wait) |
enqueue_timeout | the longest amount of time an enqueue may wait (-1 means wait forever) |
Definition at line 188 of file async_writer.hpp.
moost::io::async_writer< TWork, TRolloverPolicy >::~async_writer | ( | ) | [inline] |
Destroys the async_writer
It's safe to destroy the async_writer without first calling stop(). It will shut down cleanly.
Definition at line 202 of file async_writer.hpp.
void moost::io::async_writer< TWork, TRolloverPolicy >::do_work | ( | TWork & | work | ) | [inline, protected, virtual] |
Override this method and do your work here.
Implements moost::thread::async_worker< TWork >.
Definition at line 173 of file async_writer.hpp.
void moost::io::async_writer< TWork, TRolloverPolicy >::reload_out | ( | ) | [inline, private] |
open a new file to write
Definition at line 149 of file async_writer.hpp.
void moost::io::async_writer< TWork, TRolloverPolicy >::stop | ( | ) | [inline] |
Reimplemented from moost::thread::async_worker< TWork >.
Definition at line 207 of file async_writer.hpp.
std::string moost::io::async_writer< TWork, TRolloverPolicy >::m_base_path [private] |
Definition at line 144 of file async_writer.hpp.
std::ofstream moost::io::async_writer< TWork, TRolloverPolicy >::m_out [private] |
Definition at line 146 of file async_writer.hpp.
TRolloverPolicy moost::io::async_writer< TWork, TRolloverPolicy >::m_rollover_policy [private] |
Definition at line 145 of file async_writer.hpp.