.TH "FBB::SharedBuf" "3bobcat" "2005\-2020" "libbobcat\-dev_5\&.07\&.00" "Error handler" .PP .SH "NAME" FBB::SharedBuf \- streambuf interfacing to shared memory .PP .SH "SYNOPSIS" \fB#include \fP .br Linking option: \fI\-lpthread \-lbobcat\fP .PP .SH "DESCRIPTION" This class implements a specialization of the \fBstd::streambuf\fP class, allowing stream classes (\fIstd::istream, std::ostream, FBB::ISharedStream, FBB::OSharedStream\fP and \fIFBB::SharedStream\fP) to perform I/O operations on shared memory\&. \fBFBB::SharedBuf\fP objects interface to a \fIFBB::SharedMemory\fP objects\&. .PP .SH "NAMESPACE" \fBFBB\fP .br All constructors, members, operators and manipulators, mentioned in this man\-page, are defined in the namespace \fBFBB\fP\&. .PP .SH "INHERITS FROM" \fBstd::streambuf, FBB::SharedEnum__\fP (cf\&. \fBsharedmemory(3bobcat)\fP for a description of the latter class)\&. .PP .SH "SIZEUNIT ENUMERATION" .PP The \fBenum SizeUnit\fP defines the following symbolic constants: .IP o \fBkB\fP, representing 1024 (2**10) bytes of memory; .IP o \fBMB\fP, representing 1048576 (2**20) bytes of memory; .IP o \fBGB\fP, representing 1073741824 (2**30) bytes of memory .PP .SH "CONSTRUCTORS" .IP o \fBSharedBuf()\fP: .br The default constructor defines a stub \fBSharedBuf\fP object that cannot immediately be used to access shared memory\&. Before it can be used by, shared stream classes like \fIFBB::SharedStream\fP, its member \fIsetMemory\fP must first have been called\&. .IP .IP o \fBSharedBuf(size_t maxSize, SizeUnit sizeUnit, std::ios::openmode openMode = std::ios::in | std::ios::out, size_t access = 0600)\fP: .br This constructor creates a shared memory segment having a capacity of at least \fImaxSize * sizeUnit\fP bytes\&. .IP 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 \fIios::in | ios::out\fP 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\&. .IP The shared memory\(cq\&s access rights are defined by the \fIaccess\fP parameter, interpreted as an octal value, using the well\-known (\fBchmod\fP(1)) way to define the access rights for owner, group and others\&. .IP If construction fails, an \fIFBB::Exception\fP is thrown\&. .IP .IP o \fBSharedBuf(int id, std::ios::openmode openMode = std::ios::in | std::ios::out)\fP: .br This constructor connects to a shared memory segment having ID \fIid\fP\&. .IP Specifying the \fIios::trunc\fP flag immediately clears the content of the shared memory\&. .IP An \fIFBB::Exception\fP is thrown if construction fails (e\&.g\&., no shared memory segment having ID \fIid\fP exists), .PP Copy and move constructors (and assignment operators) are not available\&. .PP .SH "MEMBER FUNCTIONS" .PP All members of \fBstd::streambuf\fP and the \fIenum\fP values \fIkB, MB\fP, and \fIGB\fP, defined by \fIFBB::SharedEnum__\fP are available\&. .PP .IP o \fBvoid clear()\fP: .br The shared memory is first locked\&. Next, all shared data segment are returned to the operating system, after which the shared memory segment is unlocked again\&. Returning from \fIclear\fP the shared memory The \fBFBB::SharedMemory\fP object is effectively re\-initialized, with \fIoffset\fP and \fInReadable\fP returning 0\&. .IP .IP o \fBint id() const\fP: .br The ID of the shared memory segment is returned\&. .IP .IP o \fBvoid kill()\fP: .br Without locking the shared memory the \fBFBB::SharedBuf\fP\(cq\&s shared memory is deleted\&. The \fBFBB::SharedBuf\fP object is unusable after returning from \fIkill\fP\&. .IP .IP o \fBvoid memInfo(std::ostream &out)\fP: .br Information about the \fISharedMemory\fP object is inserted into the provide \fIostream\fP 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\&. The inserted information is not terminated by a final newline character\&. .IP .IP o \fBvoid remove()\fP: .br The shared memory is locked, and the \fBFBB::SharedBuf\fP\(cq\&s shared memory is deleted\&. The \fBFBB::SharedBuf\fP object is unusable after returning from \fIremove\fP\&. .IP .IP o \fBvoid setMemory(SharedMemory &&tmp)\fP: .br The anonymous temporary \fISharedMemory\fP object that is passed to \fIsetMemory\fP defines the new shared memory segment to which the \fBFBB::SharedBuf\fP object interfaces\&. It can also be called to reuse a \fBFBB::SharedBuf\fP object again after calling \fIkill\fP or \fIremove\fP\&. .IP .IP o \fBFBB::SharedMemory &sharedMemory()\fP: .br A reference to the \fIFBB::SharedMemory\fP object to which the \fBFBB::SharedBuf\fP object interfaces is returned\&. .PP .SH "PROTECTED MEMBER FUNCTIONS" .PP .IP o \fBFBB::SharedCondition attachSharedCondition(std::ios::off_type offset, std::ios::seekdir origin)\fP: .br Returns an \fBFBB::SharedCondition\fP(3) object, interfacing to a shared condition variable located at offset \fIoffset\fP (relative to \fIorigin\fP) in the \fISharedMemory\fP object to which the \fBSharedStreamBuf\fP object interfaces\&. .IP An \fIFBB::Exception\fP is thrown if the \fIFBB::SharedCondition\fP object could not be constructed\&. .IP .IP o \fBFBB::SharedCondition createSharedCondition()\fP: .br Returns an \fBFBB::SharedCondition\fP(3) object, interfacing to a newly created shared condition variable which is created at the current offset of the \fISharedMemory\fP object to which the \fBSharedStream\fP object interfaces (or at the first offset of the next physical shared memory data block, cf\&. \fBsharedcondition\fP(3bobcat))\&. .IP An \fIFBB::Exception\fP is thrown if the \fIFBB::SharedCondition\fP object could not be constructed\&. .IP .IP o \fBvoid setOpenMode(std::ios::openmode flag)\fP: .br The streambuf\(cq\&s \fIopenmode\fP is changed to the settings defined by \fIflag\fP\&. This member is used by, e\&.g\&., \fISharedStream::open\fP, to adapt the \fBFBB::SharedBuf\fP\(cq\&s \fIopenmode\fP to the flags that are passed to \fIopen\fP\&. .IP .IP o \fBFBB::SharedMemory &sharedMemory()\fP: .br Returns a reference to the \fIFBB::SharedMemory\fP object to which the \fBSharedBuf\fP object interfaces\&. .PP .SH "EXAMPLE" See the \fBsharedstream\fP(3bobcat) man page\&. .PP .SH "FILES" \fIbobcat/sharedbuf\fP \- defines the class interface .PP .SH "SEE ALSO" \fBbobcat\fP(7), \fBchmod\fP(1), \fBisharedstream\fP(3bobcat), \fBosharedstream\fP(3bobcat), \fBsharedblock\fP(3bobcat), \fBsharedcondition\fP(3bobcat), \fBsharedmemory\fP(3bobcat) \fBsharedmutex\fP(3bobcat), \fBsharedpos\fP(3bobcat), \fBsharedreadme\fP(7bobcat), \fBsharedsegment\fP(3bobcat), \fBsharedstream\fP(3bobcat) .PP .SH "BUGS" Note that by default exceptions thrown from within a \fBstd::stream\fP object are caught by the stream object, setting its \fIios::failbit\fP flag\&. To allow exceptions to leave a stream object, its \fIexceptions\fP member can be called, e\&.g\&., using: .nf myStream\&.exceptions(ios::failbit | ios::badbit | ios::eofbit); .fi .PP .SH "BOBCAT PROJECT FILES" .PP .IP o \fIhttps://fbb\-git\&.gitlab\&.io/bobcat/\fP: gitlab project page; .IP o \fIbobcat_5\&.07\&.00\-x\&.dsc\fP: detached signature; .IP o \fIbobcat_5\&.07\&.00\-x\&.tar\&.gz\fP: source archive; .IP o \fIbobcat_5\&.07\&.00\-x_i386\&.changes\fP: change log; .IP o \fIlibbobcat1_5\&.07\&.00\-x_*\&.deb\fP: debian package containing the libraries; .IP o \fIlibbobcat1\-dev_5\&.07\&.00\-x_*\&.deb\fP: debian package containing the libraries, headers and manual pages; .PP .SH "BOBCAT" Bobcat is an acronym of `Brokken\(cq\&s Own Base Classes And Templates\(cq\&\&. .PP .SH "COPYRIGHT" This is free software, distributed under the terms of the GNU General Public License (GPL)\&. .PP .SH "AUTHOR" Frank B\&. Brokken (\fBf\&.b\&.brokken@rug\&.nl\fP)\&. .PP