--- libaitsess/src/aitsess.c 2008/08/28 13:18:30 1.1.1.1 +++ libaitsess/src/aitsess.c 2012/02/10 23:38:30 1.4 @@ -1,11 +1,56 @@ +/************************************************************************* +* (C) 2008 AITNET ltd - Sofia/Bulgaria - +* by Michael Pounov +* +* $Author: misho $ +* $Id: aitsess.c,v 1.4 2012/02/10 23:38:30 misho Exp $ +* +************************************************************************** +The ELWIX and AITNET software is distributed under the following +terms: + +All of the documentation and software included in the ELWIX and AITNET +Releases is copyrighted by ELWIX - Sofia/Bulgaria + +Copyright 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011 + by Michael Pounov . All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions +are met: +1. Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. +2. Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. +3. All advertising materials mentioning features or use of this software + must display the following acknowledgement: +This product includes software developed by Michael Pounov +ELWIX - Embedded LightWeight unIX and its contributors. +4. Neither the name of AITNET nor the names of its contributors + may be used to endorse or promote products derived from this software + without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY AITNET AND CONTRIBUTORS ``AS IS'' AND +ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE +FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +SUCH DAMAGE. +*/ #include "global.h" #include "aitsess.h" #pragma GCC visibility push(hidden) -int sessErrno; -char sessError[MAX_STR + 1]; +int sess_Errno; +char sess_Error[STRSIZ]; #pragma GCC visibility pop @@ -14,320 +59,391 @@ char sessError[MAX_STR + 1]; // Error maintenance functions ... // sess_GetErrno() Get error code of last operation -inline int sess_GetErrno() +inline int +sess_GetErrno() { - return sessErrno; + return sess_Errno; } // sess_GetError() Get error text of last operation -inline const char *sess_GetError() +inline const char * +sess_GetError() { - return sessError; + return sess_Error; } -// sessDbg() Debug/Logging operations -static inline int sessDbg(FILE *f, char *fmt, ...) +// sess_SetErr() Set error to variables for internal use!!! +inline void +sess_SetErr(int eno, char *estr, ...) { - int ret = 0; va_list lst; - va_start(lst, fmt); - ret = vfprintf(f, fmt, lst); + sess_Errno = eno; + memset(sess_Error, 0, sizeof sess_Error); + va_start(lst, estr); + vsnprintf(sess_Error, sizeof sess_Error, estr, lst); va_end(lst); - - return ret; } // ----------------------------------------------------------- /* - * initSession() Initializing session structure, if session file not exists creating with specified tech - * @cnID = Technology using in session. SHARED_IPC IPC tech; SHARED_MAP BSD MemoryMap tech + * sess_initSession() Initializing session structure, if session file not exists creating with specified tech + * + * @id = Technology using in session. SHARED_IPC IPC tech orSHARED_MAP BSD MemoryMap tech * @csFName = Session filename for build key and identified - * @Sess = Session item + * @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 */ -inline int initSession(const int cnID, const char *csFName, tagSess ** __restrict Sess) +int +sess_initSession(int id, const char *csFName, ait_sess_t ** __restrict Sess) { int h, ret = 0; - char szStr[MAX_STR + 1]; + 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) { - *Sess = malloc(sizeof(tagSess)); + *Sess = malloc(sizeof(ait_sess_t)); if (!*Sess) { LOGERR; return -1; } } - memset(*Sess, 0, sizeof(tagSess)); + memset(*Sess, 0, sizeof(ait_sess_t)); + strlcpy((*Sess)->name, csFName, sizeof (*Sess)->name); - // If key file exist, session already connected - if (!access(csFName, F_OK)) - ret = 1; - // Build new key & new session - h = open(csFName, O_WRONLY | O_CREAT, 0640); + h = open((*Sess)->name, O_WRONLY | O_CREAT | O_EXCL, MEM_MODE); if (h == -1) { - LOGERR; - free(*Sess); - return -1; - } - - bzero(szStr, MAX_STR + 1); - switch (cnID) { - case SHARED_IPC: - strcpy(szStr, "IPC@"); - break; - case SHARED_MAP: - strcpy(szStr, "MAP@"); - break; - default: - errno = EPROTONOSUPPORT; + if (errno != EEXIST) { LOGERR; + free(*Sess); + return -1; + } + /* If key file exist, session already connected */ + h = open((*Sess)->name, O_RDONLY); + if (h == -1) { + LOGERR; + free(*Sess); + return -1; + } + ret = read(h, szStr, sizeof szStr); + if (ret == -1) { + LOGERR; + close(h); + free(*Sess); + return -1; + } + if (!strncmp(szStr, "IPC@", 4) && id == SHARED_IPC) { + ret = 1; + (*Sess)->sess.create = (int (*)(int, long, void*, ...)) ipc_createSession; + (*Sess)->sess.destroy = (void (*)(void*)) ipc_destroySession; + (*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); + free(*Sess); + return -1; + } + /* key found */ + } else { + /* Build new key & new session */ + if (id == SHARED_IPC) { + strlcpy(szStr, "IPC@", sizeof szStr); + + (*Sess)->sess.create = (int (*)(int, long, void*, ...)) ipc_createSession; + (*Sess)->sess.destroy = (void (*)(void*)) ipc_destroySession; + (*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 (id == SHARED_MAP) { + 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); + write(h, szStr, strlen(szStr)); + + ret = 0; + /* new key created */ } - strcat(szStr, "AN_Session ver"); - strcat(szStr, "\n"); - write(h, szStr, strlen(szStr)); close(h); - (*Sess)->type = cnID; + (*Sess)->type = id; + (*Sess)->zcpy = (char) ret; return ret; } /* - * freeSession() Free allocated memory for session item and delete session file if present name - * @csFName = Session filename for delete, if NULL nothing delete + * sess_freeSession() Free allocated memory for session item and delete session file if present name + * * @Sess = Session item + * return: none */ -inline void freeSession(const char *csFName, tagSess ** __restrict Sess) +void +sess_freeSession(ait_sess_t ** __restrict Sess) { - (*Sess)->type ^= (*Sess)->type; - if (csFName) - unlink(csFName); - if (*Sess) - free(*Sess); + if (!Sess || !(*Sess)) + return; + + if ((*Sess)->addr) + DETACH_MEMORY(*Sess); + + /* + memset(&(*Sess)->sess, 0, sizeof (*Sess)->sess); + + (*Sess)->type = SHARED_UNKNOWN; + */ + + free(*Sess); *Sess = NULL; } /* * map_createSession() MMAP Created session and allocated resources - * @csFName = Session name for identified - * @cnSeed = Seed for securing key - * @cnSize = Allocated shared memory size in bytes + * + * @nSeed = Seed for securing key, if =-1 must add ready for use key + * @nSize = Allocated shared memory size in bytes * @Sess = Session item + * @... = If nSeed == -1 add ready for use key value * return: 0 Ok successful, -1 error: not allocated resources */ -int map_createSession(const char *csFName, const int cnSeed, const u_int cnSize, tagSess ** __restrict Sess) +int +map_createSession(int nSeed, long nSize, ait_sess_t * __restrict Sess, ...) { - int ret = 0; - char szSName[2][FILENAME_MAX + 1]; - void *mem; + char szSName[2][FILENAME_MAX]; + va_list lst; - ret = initSession(SHARED_MAP, csFName, Sess); - if (ret == -1 || !*Sess) + if (!Sess || !*Sess->name) return -1; - // genkey - (*Sess)->key = ftok(csFName, cnSeed); - if ((*Sess)->key == -1) { - LOGERR; - freeSession(csFName, Sess); - return -1; + if (nSeed != -1) { + /* genkey */ + Sess->key = ftok(Sess->name, nSeed); + if (Sess->key == -1) { + LOGERR; + 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 - memset(szSName, 0, (FILENAME_MAX + 1) * 2); - snprintf(szSName[0], MAX_SEMNAME + 1, "/%X.ANS", (u_int) (*Sess)->key); - snprintf(szSName[1], FILENAME_MAX + 1, "%s-%x.ANM", csFName, (u_int) (*Sess)->key); + /* build semaphore & shared memory name */ + memset(szSName, 0, sizeof szSName); + snprintf(szSName[0], MAX_SEMNAME, "/%X.ANS", (u_int) Sess->key); + snprintf(szSName[1], FILENAME_MAX, "%s-%x.ANM", Sess->name, (u_int) Sess->key); - mem = malloc(cnSize); - if (!mem) { + /* create semaphore & add 1 */ + Sess->id.sid = sem_open(szSName[0], O_CREAT, MEM_MODE); + if (Sess->id.sid == SEM_FAILED) { LOGERR; - freeSession(csFName, Sess); + map_destroySession(Sess); return -1; - } else - memset(mem, 0, cnSize); + } + /* if is new shared memory session, init sempahore with 1 */ + if (!Sess->zcpy) + sem_post(Sess->id.sid); - // create semaphore & add 1 - (*Sess)->id.sid = sem_open(szSName[0], O_CREAT, 0644); - if ((*Sess)->id.sid == SEM_FAILED) { + /* create file for shared memory storage */ + Sess->mem.fd = open(szSName[1], O_RDWR | O_CREAT, MEM_MODE); + if (Sess->mem.fd == -1) { LOGERR; - map_destroySession(csFName, Sess); - free(mem); + map_destroySession(Sess); return -1; - } else - sem_post((*Sess)->id.sid); - - // create file for shared memory storage - (*Sess)->mem.fd = open(szSName[1], O_RDWR | O_CREAT, 0644); - if ((*Sess)->mem.fd == -1) { - LOGERR; - map_destroySession(csFName, Sess); - free(mem); - return -1; } - // if is new shared memory session, fill file with zeros - if (!ret) { - if (write((*Sess)->mem.fd, mem, cnSize) != cnSize) { + /* if is new shared memory session, fill file with zeros */ + if (!Sess->zcpy) { + if (lseek(Sess->mem.fd, nSize - 1, SEEK_SET) == -1) { LOGERR; - map_destroySession(csFName, Sess); - free(mem); + map_destroySession(Sess); return -1; - } - if (lseek((*Sess)->mem.fd, 0, SEEK_SET)) { - LOGERR; - map_destroySession(csFName, Sess); - free(mem); - return -1; - } + } else + write(Sess->mem.fd, "", 1); + lseek(Sess->mem.fd, 0, SEEK_SET); } - (*Sess)->eom = cnSize; + Sess->eom = nSize; - free(mem); - return ret; + return (int) Sess->zcpy; } /* * map_destroySession() MMAP free shared resources - * @csFName = Session name for delete + * * @Sess = Session item + * return: none */ -void map_destroySession(const char *csFName, tagSess ** __restrict Sess) +void +map_destroySession(ait_sess_t * __restrict Sess) { - int flg = 1; - char szSName[2][FILENAME_MAX + 1]; + char szSName[2][FILENAME_MAX]; - if (!*Sess) + if (!Sess || sess_isAttached(Sess) || !*Sess->name) return; - bzero(szSName, (FILENAME_MAX + 1) * 2); - snprintf(szSName[0], MAX_SEMNAME + 1, "/%X.ANS", (u_int) (*Sess)->key); - snprintf(szSName[1], FILENAME_MAX + 1, "%s-%x.ANM", csFName, (u_int) (*Sess)->key); + memset(szSName, 0, sizeof szSName); + snprintf(szSName[0], MAX_SEMNAME, "/%X.ANS", (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 (sem_close((*Sess)->id.sid) == -1) - flg = 0; - - if (sem_unlink(szSName[0]) == -1) - /*flg = 0*/; + if (Sess->id.sid != SEM_FAILED) { + sem_close(Sess->id.sid); + sem_unlink(szSName[0]); } - if ((*Sess)->mem.fd != -1) { - if (close((*Sess)->mem.fd) == -1) - flg = 0; - - if (unlink(szSName[1]) == -1) - /*flg = 0*/; + if (Sess->mem.fd > 2) { + close(Sess->mem.fd); + unlink(szSName[1]); } - (*Sess)->eom ^= (*Sess)->eom; - - freeSession(flg ? csFName : NULL, Sess); + unlink(Sess->name); + memset(Sess->name, 0, sizeof Sess->name); + Sess->eom ^= Sess->eom; + Sess->key ^= Sess->key; } /* * ipc_createSession() IPC Created session and allocated resources - * @csFName = Session name for identified - * @cnSeed = Seed for securing key - * @cnSize = Allocated shared memory size in bytes + * + * @nSeed = Seed for securing key, if =-1 must add ready for use key + * @nSize = Allocated shared memory size in bytes * @Sess = Session item + * @... = If nSeed == -1 add ready for use key value * return: 0 Ok successful, -1 error: not allocated resources -*/ -int ipc_createSession(const char *csFName, const int cnSeed, const u_int cnSize, tagSess ** __restrict Sess) + */ +int +ipc_createSession(int nSeed, long nSize, ait_sess_t * __restrict Sess, ...) { - int ret = 0; union semun sems; + va_list lst; - ret = initSession(SHARED_IPC, csFName, Sess); - if (ret == -1 || !*Sess) + if (!Sess || !*Sess->name) return -1; - // genkey - (*Sess)->key = ftok(csFName, cnSeed); - if ((*Sess)->key == -1) { - LOGERR; - freeSession(csFName, Sess); - return -1; + if (nSeed != -1) { + /* genkey */ + Sess->key = ftok(Sess->name, nSeed); + if (Sess->key == -1) { + LOGERR; + return -1; + } + } else { + /* get key from va_args */ + va_start(lst, Sess); + Sess->key = va_arg(lst, key_t); + va_end(lst); } - // create semaphore - (*Sess)->id.semid = semget((*Sess)->key, 1, 0644 | IPC_CREAT); - if ((*Sess)->id.semid == -1) { + /* create semaphore */ + Sess->id.semid = semget(Sess->key, 1, MEM_MODE | IPC_CREAT); + if (Sess->id.semid == -1) { LOGERR; - ipc_destroySession(csFName, Sess); + ipc_destroySession(Sess); return -1; } - // if is new shared memory session, init sempahore with 1 - if (!ret) { + /* if is new shared memory session, init sempahore with 1 */ + if (!Sess->zcpy) { sems.val = 1; - if (semctl((*Sess)->id.semid, 0, SETVAL, sems) == -1) { + if (semctl(Sess->id.semid, 0, SETVAL, sems) == -1) { LOGERR; - ipc_destroySession(csFName, Sess); + ipc_destroySession(Sess); return -1; } } - // create shared memory object - (*Sess)->mem.shmid = shmget((*Sess)->key, cnSize, 0644 | IPC_CREAT); - if ((*Sess)->mem.shmid == -1) { + /* create shared memory object */ + Sess->mem.shmid = shmget(Sess->key, nSize, MEM_MODE | IPC_CREAT); + if (Sess->mem.shmid == -1) { LOGERR; - ipc_destroySession(csFName, Sess); + ipc_destroySession(Sess); return -1; - } - (*Sess)->eom = cnSize; + } else + Sess->eom = nSize; - return ret; + return (int) Sess->zcpy; } /* * ipc_destroySession() IPC free shared resources - * @csFName = Session name for delete + * * @Sess = Session item -*/ -void ipc_destroySession(const char *csFName, tagSess ** __restrict Sess) + * return: none + */ +void +ipc_destroySession(ait_sess_t * __restrict Sess) { - int flg = 1; union semun sems; struct shmid_ds ds; - if (!*Sess) + if (!Sess || sess_isAttached(Sess)) return; - if ((*Sess)->id.semid != -1) - if (semctl((*Sess)->id.semid, 0, IPC_RMID, &sems) == -1) - flg = 0; - if ((*Sess)->mem.shmid != -1) - if (shmctl((*Sess)->mem.shmid, IPC_RMID, &ds) == -1) - flg = 0; - (*Sess)->eom ^= (*Sess)->eom; - - freeSession(flg ? csFName : NULL, Sess); + if (Sess->id.semid != -1) + semctl(Sess->id.semid, 0, IPC_RMID, &sems); + if (Sess->mem.shmid != -1) + shmctl(Sess->mem.shmid, IPC_RMID, &ds); + unlink(Sess->name); + memset(Sess->name, 0, sizeof Sess->name); + Sess->eom ^= Sess->eom; + Sess->key ^= Sess->key; } /* * map_attachSession() MMAP Attach to shared memory & return begin address + * * @s = Session item * @procMem = Custom start address (optionl) *default must be 0* * return: NULL failed attach, !=NULL begin address of memory -*/ -inline void *map_attachSession(tagSess * __restrict s, void *procMem) + */ +void * +map_attachSession(ait_sess_t * __restrict s, void *procMem) { - struct stat sb; - if (!s) return NULL; - // Learn size of shared memory block 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); if (s->addr == MAP_FAILED) { LOGERR; @@ -339,9 +455,12 @@ inline void *map_attachSession(tagSess * __restrict s, /* * map_detachSession() MMAP Detach from shared memory + * * @s = Session item -*/ -inline void map_detachSession(tagSess * __restrict s) + * return: none + */ +void +map_detachSession(ait_sess_t * __restrict s) { if (!s) return; @@ -356,11 +475,13 @@ inline void map_detachSession(tagSess * __restrict s) /* * ipc_attachSession() IPC Attach to shared memory & return begin address + * * @s = Session item * @procMem = Custom start address (optionl) *default must be 0* * return: NULL failed attach, !=NULL begin address of memory -*/ -inline void *ipc_attachSession(tagSess * __restrict s, void *procMem) + */ +void * +ipc_attachSession(ait_sess_t * __restrict s, void *procMem) { if (!s) return NULL; @@ -376,9 +497,12 @@ inline void *ipc_attachSession(tagSess * __restrict s, /* * ipc_detachSession() IPC Detach from shared memory + * * @s = Session item -*/ -inline void ipc_detachSession(tagSess * __restrict s) + * return: none + */ +void +ipc_detachSession(ait_sess_t * __restrict s) { if (!s) return; @@ -389,12 +513,30 @@ inline void ipc_detachSession(tagSess * __restrict s) } } +/* + * sess_isAttached() Check for attached shared memory + * + * @s = Session item + * return: -1 null session item, 0 not attached, 1 attached memory + */ +inline int +sess_isAttached(ait_sess_t * __restrict s) +{ + if (!s) + return -1; + return (s->addr ? 1 : 0); +} + + /* * map_notSemaphore() MMAP negative block if semaphore isn`t signaled + * * @s = Session item -*/ -inline void map_notSemaphore(tagSess * __restrict s) + * return: none + */ +void +map_notSemaphore(ait_sess_t * __restrict s) { int i = -1; @@ -402,16 +544,20 @@ inline void map_notSemaphore(tagSess * __restrict s) return; sem_getvalue(s->id.sid, &i); - for (;i > 0; i--) + while (i > 0) { sem_wait(s->id.sid); + i--; + } } /* - * map_isSemaphored() MMAP Check semaphore + * map_isSemaphoreOK() MMAP Check semaphore + * * @s = Session item * return: -1 error: can`t return semaphore, 0 = false, 1 = true -*/ -inline int map_isSemaphored(tagSess * __restrict s) + */ +int +map_isSemaphoreOK(ait_sess_t * __restrict s) { int val = -1; @@ -419,15 +565,17 @@ inline int map_isSemaphored(tagSess * __restrict s) return -1; 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 * return: 0 Ok, -1 error: can`t increment -*/ -inline int map_addSemaphore(tagSess * __restrict s) + */ +int +map_incSemaphore(ait_sess_t * __restrict s) { if (!s) return -1; @@ -437,10 +585,12 @@ inline int map_addSemaphore(tagSess * __restrict s) /* * map_decSemaphore() MMAP block semaphore, decrement semaphore + * * @s = Session item * return: 0 Ok, -1 error: can`t decrement -*/ -inline int map_decSemaphore(tagSess * __restrict s) + */ +int +map_decSemaphore(ait_sess_t * __restrict s) { if (!s) return -1; @@ -450,9 +600,12 @@ inline int map_decSemaphore(tagSess * __restrict s) /* * ipc_notSemaphore() IPC negative block if semaphore isn`t signaled + * * @s = Session item -*/ -inline void ipc_notSemaphore(tagSess * __restrict s) + * return: none + */ +void +ipc_notSemaphore(ait_sess_t * __restrict s) { struct sembuf sb = { 0, 0, 0 }; @@ -461,11 +614,13 @@ inline void ipc_notSemaphore(tagSess * __restrict s) } /* - * ipc_isSemaphored() IPC Check semaphore + * ipc_isSemaphoreOK() IPC Check semaphore + * * @s = Session item * return: -1 error: can`t return semaphore, 0 = false, 1 = true -*/ -inline int ipc_isSemaphored(tagSess * __restrict s) + */ +int +ipc_isSemaphoreOK(ait_sess_t * __restrict s) { struct sembuf sb = { 0, 0, IPC_NOWAIT }; @@ -476,11 +631,13 @@ inline int ipc_isSemaphored(tagSess * __restrict s) } /* - * ipc_addSemaphore() IPC unblock semaphore, increment semaphore + * ipc_incSemaphore() IPC unblock semaphore, increment semaphore + * * @s = Session item * return: 0 Ok, -1 error: can`t increment -*/ -inline int ipc_addSemaphore(tagSess * __restrict s) + */ +int +ipc_incSemaphore(ait_sess_t * __restrict s) { struct sembuf sb = { 0, 1, 0 }; @@ -492,10 +649,12 @@ inline int ipc_addSemaphore(tagSess * __restrict s) /* * ipc_decSemaphore() IPC block semaphore, decrement semaphore + * * @s = Session item * return: 0 Ok, -1 error: can`t decrement -*/ -inline int ipc_decSemaphore(tagSess * __restrict s) + */ +int +ipc_decSemaphore(ait_sess_t * __restrict s) { struct sembuf sb = { 0, -1, 0 };