shmempipe  0.1
shared memory pipe between processes
 All Classes Functions Variables Pages
shmempipe API user's manual

This is the user's manual for the shmempipe API.Interesting data structures are:

sample code

#define SHMEMFILE "SHMEMPIPE"
#define FIFOMASTERSLAVE "FIFOMASTERSLAVE"
#define FIFOSLAVEMASTER "FIFOSLAVEMASTER"
struct MyTestMsg : public shmempipeMessage
{
static MyTestMsg * allocSize(shmempipe * pPipe) {
MyTestMsg * ret;
ret = (MyTestMsg *) pPipe->allocSize(sizeof(MyTestMsg), -1);
ret->messageSize = sizeof(MyTestMsg);
return ret;
}
static const int max_size = 184;
int seqno;
char data[max_size];
};
bool connected = false;
int count = 0;
void connect(shmempipe *pPipe, void *arg)
{
printf("got connect\n");
connected = true;
}
void disconnect(shmempipe *pPipe, void *arg)
{
printf("got disconnect\n");
connected = false;
}
void message(shmempipe * pPipe, void *arg, shmempipeMessage * _pMsg)
{
MyTestMsg * pMsg = (MyTestMsg *) _pMsg;
pPipe->release(pMsg);
pMsg = MyTestMsg::allocSize(pPipe);
if (pMsg)
{
pMsg->seqno = 8;
pPipe->send(pMsg);
}
count ++;
}
int
main()
{
shmempipe * pPipe;
CONFIG.setPipeName( "shmempipe_test" );
CONFIG.addPool(500, sizeof(MyTestMsg));
CONFIG.connectCallback = &connect;
CONFIG.disconnectCallback = &disconnect;
CONFIG.messageCallback = &message;
CONFIG.arg = NULL;
pPipe = new shmempipe( &CONFIG );
if (!CONFIG.bInitialized)
{
printf("error constructing shmempipe\n");
return 1;
}
while (!connected)
usleep(1);
do {
pPipe->getStats(&stats,true);
printf("sb %lld sp %lld ss %lld rb %lld rp %lld rs %lld "
"af %lld fb %lld\n",
stats.sent_bytes, stats.sent_packets, stats.sent_signals,
stats.rcvd_bytes, stats.rcvd_packets, stats.rcvd_signals,
stats.alloc_fails, stats.free_buffers);
usleep(100000);
} while (connected);
delete pPipe;
return 0;
}
bool connected = false;
int count=0;
bool done = false;
void connect(shmempipe *pPipe, void *arg)
{
printf("got connect\n");
connected = true;
}
void disconnect(shmempipe *pPipe, void *arg)
{
printf("got disconnect\n");
connected = false;
}
void message(shmempipe * pPipe, void *arg, shmempipeMessage * _pMsg)
{
MyTestMsg * pMsg = (MyTestMsg *) _pMsg;
pPipe->release(pMsg);
if (!done)
{
pMsg = MyTestMsg::allocSize(pPipe);
if (pMsg)
{
pMsg->seqno = 8;
pPipe->send(pMsg);
}
}
count++;
if (count >= 10000000)
done=true;
}
int
main()
{
shmempipe * pPipe;
CONFIG.setPipeName( "shmempipe_test" );
CONFIG.connectCallback = &connect;
CONFIG.disconnectCallback = &disconnect;
CONFIG.messageCallback = &message;
CONFIG.arg = NULL;
pPipe = new shmempipe( &CONFIG );
if (!CONFIG.bInitialized)
{
printf("error constructing shmempipe\n");
return 1;
}
while (!connected)
usleep(1);
for (int counter=0; counter < 50; counter++)
{
MyTestMsg * pMsg = MyTestMsg::allocSize(pPipe);
pMsg->seqno = 1;
pPipe->send(pMsg);
}
do {
pPipe->getStats(&stats,true);
printf("sb %lld sp %lld ss %lld rb %lld rp %lld rs %lld "
"af %lld fb %lld\n",
stats.sent_bytes, stats.sent_packets, stats.sent_signals,
stats.rcvd_bytes, stats.rcvd_packets, stats.rcvd_signals,
stats.alloc_fails, stats.free_buffers);
usleep(100000);
} while (connected && !done);
delete pPipe;
return 0;
}