Fixed shared memory initialization bug.

This commit is contained in:
Thulinma 2014-09-10 10:44:12 +02:00
parent cc6946c95b
commit 81866a50a1

View file

@ -834,7 +834,7 @@ namespace IPC {
///\param name The basename of the server to connect to ///\param name The basename of the server to connect to
///\param len The size of the payload to allocate ///\param len The size of the payload to allocate
///\param withCounter Whether or not this payload has a counter ///\param withCounter Whether or not this payload has a counter
sharedClient::sharedClient(std::string name, int len, bool withCounter) : baseName(name), payLen(len), offsetOnPage(-1), hasCounter(withCounter) { sharedClient::sharedClient(std::string name, int len, bool withCounter) : baseName("/"+name), payLen(len), offsetOnPage(-1), hasCounter(withCounter) {
#ifdef __APPLE__ #ifdef __APPLE__
//note: O_CREAT is only needed for mac, probably //note: O_CREAT is only needed for mac, probably
mySemaphore.open(baseName.c_str(), O_RDWR | O_CREAT, 0); mySemaphore.open(baseName.c_str(), O_RDWR | O_CREAT, 0);
@ -856,7 +856,7 @@ namespace IPC {
memset(empty, 0, payLen); memset(empty, 0, payLen);
} }
for (char i = 'A'; i <= 'Z'; i++) { for (char i = 'A'; i <= 'Z'; i++) {
myPage.init(baseName + i, (4096 << (i - 'A'))); myPage.init(baseName.substr(1) + i, (4096 << (i - 'A')));
int offset = 0; int offset = 0;
while (offset + payLen + (hasCounter ? 1 : 0) <= myPage.len) { while (offset + payLen + (hasCounter ? 1 : 0) <= myPage.len) {
if ((hasCounter && myPage.mapped[offset] == 0) || (!hasCounter && !memcmp(myPage.mapped + offset, empty, payLen))) { if ((hasCounter && myPage.mapped[offset] == 0) || (!hasCounter && !memcmp(myPage.mapped + offset, empty, payLen))) {