version 1.3, 2011/09/07 13:11:56
|
version 1.4, 2012/02/10 23:38:30
|
Line 86 sess_SetErr(int eno, char *estr, ...)
|
Line 86 sess_SetErr(int eno, char *estr, ...)
|
// ----------------------------------------------------------- |
// ----------------------------------------------------------- |
|
|
/* |
/* |
* initSession() Initializing session structure, if session file not exists creating with specified tech | * sess_initSession() Initializing session structure, if session file not exists creating with specified tech |
* @pnID = Technology using in session. | * |
SHARED_IPC IPC tech; SHARED_MAP BSD MemoryMap tech or if =NULL SHARED_IPC | * @id = Technology using in session. SHARED_IPC IPC tech orSHARED_MAP BSD MemoryMap tech |
* @csFName = Session filename for build key and identified |
* @csFName = Session filename for build key and identified |
* @Sess = Session item, if =NULL allocate memory for session after use must be free! |
* @Sess = Session item, if =NULL allocate memory for session after use must be free! |
* return: 0 OK new key created, -1 error: no memory or file not created, 1 OK key finded |
* return: 0 OK new key created, -1 error: no memory or file not created, 1 OK key finded |
*/ |
*/ |
inline int | int |
initSession(int *pnID, const char *csFName, tagSess ** __restrict Sess) | sess_initSession(int id, const char *csFName, ait_sess_t ** __restrict Sess) |
{ |
{ |
int h, ret = 0, id = SHARED_IPC; | int h, ret = 0; |
char szStr[STRSIZ]; |
char szStr[STRSIZ]; |
|
|
|
if (!csFName) { |
|
sess_SetErr(EINVAL, "Filename is NULL"); |
|
return -1; |
|
} |
|
if (id < SHARED_UNKNOWN || id > SHARED_MAP) { |
|
sess_SetErr(EPROTONOSUPPORT, "Session type not supported"); |
|
return -1; |
|
} |
|
|
if (!*Sess) { |
if (!*Sess) { |
*Sess = malloc(sizeof(tagSess)); | *Sess = malloc(sizeof(ait_sess_t)); |
if (!*Sess) { |
if (!*Sess) { |
LOGERR; |
LOGERR; |
return -1; |
return -1; |
} |
} |
} else | } |
memset(*Sess, 0, sizeof(tagSess)); | memset(*Sess, 0, sizeof(ait_sess_t)); |
if (pnID && *pnID) | strlcpy((*Sess)->name, csFName, sizeof (*Sess)->name); |
id = *pnID; | |
|
|
h = open(csFName, O_WRONLY | O_CREAT | O_EXCL, MEM_MODE); | h = open((*Sess)->name, O_WRONLY | O_CREAT | O_EXCL, MEM_MODE); |
if (h == -1) { |
if (h == -1) { |
if (errno != EEXIST) { |
if (errno != EEXIST) { |
LOGERR; |
LOGERR; |
Line 118 initSession(int *pnID, const char *csFName, tagSess **
|
Line 126 initSession(int *pnID, const char *csFName, tagSess **
|
return -1; |
return -1; |
} |
} |
/* If key file exist, session already connected */ |
/* If key file exist, session already connected */ |
h = open(csFName, O_RDONLY); | h = open((*Sess)->name, O_RDONLY); |
if (h == -1) { |
if (h == -1) { |
LOGERR; |
LOGERR; |
free(*Sess); |
free(*Sess); |
Line 131 initSession(int *pnID, const char *csFName, tagSess **
|
Line 139 initSession(int *pnID, const char *csFName, tagSess **
|
free(*Sess); |
free(*Sess); |
return -1; |
return -1; |
} |
} |
if (!strncmp(szStr, "IPC@", 4)) | if (!strncmp(szStr, "IPC@", 4) && id == SHARED_IPC) { |
id = SHARED_IPC; | ret = 1; |
else if (!strncmp(szStr, "MAP@", 4)) | |
id = SHARED_MAP; | (*Sess)->sess.create = (int (*)(int, long, void*, ...)) ipc_createSession; |
else { | (*Sess)->sess.destroy = (void (*)(void*)) ipc_destroySession; |
sess_SetErr(EPROTONOSUPPORT, "Error:: Session type not supported"); | (*Sess)->sess.attach = (void* (*)(void*, void*)) ipc_attachSession; |
| (*Sess)->sess.detach = (void (*)(void*)) ipc_detachSession; |
| (*Sess)->sess.notSem = (void (*)(void*)) ipc_notSemaphore; |
| (*Sess)->sess.isSemOK = (int (*)(void*)) ipc_isSemaphoreOK; |
| (*Sess)->sess.incSem = (int (*)(void*)) ipc_incSemaphore; |
| (*Sess)->sess.decSem = (int (*)(void*)) ipc_decSemaphore; |
| } else if (!strncmp(szStr, "MAP@", 4) && id == SHARED_MAP) { |
| ret = 1; |
| |
| (*Sess)->sess.create = (int (*)(int, long, void*, ...)) map_createSession; |
| (*Sess)->sess.destroy = (void (*)(void*)) map_destroySession; |
| (*Sess)->sess.attach = (void* (*)(void*, void*)) map_attachSession; |
| (*Sess)->sess.detach = (void (*)(void*)) map_detachSession; |
| (*Sess)->sess.notSem = (void (*)(void*)) map_notSemaphore; |
| (*Sess)->sess.isSemOK = (int (*)(void*)) map_isSemaphoreOK; |
| (*Sess)->sess.incSem = (int (*)(void*)) map_incSemaphore; |
| (*Sess)->sess.decSem = (int (*)(void*)) map_decSemaphore; |
| } else { |
| sess_SetErr(EPROTONOSUPPORT, |
| "Session type not supported or wrong session type"); |
close(h); |
close(h); |
free(*Sess); |
free(*Sess); |
return -1; |
return -1; |
} |
} |
| /* key found */ |
ret = 1; /* key found */ | |
} else { |
} else { |
/* Build new key & new session */ |
/* Build new key & new session */ |
switch (id) { | if (id == SHARED_IPC) { |
case SHARED_IPC: | strlcpy(szStr, "IPC@", sizeof szStr); |
strlcpy(szStr, "IPC@", sizeof szStr); | |
break; | (*Sess)->sess.create = (int (*)(int, long, void*, ...)) ipc_createSession; |
case SHARED_MAP: | (*Sess)->sess.destroy = (void (*)(void*)) ipc_destroySession; |
strlcpy(szStr, "MAP@", sizeof szStr); | (*Sess)->sess.attach = (void* (*)(void*, void*)) ipc_attachSession; |
break; | (*Sess)->sess.detach = (void (*)(void*)) ipc_detachSession; |
default: | (*Sess)->sess.notSem = (void (*)(void*)) ipc_notSemaphore; |
sess_SetErr(EPROTONOSUPPORT, "Error:: Session type not supported"); | (*Sess)->sess.isSemOK = (int (*)(void*)) ipc_isSemaphoreOK; |
close(h); | (*Sess)->sess.incSem = (int (*)(void*)) ipc_incSemaphore; |
unlink(csFName); | (*Sess)->sess.decSem = (int (*)(void*)) ipc_decSemaphore; |
free(*Sess); | } else if (id == SHARED_MAP) { |
return -1; | strlcpy(szStr, "MAP@", sizeof szStr); |
| |
| (*Sess)->sess.create = (int (*)(int, long, void*, ...)) map_createSession; |
| (*Sess)->sess.destroy = (void (*)(void*)) map_destroySession; |
| (*Sess)->sess.attach = (void* (*)(void*, void*)) map_attachSession; |
| (*Sess)->sess.detach = (void (*)(void*)) map_detachSession; |
| (*Sess)->sess.notSem = (void (*)(void*)) map_notSemaphore; |
| (*Sess)->sess.isSemOK = (int (*)(void*)) map_isSemaphoreOK; |
| (*Sess)->sess.incSem = (int (*)(void*)) map_incSemaphore; |
| (*Sess)->sess.decSem = (int (*)(void*)) map_decSemaphore; |
| } else { |
| sess_SetErr(EINVAL, "Session type must be specified"); |
| close(h); |
| unlink(csFName); |
| free(*Sess); |
| return -1; |
} |
} |
strlcat(szStr, "ELWIX_Session ("PACKAGE_STRING")\n", sizeof szStr); |
strlcat(szStr, "ELWIX_Session ("PACKAGE_STRING")\n", sizeof szStr); |
write(h, szStr, strlen(szStr)); |
write(h, szStr, strlen(szStr)); |
|
|
ret = 0; /* new key created */ | ret = 0; |
| /* new key created */ |
} |
} |
close(h); |
close(h); |
|
|
(*Sess)->type = id; |
(*Sess)->type = id; |
|
(*Sess)->zcpy = (char) ret; |
return ret; |
return ret; |
} |
} |
|
|
/* |
/* |
* freeSession() Free allocated memory for session item and delete session file if present name | * sess_freeSession() Free allocated memory for session item and delete session file if present name |
* @csFName = Session filename for delete, if NULL nothing delete | * |
* @Sess = Session item |
* @Sess = Session item |
|
* return: none |
*/ |
*/ |
inline void | void |
freeSession(const char *csFName, tagSess ** __restrict Sess) | sess_freeSession(ait_sess_t ** __restrict Sess) |
{ |
{ |
assert(Sess); | if (!Sess || !(*Sess)) |
if (!Sess) | |
return; |
return; |
|
|
|
if ((*Sess)->addr) |
|
DETACH_MEMORY(*Sess); |
|
|
|
/* |
|
memset(&(*Sess)->sess, 0, sizeof (*Sess)->sess); |
|
|
(*Sess)->type = SHARED_UNKNOWN; |
(*Sess)->type = SHARED_UNKNOWN; |
if (csFName) | */ |
unlink(csFName); | |
if (*Sess) | free(*Sess); |
free(*Sess); | |
*Sess = NULL; |
*Sess = NULL; |
} |
} |
|
|
|
|
/* |
/* |
* map_createSession() MMAP Created session and allocated resources |
* map_createSession() MMAP Created session and allocated resources |
* @csFName = Session name for identified | * |
* @cnSeed = Seed for securing key | * @nSeed = Seed for securing key, if =-1 must add ready for use key |
* @cnSize = Allocated shared memory size in bytes | * @nSize = Allocated shared memory size in bytes |
* @Sess = Session item |
* @Sess = Session item |
|
* @... = If nSeed == -1 add ready for use key value |
* return: 0 Ok successful, -1 error: not allocated resources |
* return: 0 Ok successful, -1 error: not allocated resources |
*/ |
*/ |
int |
int |
map_createSession(const char *csFName, const int cnSeed, const u_int cnSize, tagSess ** __restrict Sess) | map_createSession(int nSeed, long nSize, ait_sess_t * __restrict Sess, ...) |
{ |
{ |
int ret = 0, id = SHARED_MAP; |
|
char szSName[2][FILENAME_MAX]; |
char szSName[2][FILENAME_MAX]; |
|
va_list lst; |
|
|
ret = initSession(&id, csFName, Sess); | if (!Sess || !*Sess->name) |
if (ret == -1 || !*Sess) | |
return -1; |
return -1; |
|
|
/* genkey */ | if (nSeed != -1) { |
(*Sess)->key = ftok(csFName, cnSeed); | /* genkey */ |
if ((*Sess)->key == -1) { | Sess->key = ftok(Sess->name, nSeed); |
LOGERR; | if (Sess->key == -1) { |
freeSession(csFName, Sess); | LOGERR; |
return -1; | return -1; |
| } |
| } else { |
| /* get key from va_args */ |
| va_start(lst, Sess); |
| Sess->key = va_arg(lst, key_t); |
| va_end(lst); |
} |
} |
|
|
/* 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); |
snprintf(szSName[1], FILENAME_MAX, "%s-%x.ANM", csFName, (u_int) (*Sess)->key); | snprintf(szSName[1], FILENAME_MAX, "%s-%x.ANM", Sess->name, (u_int) Sess->key); |
|
|
/* 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); |
if ((*Sess)->id.sid == SEM_FAILED) { | if (Sess->id.sid == SEM_FAILED) { |
LOGERR; |
LOGERR; |
map_destroySession(csFName, Sess); | map_destroySession(Sess); |
return -1; |
return -1; |
} else | } |
sem_post((*Sess)->id.sid); | /* if is new shared memory session, init sempahore with 1 */ |
| if (!Sess->zcpy) |
| sem_post(Sess->id.sid); |
|
|
/* create file for shared memory storage */ |
/* create file for shared memory storage */ |
(*Sess)->mem.fd = open(szSName[1], O_RDWR | O_CREAT, MEM_MODE); | Sess->mem.fd = open(szSName[1], O_RDWR | O_CREAT, MEM_MODE); |
if ((*Sess)->mem.fd == -1) { | if (Sess->mem.fd == -1) { |
LOGERR; |
LOGERR; |
map_destroySession(csFName, Sess); | map_destroySession(Sess); |
return -1; |
return -1; |
} |
} |
/* if is new shared memory session, fill file with zeros */ |
/* if is new shared memory session, fill file with zeros */ |
if (!ret) { | if (!Sess->zcpy) { |
if (lseek((*Sess)->mem.fd, cnSize - 1, SEEK_SET) == -1) { | if (lseek(Sess->mem.fd, nSize - 1, SEEK_SET) == -1) { |
LOGERR; |
LOGERR; |
map_destroySession(csFName, Sess); | map_destroySession(Sess); |
return -1; |
return -1; |
} 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); |
} |
} |
(*Sess)->eom = cnSize; | Sess->eom = nSize; |
|
|
return ret; | return (int) Sess->zcpy; |
} |
} |
|
|
/* |
/* |
* map_destroySession() MMAP free shared resources |
* map_destroySession() MMAP free shared resources |
* @csFName = Session name for delete | * |
* @Sess = Session item |
* @Sess = Session item |
|
* return: none |
*/ |
*/ |
void |
void |
map_destroySession(const char *csFName, tagSess ** __restrict Sess) | map_destroySession(ait_sess_t * __restrict Sess) |
{ |
{ |
int flg = 1; |
|
char szSName[2][FILENAME_MAX]; |
char szSName[2][FILENAME_MAX]; |
|
|
assert(Sess); | if (!Sess || sess_isAttached(Sess) || !*Sess->name) |
if (!Sess || !*Sess) | |
return; |
return; |
|
|
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); |
snprintf(szSName[1], FILENAME_MAX, "%s-%x.ANM", csFName, (u_int) (*Sess)->key); | snprintf(szSName[1], FILENAME_MAX, "%s-%x.ANM", Sess->name, (u_int) Sess->key); |
|
|
if ((*Sess)->id.sid != SEM_FAILED) { | if (Sess->id.sid != SEM_FAILED) { |
if (sem_close((*Sess)->id.sid) == -1) | sem_close(Sess->id.sid); |
flg = 0; | sem_unlink(szSName[0]); |
if (sem_unlink(szSName[0]) == -1) | |
/*flg = 0*/; | |
} |
} |
if ((*Sess)->mem.fd != -1) { | if (Sess->mem.fd > 2) { |
if (close((*Sess)->mem.fd) == -1) | close(Sess->mem.fd); |
flg = 0; | unlink(szSName[1]); |
if (unlink(szSName[1]) == -1) | |
/*flg = 0*/; | |
} |
} |
(*Sess)->eom ^= (*Sess)->eom; | unlink(Sess->name); |
| memset(Sess->name, 0, sizeof Sess->name); |
freeSession(flg ? csFName : NULL, Sess); | Sess->eom ^= Sess->eom; |
| Sess->key ^= Sess->key; |
} |
} |
|
|
/* |
/* |
* ipc_createSession() IPC Created session and allocated resources |
* ipc_createSession() IPC Created session and allocated resources |
* @csFName = Session name for identified | * |
* @cnSeed = Seed for securing key | * @nSeed = Seed for securing key, if =-1 must add ready for use key |
* @cnSize = Allocated shared memory size in bytes | * @nSize = Allocated shared memory size in bytes |
* @Sess = Session item |
* @Sess = Session item |
|
* @... = If nSeed == -1 add ready for use key value |
* return: 0 Ok successful, -1 error: not allocated resources |
* return: 0 Ok successful, -1 error: not allocated resources |
*/ | */ |
int |
int |
ipc_createSession(const char *csFName, const int cnSeed, const u_int cnSize, tagSess ** __restrict Sess) | ipc_createSession(int nSeed, long nSize, ait_sess_t * __restrict Sess, ...) |
{ |
{ |
int ret = 0, id = SHARED_IPC; |
|
union semun sems; |
union semun sems; |
|
va_list lst; |
|
|
ret = initSession(&id, csFName, Sess); | if (!Sess || !*Sess->name) |
if (ret == -1 || !*Sess) | |
return -1; |
return -1; |
|
|
/* genkey */ | if (nSeed != -1) { |
(*Sess)->key = ftok(csFName, cnSeed); | /* genkey */ |
if ((*Sess)->key == -1) { | Sess->key = ftok(Sess->name, nSeed); |
LOGERR; | if (Sess->key == -1) { |
freeSession(csFName, Sess); | LOGERR; |
return -1; | return -1; |
| } |
| } else { |
| /* get key from va_args */ |
| va_start(lst, Sess); |
| Sess->key = va_arg(lst, key_t); |
| va_end(lst); |
} |
} |
|
|
/* create semaphore */ |
/* create semaphore */ |
(*Sess)->id.semid = semget((*Sess)->key, 1, MEM_MODE | IPC_CREAT); | Sess->id.semid = semget(Sess->key, 1, MEM_MODE | IPC_CREAT); |
if ((*Sess)->id.semid == -1) { | if (Sess->id.semid == -1) { |
LOGERR; |
LOGERR; |
ipc_destroySession(csFName, Sess); | ipc_destroySession(Sess); |
return -1; |
return -1; |
} |
} |
/* if is new shared memory session, init sempahore with 1 */ |
/* if is new shared memory session, init sempahore with 1 */ |
if (!ret) { | if (!Sess->zcpy) { |
sems.val = 1; |
sems.val = 1; |
if (semctl((*Sess)->id.semid, 0, SETVAL, sems) == -1) { | if (semctl(Sess->id.semid, 0, SETVAL, sems) == -1) { |
LOGERR; |
LOGERR; |
ipc_destroySession(csFName, Sess); | ipc_destroySession(Sess); |
return -1; |
return -1; |
} |
} |
} |
} |
|
|
/* create shared memory object */ |
/* create shared memory object */ |
(*Sess)->mem.shmid = shmget((*Sess)->key, cnSize, MEM_MODE | IPC_CREAT); | Sess->mem.shmid = shmget(Sess->key, nSize, MEM_MODE | IPC_CREAT); |
if ((*Sess)->mem.shmid == -1) { | if (Sess->mem.shmid == -1) { |
LOGERR; |
LOGERR; |
ipc_destroySession(csFName, Sess); | ipc_destroySession(Sess); |
return -1; |
return -1; |
} | } else |
(*Sess)->eom = cnSize; | Sess->eom = nSize; |
|
|
return ret; | return (int) Sess->zcpy; |
} |
} |
|
|
/* |
/* |
* ipc_destroySession() IPC free shared resources |
* ipc_destroySession() IPC free shared resources |
* @csFName = Session name for delete | * |
* @Sess = Session item |
* @Sess = Session item |
*/ | * return: none |
| */ |
void |
void |
ipc_destroySession(const char *csFName, tagSess ** __restrict Sess) | ipc_destroySession(ait_sess_t * __restrict Sess) |
{ |
{ |
int flg = 1; |
|
union semun sems; |
union semun sems; |
struct shmid_ds ds; |
struct shmid_ds ds; |
|
|
assert(Sess); | if (!Sess || sess_isAttached(Sess)) |
if (!Sess || !*Sess) | |
return; |
return; |
|
|
if ((*Sess)->id.semid != -1) | if (Sess->id.semid != -1) |
if (semctl((*Sess)->id.semid, 0, IPC_RMID, &sems) == -1) | semctl(Sess->id.semid, 0, IPC_RMID, &sems); |
flg = 0; | if (Sess->mem.shmid != -1) |
if ((*Sess)->mem.shmid != -1) | shmctl(Sess->mem.shmid, IPC_RMID, &ds); |
if (shmctl((*Sess)->mem.shmid, IPC_RMID, &ds) == -1) | unlink(Sess->name); |
flg = 0; | memset(Sess->name, 0, sizeof Sess->name); |
(*Sess)->eom ^= (*Sess)->eom; | Sess->eom ^= Sess->eom; |
| Sess->key ^= Sess->key; |
freeSession(flg ? csFName : NULL, Sess); | |
} |
} |
|
|
|
|
/* |
/* |
* map_attachSession() MMAP Attach to shared memory & return begin address |
* map_attachSession() MMAP Attach to shared memory & return begin address |
|
* |
* @s = Session item |
* @s = Session item |
* @procMem = Custom start address (optionl) *default must be 0* |
* @procMem = Custom start address (optionl) *default must be 0* |
* return: NULL failed attach, !=NULL begin address of memory |
* return: NULL failed attach, !=NULL begin address of memory |
*/ | */ |
inline void * | void * |
map_attachSession(tagSess * __restrict s, void *procMem) | map_attachSession(ait_sess_t * __restrict s, void *procMem) |
{ |
{ |
struct stat sb; |
|
|
|
if (!s) |
if (!s) |
return NULL; |
return NULL; |
|
|
/* Learn size of shared memory block */ |
|
sync(); |
sync(); |
if (fstat(s->mem.fd, &sb) == -1) { |
|
LOGERR; |
|
return NULL; |
|
} else |
|
s->eom = sb.st_size; |
|
|
|
/* attach to memory */ |
/* attach to memory */ |
s->addr = mmap(procMem, s->eom, PROT_READ | PROT_WRITE, MAP_SHARED, s->mem.fd, 0); |
s->addr = mmap(procMem, s->eom, PROT_READ | PROT_WRITE, MAP_SHARED, s->mem.fd, 0); |
Line 406 map_attachSession(tagSess * __restrict s, void *procMe
|
Line 455 map_attachSession(tagSess * __restrict s, void *procMe
|
|
|
/* |
/* |
* map_detachSession() MMAP Detach from shared memory |
* map_detachSession() MMAP Detach from shared memory |
|
* |
* @s = Session item |
* @s = Session item |
*/ | * return: none |
inline void | */ |
map_detachSession(tagSess * __restrict s) | void |
| map_detachSession(ait_sess_t * __restrict s) |
{ |
{ |
if (!s) |
if (!s) |
return; |
return; |
Line 424 map_detachSession(tagSess * __restrict s)
|
Line 475 map_detachSession(tagSess * __restrict s)
|
|
|
/* |
/* |
* ipc_attachSession() IPC Attach to shared memory & return begin address |
* ipc_attachSession() IPC Attach to shared memory & return begin address |
|
* |
* @s = Session item |
* @s = Session item |
* @procMem = Custom start address (optionl) *default must be 0* |
* @procMem = Custom start address (optionl) *default must be 0* |
* return: NULL failed attach, !=NULL begin address of memory |
* return: NULL failed attach, !=NULL begin address of memory |
*/ | */ |
inline void * | void * |
ipc_attachSession(tagSess * __restrict s, void *procMem) | ipc_attachSession(ait_sess_t * __restrict s, void *procMem) |
{ |
{ |
if (!s) |
if (!s) |
return NULL; |
return NULL; |
Line 445 ipc_attachSession(tagSess * __restrict s, void *procMe
|
Line 497 ipc_attachSession(tagSess * __restrict s, void *procMe
|
|
|
/* |
/* |
* ipc_detachSession() IPC Detach from shared memory |
* ipc_detachSession() IPC Detach from shared memory |
|
* |
* @s = Session item |
* @s = Session item |
*/ | * return: none |
inline void | */ |
ipc_detachSession(tagSess * __restrict s) | void |
| ipc_detachSession(ait_sess_t * __restrict s) |
{ |
{ |
if (!s) |
if (!s) |
return; |
return; |
Line 460 ipc_detachSession(tagSess * __restrict s)
|
Line 514 ipc_detachSession(tagSess * __restrict s)
|
} |
} |
|
|
/* |
/* |
* isAttached() Check for mapped/(attached) shared memory | * sess_isAttached() Check for attached shared memory |
| * |
* @s = Session item |
* @s = Session item |
* return: -1 null session item, 0 not attached, 1 attached memory |
* return: -1 null session item, 0 not attached, 1 attached memory |
*/ | */ |
inline int |
inline int |
isAttached(tagSess * __restrict s) | sess_isAttached(ait_sess_t * __restrict s) |
{ |
{ |
if (!s) |
if (!s) |
return -1; |
return -1; |
Line 476 isAttached(tagSess * __restrict s)
|
Line 531 isAttached(tagSess * __restrict s)
|
|
|
/* |
/* |
* map_notSemaphore() MMAP negative block if semaphore isn`t signaled |
* map_notSemaphore() MMAP negative block if semaphore isn`t signaled |
|
* |
* @s = Session item |
* @s = Session item |
*/ | * return: none |
inline void | */ |
map_notSemaphore(tagSess * __restrict s) | void |
| map_notSemaphore(ait_sess_t * __restrict s) |
{ |
{ |
int i = -1; |
int i = -1; |
|
|
Line 487 map_notSemaphore(tagSess * __restrict s)
|
Line 544 map_notSemaphore(tagSess * __restrict s)
|
return; |
return; |
|
|
sem_getvalue(s->id.sid, &i); |
sem_getvalue(s->id.sid, &i); |
for (;i > 0; i--) | while (i > 0) { |
sem_wait(s->id.sid); |
sem_wait(s->id.sid); |
|
i--; |
|
} |
} |
} |
|
|
/* |
/* |
* map_isSemaphored() MMAP Check semaphore | * map_isSemaphoreOK() MMAP Check semaphore |
| * |
* @s = Session item |
* @s = Session item |
* return: -1 error: can`t return semaphore, 0 = false, 1 = true |
* return: -1 error: can`t return semaphore, 0 = false, 1 = true |
*/ | */ |
inline int | int |
map_isSemaphored(tagSess * __restrict s) | map_isSemaphoreOK(ait_sess_t * __restrict s) |
{ |
{ |
int val = -1; |
int val = -1; |
|
|
Line 505 map_isSemaphored(tagSess * __restrict s)
|
Line 565 map_isSemaphored(tagSess * __restrict s)
|
return -1; |
return -1; |
|
|
sem_getvalue(s->id.sid, &val); |
sem_getvalue(s->id.sid, &val); |
return val ? 0 : 1; | return (val ? 0 : 1); |
} |
} |
|
|
/* |
/* |
* map_addSemaphore() MMAP unblock semaphore, increment semaphore | * map_incSemaphore() MMAP unblock semaphore, increment semaphore |
| * |
* @s = Session item |
* @s = Session item |
* return: 0 Ok, -1 error: can`t increment |
* return: 0 Ok, -1 error: can`t increment |
*/ | */ |
inline int | int |
map_addSemaphore(tagSess * __restrict s) | map_incSemaphore(ait_sess_t * __restrict s) |
{ |
{ |
if (!s) |
if (!s) |
return -1; |
return -1; |
Line 524 map_addSemaphore(tagSess * __restrict s)
|
Line 585 map_addSemaphore(tagSess * __restrict s)
|
|
|
/* |
/* |
* map_decSemaphore() MMAP block semaphore, decrement semaphore |
* map_decSemaphore() MMAP block semaphore, decrement semaphore |
|
* |
* @s = Session item |
* @s = Session item |
* return: 0 Ok, -1 error: can`t decrement |
* return: 0 Ok, -1 error: can`t decrement |
*/ | */ |
inline int | int |
map_decSemaphore(tagSess * __restrict s) | map_decSemaphore(ait_sess_t * __restrict s) |
{ |
{ |
if (!s) |
if (!s) |
return -1; |
return -1; |
Line 538 map_decSemaphore(tagSess * __restrict s)
|
Line 600 map_decSemaphore(tagSess * __restrict s)
|
|
|
/* |
/* |
* ipc_notSemaphore() IPC negative block if semaphore isn`t signaled |
* ipc_notSemaphore() IPC negative block if semaphore isn`t signaled |
|
* |
* @s = Session item |
* @s = Session item |
*/ | * return: none |
inline void | */ |
ipc_notSemaphore(tagSess * __restrict s) | void |
| ipc_notSemaphore(ait_sess_t * __restrict s) |
{ |
{ |
struct sembuf sb = { 0, 0, 0 }; |
struct sembuf sb = { 0, 0, 0 }; |
|
|
Line 550 ipc_notSemaphore(tagSess * __restrict s)
|
Line 614 ipc_notSemaphore(tagSess * __restrict s)
|
} |
} |
|
|
/* |
/* |
* ipc_isSemaphored() IPC Check semaphore | * ipc_isSemaphoreOK() IPC Check semaphore |
| * |
* @s = Session item |
* @s = Session item |
* return: -1 error: can`t return semaphore, 0 = false, 1 = true |
* return: -1 error: can`t return semaphore, 0 = false, 1 = true |
*/ | */ |
inline int | int |
ipc_isSemaphored(tagSess * __restrict s) | ipc_isSemaphoreOK(ait_sess_t * __restrict s) |
{ |
{ |
struct sembuf sb = { 0, 0, IPC_NOWAIT }; |
struct sembuf sb = { 0, 0, IPC_NOWAIT }; |
|
|
Line 566 ipc_isSemaphored(tagSess * __restrict s)
|
Line 631 ipc_isSemaphored(tagSess * __restrict s)
|
} |
} |
|
|
/* |
/* |
* ipc_addSemaphore() IPC unblock semaphore, increment semaphore | * ipc_incSemaphore() IPC unblock semaphore, increment semaphore |
| * |
* @s = Session item |
* @s = Session item |
* return: 0 Ok, -1 error: can`t increment |
* return: 0 Ok, -1 error: can`t increment |
*/ | */ |
inline int | int |
ipc_addSemaphore(tagSess * __restrict s) | ipc_incSemaphore(ait_sess_t * __restrict s) |
{ |
{ |
struct sembuf sb = { 0, 1, 0 }; |
struct sembuf sb = { 0, 1, 0 }; |
|
|
Line 583 ipc_addSemaphore(tagSess * __restrict s)
|
Line 649 ipc_addSemaphore(tagSess * __restrict s)
|
|
|
/* |
/* |
* ipc_decSemaphore() IPC block semaphore, decrement semaphore |
* ipc_decSemaphore() IPC block semaphore, decrement semaphore |
|
* |
* @s = Session item |
* @s = Session item |
* return: 0 Ok, -1 error: can`t decrement |
* return: 0 Ok, -1 error: can`t decrement |
*/ | */ |
inline int | int |
ipc_decSemaphore(tagSess * __restrict s) | ipc_decSemaphore(ait_sess_t * __restrict s) |
{ |
{ |
struct sembuf sb = { 0, -1, 0 }; |
struct sembuf sb = { 0, -1, 0 }; |
|
|