Skip to content

Commit

Permalink
Ready for 3.18.00
Browse files Browse the repository at this point in the history
  • Loading branch information
fbb-git committed Nov 18, 2013
1 parent 11aa490 commit a992cfb
Show file tree
Hide file tree
Showing 16 changed files with 556 additions and 52 deletions.
3 changes: 0 additions & 3 deletions bobcat/TODO
Expand Up @@ -3,6 +3,3 @@ Provide examples in the following man-pages:
ifdstreambuf.yo
milter.yo
ofdstreambuf.yo

./sharedpos

2 changes: 2 additions & 0 deletions bobcat/changelog
Expand Up @@ -10,6 +10,8 @@ bobcat (3.18.00)
* The nested class MailHeaders::const_hdr_iterator is used in the public
interface: it is now declared in the public interface as well.

-- Frank B. Brokken <f.b.brokken@rug.nl> Mon, 18 Nov 2013 12:26:47 +0100

bobcat (3.17.00)

* New split members added to the String class, removing the private split
Expand Down
32 changes: 16 additions & 16 deletions bobcat/documentation/man/isharedstream.yo
Expand Up @@ -34,24 +34,24 @@ manpagesection(CONSTRUCTORS)
itb(ISharedStream(size_t maxSize, SizeUnit sizeUnit,
std::ios::openmode openMode = std::ios::in,
size_t access = 0600))
This constructor creates a shared memory segment having a capacity of
at least tt(maxSize * sizeUnit) bytes. By default, the shared memory
segment is opened for reading. Different from the open modes used for
file streams, creating a shared memory stream with open modes
tt(ios::in) is OK. In this case the shared memory segment is created
and once information has been written to the shared memory by another
process (or object) the information can be read. 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.
This constructor creates an tt(std::istream) 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. Different from the open modes used for file streams, creating
a shared memory stream with open modes tt(ios::in) is OK. In this case
the shared memory segment is created and once information has been
written to the shared memory by another process (or object) the
information can be read. 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(ISharedStream(int id, std::ios::openmode openMode = std::ios::in))
This constructor 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.
This constructor creates an tt(std::istream) 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.
)
Copy and move constructors are not available.

Expand Down
24 changes: 12 additions & 12 deletions bobcat/documentation/man/osharedstream.yo
Expand Up @@ -35,21 +35,21 @@ manpagesection(CONSTRUCTORS)
itb(OSharedStream(size_t maxSize, SizeUnit sizeUnit,
std::ios::openmode openMode = std::ios::out,
size_t access = 0600))
This constructor creates a shared memory segment having a capacity of
at least tt(maxSize * sizeUnit) bytes. By default, the shared memory
segment is opened for writing. 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.
This constructor creates an 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
writing. 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(OSharedStreambuf(int id, std::ios::openmode openMode = std::ios::out |
std::ios::in))
This constructor 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.
This constructor creates an tt(std::istream) 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.
)
Copy and move constructors are not available.

Expand Down
41 changes: 22 additions & 19 deletions bobcat/documentation/man/sharedstream.yo
Expand Up @@ -37,27 +37,29 @@ manpagesection(CONSTRUCTORS)
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 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.
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 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.
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.

Expand Down Expand Up @@ -128,7 +130,8 @@ values tt(kB, MB), and tt(GB), defined by tt(FBB::SharedEnum__) are available.
)

manpagesection(EXAMPLE)
TO DO

verbinclude(../../sharedstream/driver/driver.cc)

manpagefiles()
em(bobcat/sharedstream) - defines the class interface
Expand Down
2 changes: 1 addition & 1 deletion bobcat/sharedmemory/write.cc
Expand Up @@ -28,7 +28,7 @@ int SharedMemory::write(char const *data, streamsize len)
//cerr << "Next offset: " << d_pos.offset() << ", len = " << len << '\n';
}

cerr << ".write wrote " << (d_pos.offset() - begin) << " chars\n";
//cerr << ".write wrote " << (d_pos.offset() - begin) << " chars\n";

return d_pos.offset() - begin;
}
22 changes: 22 additions & 0 deletions bobcat/sharedstream/driver/build
@@ -0,0 +1,22 @@
#!/bin/bash

