MistServer  2.5.3-Pro-19-gf5e75b1 ( Generic_64)
Public Member Functions | Data Fields | Private Member Functions | Private Attributes
IPC::sharedServer Class Reference

The server part of a server/client model for shared memory. More...

#include <shared_memory.h>

Public Member Functions

 sharedServer ()
 Default constructor, erases all the values. More...
 
 sharedServer ()
 
 sharedServer (std::string name, int len, bool withCounter=false)
 Desired constructor, initializes after cleaning. More...
 
 sharedServer (std::string name, int len, bool withCounter=false)
 
 ~sharedServer ()
 The deconstructor. More...
 
 ~sharedServer ()
 
void init (std::string name, int len, bool withCounter=false)
 
void init (std::string name, int len, bool withCounter=false)
 Initialize the server. More...
 
 operator bool () const
 
 operator bool () const
 Determines whether a sharedServer is valid. More...
 
void parseEach (void(*callback)(char *data, size_t len, unsigned int id))
 
void parseEach (void(*callback)(char *data, size_t len, unsigned int id))
 Parse each of the possible payload pieces, and runs a callback on it if in use. More...
 

Data Fields

unsigned int amount
 The amount of connected clients. More...
 

Private Member Functions

void deletePage ()
 Deletes the highest allocated page. More...
 
void deletePage ()
 
bool isInUse (unsigned int id)
 
bool isInUse (unsigned int id)
 Determines whether an id is currently in use or not. More...
 
void newPage ()
 Creates the next page with the correct size. More...
 
void newPage ()
 

Private Attributes

std::string baseName
 The basename of the shared pages. More...
 
bool hasCounter
 Whether the payload has a counter, if so, it is added in front of the payload. More...
 
std::set< sharedPagemyPages
 The set of sharedPage structures to manage the actual memory. More...
 
semaphore mySemaphore
 A semaphore that is locked upon creation and deletion of the page, to ensure no new data is allocated during this step. More...
 
unsigned int payLen
 The length of each consecutive piece of payload. More...
 

Detailed Description

The server part of a server/client model for shared memory.

The server manages the shared memory pages, and allocates new pages when needed.

Pages are created with a basename + index, where index is in the range of 'A' - 'Z' Each time a page is nearly full, the next page is created with a size double to the previous one.

Clients should allocate payLen bytes at a time, possibly with the addition of a counter. If no such length can be allocated, the next page should be tried, and so on.

Constructor & Destructor Documentation

IPC::sharedServer::sharedServer ( )

Default constructor, erases all the values.

IPC::sharedServer::sharedServer ( std::string  name,
int  len,
bool  withCounter = false 
)

Desired constructor, initializes after cleaning.

Parameters
nameThe basename of this server
lenThe lenght of the payload
withCounterWhether the content should have a counter
IPC::sharedServer::~sharedServer ( )

The deconstructor.

IPC::sharedServer::sharedServer ( )
IPC::sharedServer::sharedServer ( std::string  name,
int  len,
bool  withCounter = false 
)
IPC::sharedServer::~sharedServer ( )

Member Function Documentation

void IPC::sharedServer::deletePage ( )
private

Deletes the highest allocated page.

void IPC::sharedServer::deletePage ( )
private
void IPC::sharedServer::init ( std::string  name,
int  len,
bool  withCounter = false 
)

Initialize the server.

Parameters
nameThe basename of this server
lenThe lenght of the payload
withCounterWhether the content should have a counter
void IPC::sharedServer::init ( std::string  name,
int  len,
bool  withCounter = false 
)
bool IPC::sharedServer::isInUse ( unsigned int  id)
private

Determines whether an id is currently in use or not.

bool IPC::sharedServer::isInUse ( unsigned int  id)
private
void IPC::sharedServer::newPage ( )
private
void IPC::sharedServer::newPage ( )
private

Creates the next page with the correct size.

IPC::sharedServer::operator bool ( ) const
IPC::sharedServer::operator bool ( ) const

Determines whether a sharedServer is valid.

void IPC::sharedServer::parseEach ( void(*)(char *data, size_t len, unsigned int id)  callback)
void IPC::sharedServer::parseEach ( void(*)(char *data, size_t len, unsigned int id)  callback)

Parse each of the possible payload pieces, and runs a callback on it if in use.

Field Documentation

unsigned int IPC::sharedServer::amount

The amount of connected clients.

std::string IPC::sharedServer::baseName
private

The basename of the shared pages.

bool IPC::sharedServer::hasCounter
private

Whether the payload has a counter, if so, it is added in front of the payload.

std::set< sharedPage > IPC::sharedServer::myPages
private

The set of sharedPage structures to manage the actual memory.

semaphore IPC::sharedServer::mySemaphore
private

A semaphore that is locked upon creation and deletion of the page, to ensure no new data is allocated during this step.

unsigned int IPC::sharedServer::payLen
private

The length of each consecutive piece of payload.


The documentation for this class was generated from the following files: