version 1.4, 2012/02/10 23:38:30
|
version 1.4.2.1, 2012/02/15 16:06:13
|
Line 274 map_createSession(int nSeed, long nSize, ait_sess_t *
|
Line 274 map_createSession(int nSeed, long nSize, ait_sess_t *
|
/* build semaphore & shared memory name */ |
/* build semaphore & shared memory name */ |
memset(szSName, 0, sizeof szSName); |
memset(szSName, 0, sizeof szSName); |
snprintf(szSName[0], MAX_SEMNAME, "/%X.ANS", (u_int) Sess->key); |
snprintf(szSName[0], MAX_SEMNAME, "/%X.ANS", (u_int) Sess->key); |
|
#ifdef HAVE_SHM_OPEN |
|
snprintf(szSName[1], FILENAME_MAX, "/%s-%x.ANM", Sess->name, (u_int) Sess->key); |
|
#else |
snprintf(szSName[1], FILENAME_MAX, "%s-%x.ANM", Sess->name, (u_int) Sess->key); |
snprintf(szSName[1], FILENAME_MAX, "%s-%x.ANM", Sess->name, (u_int) Sess->key); |
|
#endif |
|
|
/* create semaphore & add 1 */ |
/* create semaphore & add 1 */ |
Sess->id.sid = sem_open(szSName[0], O_CREAT, MEM_MODE); |
Sess->id.sid = sem_open(szSName[0], O_CREAT, MEM_MODE); |
Line 288 map_createSession(int nSeed, long nSize, ait_sess_t *
|
Line 292 map_createSession(int nSeed, long nSize, ait_sess_t *
|
sem_post(Sess->id.sid); |
sem_post(Sess->id.sid); |
|
|
/* create file for shared memory storage */ |
/* create file for shared memory storage */ |
|
#ifdef HAVE_SHM_OPEN |
|
Sess->mem.fd = shm_open(szSName[1], O_RDWR | O_CREAT, MEM_MODE); |
|
#else |
Sess->mem.fd = open(szSName[1], O_RDWR | O_CREAT, MEM_MODE); |
Sess->mem.fd = open(szSName[1], O_RDWR | O_CREAT, MEM_MODE); |
|
#endif |
if (Sess->mem.fd == -1) { |
if (Sess->mem.fd == -1) { |
LOGERR; |
LOGERR; |
map_destroySession(Sess); |
map_destroySession(Sess); |
return -1; |
return -1; |
} |
} |
/* if is new shared memory session, fill file with zeros */ |
|
if (!Sess->zcpy) { |
if (!Sess->zcpy) { |
|
#ifdef HAVE_SHM_OPEN |
|
if (ftruncate(Sess->mem.fd, nSize) == -1) { |
|
LOGERR; |
|
map_destroySession(Sess); |
|
return -1; |
|
} |
|
#else |
|
/* if is new shared memory session, fill file with zeros */ |
if (lseek(Sess->mem.fd, nSize - 1, SEEK_SET) == -1) { |
if (lseek(Sess->mem.fd, nSize - 1, SEEK_SET) == -1) { |
LOGERR; |
LOGERR; |
map_destroySession(Sess); |
map_destroySession(Sess); |
Line 303 map_createSession(int nSeed, long nSize, ait_sess_t *
|
Line 318 map_createSession(int nSeed, long nSize, ait_sess_t *
|
} else |
} else |
write(Sess->mem.fd, "", 1); |
write(Sess->mem.fd, "", 1); |
lseek(Sess->mem.fd, 0, SEEK_SET); |
lseek(Sess->mem.fd, 0, SEEK_SET); |
|
#endif |
} |
} |
Sess->eom = nSize; |
Sess->eom = nSize; |
|
|
Line 325 map_destroySession(ait_sess_t * __restrict Sess)
|
Line 341 map_destroySession(ait_sess_t * __restrict Sess)
|
|
|
memset(szSName, 0, sizeof szSName); |
memset(szSName, 0, sizeof szSName); |
snprintf(szSName[0], MAX_SEMNAME, "/%X.ANS", (u_int) Sess->key); |
snprintf(szSName[0], MAX_SEMNAME, "/%X.ANS", (u_int) Sess->key); |
|
#ifdef HAVE_SHM_UNLINK |
|
snprintf(szSName[1], FILENAME_MAX, "/%s-%x.ANM", Sess->name, (u_int) Sess->key); |
|
#else |
snprintf(szSName[1], FILENAME_MAX, "%s-%x.ANM", Sess->name, (u_int) Sess->key); |
snprintf(szSName[1], FILENAME_MAX, "%s-%x.ANM", Sess->name, (u_int) Sess->key); |
|
#endif |
|
|
if (Sess->id.sid != SEM_FAILED) { |
if (Sess->id.sid != SEM_FAILED) { |
sem_close(Sess->id.sid); |
sem_close(Sess->id.sid); |
Line 333 map_destroySession(ait_sess_t * __restrict Sess)
|
Line 353 map_destroySession(ait_sess_t * __restrict Sess)
|
} |
} |
if (Sess->mem.fd > 2) { |
if (Sess->mem.fd > 2) { |
close(Sess->mem.fd); |
close(Sess->mem.fd); |
|
#ifdef HAVE_SHM_UNLINK |
|
shm_unlink(szSName[1]); |
|
#else |
unlink(szSName[1]); |
unlink(szSName[1]); |
|
#endif |
} |
} |
unlink(Sess->name); |
unlink(Sess->name); |
memset(Sess->name, 0, sizeof Sess->name); |
memset(Sess->name, 0, sizeof Sess->name); |