diff options
Diffstat (limited to 'src/libdisfluid/disfluid-cache-entry.h')
-rw-r--r-- | src/libdisfluid/disfluid-cache-entry.h | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/src/libdisfluid/disfluid-cache-entry.h b/src/libdisfluid/disfluid-cache-entry.h index ca4f743..1c06537 100644 --- a/src/libdisfluid/disfluid-cache-entry.h +++ b/src/libdisfluid/disfluid-cache-entry.h @@ -26,6 +26,9 @@ ao_cache_entry_push (int fd, size_t *offset, const string_desc_t response_header, const string_desc_t response_body); +MAYBE_UNUSED static int +ao_cache_entry_invalidate (int fd, size_t offset, size_t *invalidated_offset); + # include "disfluid-append-only-file.h" # include "safe-alloc.h" @@ -355,4 +358,39 @@ ao_cache_entry_push (int fd, size_t *offset, } return 0; } + +static int +ao_cache_entry_invalidate (int fd, size_t offset, size_t *invalidated_offset) +{ + struct cache_entry_header header; + uint8_t header_bytes[12 * 2 + 16 * 3 + 1 + 7] = { 0 }; + string_desc_t data = {._nbytes = sizeof (header_bytes),._data = header_bytes + }; + *invalidated_offset = offset; + if (ao_file_read (fd, offset, data) < 0) + { + return -1; + } + if (ao_cache_entry_from_bytes (header_bytes, &header) < 0) + { + return -1; + } + if (header.invalidated) + { + return 0; + } + header.invalidated = true; + /* Push just the header, reuse the memory for key, response header + and body. */ + if (ao_cache_entry_to_bytes (&header, header_bytes) < 0) + { + return -1; + } + if (ao_file_push_data (fd, data, invalidated_offset) < 0) + { + return -1; + } + return 0; +} + #endif /* DISFLUID_DISFLUID_CACHE_ENTRY_INCLUDED */ |