Header only.
Link with -lrt
for mmap.
mkdir build
cd build
cmake ..
make
make install
make examples
Full demo in examples/cpp_ipc_demo/.
#include "ipc/ipc.h"
...
ipc_writer<my_struct> writer("my_topic");
while (1)
{
// create / obtain entry
my_struct entry = { .field = 1 };
writer.write(entry);
}
#include "ipc/ipc.h"
...
ipc_reader<my_struct> reader("my_topic");
while (1)
{
my_struct entry;
if (reader.read(entry) == 0)
{
// use entry
int field = entry.field;
}
}
When using the ring queue-based data structure exposed through ipc_reader_rq
,
the reader should read all available elements to avoid exhaustion in case the writer is
quicker than the reader.
This can be achieved simply by changing the if statement above to a while loop:
#include "ipc/ipc.h"
...
ipc_reader_rq<my_struct> reader("my_topic");
while (1)
{
my_struct entry;
while (reader.read(entry) == 0)
{
// use entry
int field = entry.field;
}
}
This example uses the helper methods ipc_write
/ ipc_read
, which contain static declared instances of the ipc objects,
so that the shared memory is allocated / mapped on the first call of ipc_write
/ ipc_read
with a new entry type or id.
Full demo in examples/cpp_ipc_brief_demo/.
#include "ipc/ipc.h"
...
while (1)
{
// create / obtain entry
my_struct entry = { .field = 1 };
ipc_write(entry, "my_topic");
}
#include "ipc/ipc.h"
...
while (1)
{
my_struct entry;
if (ipc_read(entry, "my_topic") == 0)
{
// use entry
int field = entry.field;
}
}
A debugging interface is exposed in include/ipc/debug.h . It is used internally, but output is off by default.
Configure the debugging output by defining debug_stdout
and debug_stderr
to the wanted file descriptors before including ipc.h
:
#define debug_stdout stdout
#define debug_stderr stderr
#include "ipc/ipc.h"