/
sharedstream.yo
159 lines (131 loc) · 7.04 KB
/
sharedstream.yo
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
includefile(include/header)
COMMENT(manpage, section, releasedate, archive, short name)
manpage(FBB::SharedStream)(3bobcat)(_CurYrs_)(libbobcat-dev__CurVers_-x.tar.gz)
(I/O on shared memory)
manpagename(FBB::SharedStream)(I/O operations on shared memory)
manpagesynopsis()
bf(#include <bobcat/sharedstream>)nl()
Linking option: tt(-lpthread -lbobcat)
manpagedescription()
This class combines the features of the bf(std::istream) and
bf(std::ostream) classes, operating on shared memory. As with tt(std::fstream)
objects, a tt(seekp) or tt(seekg) member call is required to switch from
writing to reading or v.v.
includefile(include/namespace)
manpagesection(INHERITS FROM)
bf(FBB::SharedStreambuf) (private inheritance),nl()
bf(std::istream),nl()
bf(std::ostream),nl()
bf(FBB::SharedEnum__) (cf. bf(sharedmemory)(3bobcat) for a description of
this last base class).
manpagesection(CONSTRUCTORS)
itemization(
itb(SharedStream())
The default constructor defines a stub a bf(SharedStream) object that
cannot immediately be used to access shared memory. To use it, its
member tt(open) must first be called.
itb(SharedStream(size_t maxSize, SizeUnit sizeUnit,
std::ios::openmode openMode = std::ios::in | std::ios::out,
size_t access = 0600))
This constructor creates a stream inheriting the facilities of an
tt(std::istream) and tt(std::ostream) that interfaces to a shared
memory segment having a capacity of at least tt(maxSize * sizeUnit)
bytes. By default, the shared memory segment is opened for reading and
writing. Different from the open modes used for file streams, creating
a shared memory stream with open modes tt(ios::in | ios::out) is
OK. In this case the shared memory segment is created and once
information has been written to the shared memory it can also be read
again. The shared memory's access rights are defined by the tt(access)
parameter, using the well-known (bf(chmod)(1)) way to define the
access rights for the owner, the group and others, using octal
digits. If construction succeeds the shared memory is ready for
use. If construction fails, an tt(FBB::Exception) is thrown.
itb(SharedStream(int id, std::ios::openmode openMode = std::ios::in |
std::ios::out))
This constructor creates a stream inheriting the facilities of an
tt(std::istream) and tt(std::ostream) that connects to a shared memory
segment having ID tt(id). If construction succeeds the shared memory
is ready for use. If construction fails (e.g., no shared memory
segment having ID tt(id) exists), an tt(FBB::Exception) is
thrown. Specifying the tt(ios::trunc) flag immediately clears the
contents of the shared memory.
)
Copy and move constructors are not available.
manpagesection(OVERLOADED OPERATORS)
The overloaded move and copy assignment operators are not available.
manpagesection(MEMBER FUNCTIONS)
All members of tt(std::istream) and tt(std::ostream) and the tt(enum)
values tt(kB, MB), and tt(GB), defined by tt(FBB::SharedEnum__) are available.
itemization(
itb(void clear())
This member clears the error states of the tt(std::istream)
and tt(std::ostream) base class objects.
itb(int id() const)
The ID of the shared memory segment is returned.
itb(void kill())
Without locking the shared memory first, all shared memory is returned
to the operating system. The bf(FBB::SharedStream) object is unusable
after returning from tt(kill). Other processes that were using the
shared memory can continue to do so.
itb(void remove())
The shared memory is first locked. Next, all shared memory is returned
to the operating system. The bf(FBB::SharedStream) object is unusable
after returning from tt(remove). Other processes that were using the
shared memory can continue to do so.
itb(void memInfo(std::ostream &out, char const *end = "\n"))
Information about the tt(SharedMemory) object is inserted into the
provide tt(ostream) object. The IDs of the shared segments, their
sizes, the maximum number of shared memory segments, the number of
bytes that can be read from the shared memory, and its actual storage
capacity, etc., are displayed. Following the information about the
shaed memory, tt(end) is inserted into tt(out).
itb(void open(size_t maxSize, SizeUnit sizeUnit,
std::ios::openmode openMode = std::ios::in | std::ios::out,
size_t access = 0600))
This member creates a shared memory segment having a capacity of at
least tt(maxSize * sizeUnit) bytes, and connects the shared memory
segment to the bf(FBB::SharedStream). A matching tt(close) member does
not exist and is not required. By default, the shared memory segment
is opened for reading and writing. Different from the open modes used
for file streams, creating a shared memory stream with open modes
tt(ios::in | ios::out) is OK. In this case the shared memory segment
is created and once information has been written to the shared memory
it can also be read again. The shared memory's access rights are
defined by the tt(access) parameter, using the well-known
(bf(chmod)(1)) way to define the access rights for the owner, the
group and others, using octal digits. If opening succeeds the shared
memory is ready for use. If opening fails, an tt(FBB::Exception) is
thrown.
itb(void open(int id, std::ios::openmode openMode = std::ios::in |
std::ios::out))
This member connects the bf(FBB::SharedStream) object to a shared
memory segment having ID tt(id). A matching tt(close) member does
not exist and is not required. If opening succeeds the shared
memory is ready for use. If opening fails (e.g., no shared memory
segment having ID tt(id) exists), an tt(FBB::Exception) is
thrown. Specifying the tt(ios::trunc) flag immediately clears the
contents of the shared memory.
)
manpagesection(EXAMPLE)
verbinclude(../../sharedstream/driver/driver.cc)
manpagefiles()
em(bobcat/sharedstream) - defines the class interface
manpageseealso()
bf(bobcat)(7), bf(chmod)(1),
bf(isharedstream)(3bobcat),
bf(osharedstream)(3bobcat),
bf(sharedblock)(3bobcat),
bf(sharedmemory)(3bobcat)
bf(sharedmutex)(3bobcat),
bf(sharedpos)(3bobcat),
bf(sharedsegment)(3bobcat),
bf(sharedstreambuf)(3bobcat)
manpagebugs()
Note that by default exceptions thrown from within a bf(std::stream)
object are caught by the stream object, setting its tt(ios::failbit) flag. To
allow exceptions to leave a stream object, its tt(exceptions) member can be
called, e.g., using:
verb(
myStream.exceptions(ios::failbit | ios::badbit | ios::eofbit);
)
includefile(include/trailer)