]> git.ipfire.org Git - thirdparty/squid.git/blame - src/fs/rock/RockHeaderUpdater.h
SourceFormat Enforcement
[thirdparty/squid.git] / src / fs / rock / RockHeaderUpdater.h
CommitLineData
abf396ec 1/*
4ac4a490 2 * Copyright (C) 1996-2017 The Squid Software Foundation and contributors
abf396ec
AR
3 *
4 * Squid software is distributed under GPLv2+ license and includes
5 * contributions from numerous individuals and organizations.
6 * Please see the COPYING and CONTRIBUTORS files for details.
7 */
8
9#ifndef SQUID_FS_ROCK_HEADER_UPDATER_H
10#define SQUID_FS_ROCK_HEADER_UPDATER_H
11
12#include "base/AsyncJob.h"
13#include "cbdata.h"
14#include "fs/rock/forward.h"
15#include "fs/rock/RockSwapDir.h"
16#include "ipc/StoreMap.h"
17
18namespace Rock
19{
20
21/// Updates HTTP headers of a single Rock store entry:
22/// * reads old body data in the same slot as the last old headers slot, if any
23/// * writes new headers (1+ slots)
24/// * writes old data (0-2 slots)
25/// * chains the new entry prefix (1+ slots) to the old entry suffix (0+ slots)
26class HeaderUpdater: public AsyncJob
27{
1625e4a1 28 CBDATA_CHILD(HeaderUpdater);
abf396ec
AR
29
30public:
31 HeaderUpdater(const Rock::SwapDir::Pointer &aStore, const Ipc::StoreMapUpdate &update);
32 virtual ~HeaderUpdater() override = default;
33
34protected:
35 /* AsyncJob API */
36 virtual void start() override;
37 virtual bool doneAll() const override;
38 virtual void swanSong() override;
39
40private:
41 static StoreIOState::STRCB NoteRead;
42 static StoreIOState::STIOCB NoteDoneReading;
43 static StoreIOState::STIOCB NoteDoneWriting;
44
45 void startReading();
46 void stopReading(const char *why);
47 void readMore(const char *why);
48 void noteRead(ssize_t result);
49 void noteDoneReading(int errflag);
50 void parseReadBytes();
51
52 void startWriting();
53 void noteDoneWriting(int errflag);
54
55 Rock::SwapDir::Pointer store; ///< cache_dir where the entry is stored
56 Ipc::StoreMapUpdate update; ///< Ipc::StoreMap update reservation
57
58 StoreIOState::Pointer reader; ///< reads old headers and old data
59 StoreIOState::Pointer writer; ///< writes new headers and old data
60
61 SBuf readerBuffer; ///< I/O buffer for a single read operation
62 SBuf exchangeBuffer; ///< bytes read but not yet discarded or written
63 uint64_t bytesRead; ///< total entry bytes read from Store so far
64
65 int staleSwapHeaderSize; ///< stored size of the stale entry metadata
66
67 SlotId staleSplicingPointNext; ///< non-updatable old HTTP body suffix start
68};
69
70} // namespace Rock
71
72#endif /* SQUID_FS_ROCK_HEADER_UPDATER_H */
73