|
LeftHookRoll
An HTTP/1.0 compliant web server, as specified by RFC1945
|
#include <DataStore.hpp>
Public Member Functions | |
| DataStore () | |
| DataStore (const DataStore &other) | |
| DataStore & | operator= (DataStore other) |
| ~DataStore () | |
| void | append (const char *data, size_t length) |
| Appends raw byte data to the store. Automatically transitions from RAM to FILE_MODE if _bufferLimit is exceeded. | |
| void | append (const std::string &data) |
| Convenience overload to append a std::string directly. | |
| void | clear () |
| Resets the store, clears the vector, and closes the temp file descriptor. | |
| BufferMode | getMode () const |
| Returns the current storage mode (RAM or FILE_MODE). | |
| const std::vector< char > & | getVector () const |
| Returns a reference to the RAM buffer. | |
| int | getFd () const |
| Returns the file descriptor of the temporary file. | |
| size_t | getSize () const |
| Gets total bytes currently stored (whether in RAM or File). | |
| std::string | getFilePath () const |
| Gets the absolute path of the temporary file. | |
| size_t | read (char *buffer, size_t length) |
| Reads data from the store starting at the current read position. Advances the internal read position by the number of bytes read. | |
| void | resetReadPosition () |
| Resets the internal read position to the beginning of the data. | |
| size_t | getReadPosition () const |
| Gets the current read position. | |
| void | switchToFileMode () |
| Handles the transition from RAM to a temporary file on disk. Uses the immediate unlink() trick to ensure OS-level cleanup on crashes. | |
Private Member Functions | |
| void | _generateTempFileName () |
| Generates a unique temporary filename (e.g., FILEPREFIX_XXXXXX). | |
| void | write_all (int fd, const char *data, size_t length) |
| Ensures all data is written to the file descriptor. | |
| void | copy_fd_contents (const std::string &srcPath, int dstFd, size_t totalBytes) |
| Copies data directly from one FD to another using a buffer. | |
Private Attributes | |
| BufferMode | _mode |
| size_t | _bufferLimit |
| size_t | _currentSize |
| size_t | _readOffset |
| std::vector< char > | _dataBuffer |
| int | _fileFd |
| std::string | _absolutePath |
Definition at line 34 of file DataStore.hpp.
| DataStore::DataStore | ( | ) |
Definition at line 65 of file DataStore.cpp.
| DataStore::DataStore | ( | const DataStore & | other | ) |
Definition at line 69 of file DataStore.cpp.
| DataStore::~DataStore | ( | ) |
Definition at line 107 of file DataStore.cpp.
Definition at line 96 of file DataStore.cpp.
| void DataStore::append | ( | const char * | data, |
| size_t | length | ||
| ) |
Appends raw byte data to the store. Automatically transitions from RAM to FILE_MODE if _bufferLimit is exceeded.
| data | Pointer to the buffer to append. |
| length | Number of bytes to append. |
Definition at line 119 of file DataStore.cpp.
| void DataStore::append | ( | const std::string & | data | ) |
Convenience overload to append a std::string directly.
Definition at line 145 of file DataStore.cpp.
| void DataStore::clear | ( | ) |
Resets the store, clears the vector, and closes the temp file descriptor.
Definition at line 152 of file DataStore.cpp.
| BufferMode DataStore::getMode | ( | ) | const |
Returns the current storage mode (RAM or FILE_MODE).
Definition at line 169 of file DataStore.cpp.
| const std::vector< char > & DataStore::getVector | ( | ) | const |
Returns a reference to the RAM buffer.
Definition at line 173 of file DataStore.cpp.
| int DataStore::getFd | ( | ) | const |
Returns the file descriptor of the temporary file.
Definition at line 177 of file DataStore.cpp.
| size_t DataStore::getSize | ( | ) | const |
Gets total bytes currently stored (whether in RAM or File).
Definition at line 185 of file DataStore.cpp.
| std::string DataStore::getFilePath | ( | ) | const |
Gets the absolute path of the temporary file.
Definition at line 181 of file DataStore.cpp.
| size_t DataStore::read | ( | char * | buffer, |
| size_t | length | ||
| ) |
Reads data from the store starting at the current read position. Advances the internal read position by the number of bytes read.
| buffer | Pointer to the buffer to read into. |
| length | Maximum number of bytes to read. |
Definition at line 197 of file DataStore.cpp.
| void DataStore::resetReadPosition | ( | ) |
Resets the internal read position to the beginning of the data.
Definition at line 231 of file DataStore.cpp.
| size_t DataStore::getReadPosition | ( | ) | const |
Gets the current read position.
Definition at line 246 of file DataStore.cpp.
| void DataStore::switchToFileMode | ( | ) |
Handles the transition from RAM to a temporary file on disk. Uses the immediate unlink() trick to ensure OS-level cleanup on crashes.
Definition at line 254 of file DataStore.cpp.
|
private |
Generates a unique temporary filename (e.g., FILEPREFIX_XXXXXX).
Definition at line 277 of file DataStore.cpp.
|
private |
Ensures all data is written to the file descriptor.
Ensures all data is written to the file descriptor. Throws on any system error.
Definition at line 14 of file DataStore.cpp.
|
private |
Copies data directly from one FD to another using a buffer.
Copies data directly from one FD to another using a buffer. Throws on error.
Definition at line 32 of file DataStore.cpp.
|
private |
Definition at line 120 of file DataStore.hpp.
|
private |
Definition at line 121 of file DataStore.hpp.
|
private |
Definition at line 122 of file DataStore.hpp.
|
private |
Definition at line 123 of file DataStore.hpp.
|
private |
Definition at line 126 of file DataStore.hpp.
|
private |
Definition at line 129 of file DataStore.hpp.
|
private |
Definition at line 130 of file DataStore.hpp.