sed 's?<bobcat/sharedstream>?"../sharedstream"?' driver.cc > localdriver.cc

for x in sharedstream sharedmutex sharedstreambuf sharedmemory \
sharedpos sharedsegment
do
echo $x
cd ../../$x
g++ --std=c++11 -Wall -pthread -c *.cc
cd ../sharedstream/driver
done

echo driver

g++ -o driver --std=c++11 -Wall localdriver.cc ../../shared*/*.o \
-lpthread -lbobcat

rm ../../shared*/*.o localdriver.cc

echo Start ./driver for an interactive menu.
echo Optionally remove ./driver after the demo-run
Binary file added bobcat/sharedstream/driver/driver
Binary file not shown.
188 changes: 188 additions & 0 deletions bobcat/sharedstream/driver/driver.cc
@@ -0,0 +1,188 @@
#include <iostream>
#include <string>
#include <ostream>
#include <istream>

#include <bobcat/exception>
#include <bobcat/sharedstream>

using namespace std;
using namespace FBB;

int main()
{
SharedStream shared;

int id = -1;

while (true)
{
cout <<
"\n"
" K kill (no lock) existing shared segment\n"
" R remove existing shared segment\n"
" S show stats of current shared segment\n"
" L <id> Load segment <id>\n"
" c create new shared memory (sets id)\n"
" l lock segment id until key pressed\n"
" p <x> c put char c at offset x\n"
" q quit\n"
" r <x> <n> read n chars from offset x\n"
" w <x> args write all args at offset x\n"
"? ";

char ch;
cin >> ch;

ios::off_type offset;

cout << "Requested: " << ch << '\n';

shared.clear();

switch (ch)
{
case 'c':
{
shared.open(1, SharedStream::kB);

id = shared.id();
cout << "id = " << id << '\n';
shared.memInfo(cout);
cout << '\n';
}
break;

case 'K': // delete segment
case 'R': // delete segment
{
if (id == -1)
{
cout << "No segment loaded\n";
continue;
}

cout << "Removing segment id = " << id << '\n';
if (ch == 'R')
shared.remove();
else
shared.kill();

id = -1;
}
break;

case 'L':
cin >> id;
cout << "Loading segment " << id << '\n';
shared.open(id);
shared.memInfo(cout);
cout << '\n';
break;

case 'S':
if (id == -1)
{
cout << "No segment loaded\n";
continue;
}
shared.memInfo(cout);
cout << '\n';
break;

case 'p': // put a char behind the last written
{
if (id == -1)
{
cout << "No segment loaded\n";
continue;
}

cin >> offset >> ch;
if (!cin)
throw Exception() << "cmd specification error";

shared.seekp(offset);
cout << "Segment id = " << id << " at write offset " <<
shared.tellp() << '\n';
shared.put(ch);
}
break;

case 'r': // put a char behind the last written
{
if (id == -1)
{
cout << "No segment loaded\n";
continue;
}

int n;

cin >> offset >> n;
if (!cin)
throw Exception() << "cmd specification error";

char buf[n];

shared.seekg(offset);
cout << "Segment id = " << id << " at offset " <<
shared.tellg() << ", to read " << n << " bytes\n";

n = shared.read(buf, n).gcount();

if (n < 0)
cout << "No data at " << offset << '\n';
else
{
cout << "Retrieved " << n << " bytes, containing `";
cout.write(buf, n);
cout << "'\n";

for (auto ch: buf)
cout << static_cast<int>(ch) << ' ';
cout << '\n';
}
}
break;

case 'w': // write chars at offset
{
if (id == -1)
{
cout << "No segment loaded\n";
continue;
}

string line;

cin >> offset;
getline(cin, line);
if (!cin)
throw Exception() << "cmd specification error";

streampos pos = shared.seekp(offset).tellp();

cout << "Segment id = " << id << " at offset " <<
pos << ", to write " << line.length() << " bytes\n";


shared.write(line.data(), line.length());

if (!shared)
cout << "No room left to write any bytes\n";
else
cout << "Wrote " << (shared.tellp() - pos) << " bytes\n";
}
break;

case 'q':
return 0;

default:
cout << "request not implemented: " << ch << '\n';
break;
}
}
}

0 comments on commit a992cfb

Please sign in to comment.