]> git.ipfire.org Git - thirdparty/squid.git/blame - src/ipc/mem/Segment.h
Use size_t instead of unsigned int for the page size to prevent int overflows
[thirdparty/squid.git] / src / ipc / mem / Segment.h
CommitLineData
f5eef98c
DK
1/*
2 * $Id$
3 *
4 */
5
d8a82533
AR
6#ifndef SQUID_IPC_MEM_SEGMENT_H
7#define SQUID_IPC_MEM_SEGMENT_H
f5eef98c
DK
8
9#include "SquidString.h"
10
d8a82533
AR
11namespace Ipc {
12
13namespace Mem {
14
f5eef98c 15/// POSIX shared memory segment
d8a82533 16class Segment {
f5eef98c 17public:
f1eaa254 18 /// Create a shared memory segment.
d8a82533
AR
19 Segment(const char *const id);
20 ~Segment();
f5eef98c
DK
21
22 /// Create a new shared memory segment. Fails if a segment with
23 /// the same name already exists.
24 void create(const int aSize);
25 void open(); ///< Open an existing shared memory segment.
26
27 const String &name() { return theName; } ///< shared memory segment name
28 int size() { return theSize; } ///< shared memory segment size
29 void *mem() { return theMem; } ///< pointer to mmapped shared memory segment
937d0d3f
AR
30 void *reserve(size_t chunkSize); ///< reserve and return the next chunk
31 // TODO: convert most mem() calls to reserve()
f5eef98c
DK
32
33private:
34 void attach();
35 void detach();
36
9a51593d 37 static String GenerateName(const char *id);
f5eef98c
DK
38
39 const String theName; ///< shared memory segment file name
40 int theFD; ///< shared memory segment file descriptor
f5eef98c 41 void *theMem; ///< pointer to mmapped shared memory segment
937d0d3f
AR
42 size_t theSize; ///< shared memory segment size
43 size_t theReserved; ///< the total number of reserve()d bytes
f5eef98c
DK
44};
45
d8a82533
AR
46} // namespace Mem
47
48} // namespace Ipc
49
50#endif /* SQUID_IPC_MEM_SEGMENT_H */