--- libaitsess/src/aitsess.c 2011/04/30 21:35:21 1.2 +++ libaitsess/src/aitsess.c 2011/05/10 21:06:13 1.2.2.2 @@ -3,9 +3,46 @@ * by Michael Pounov * * $Author: misho $ -* $Id: aitsess.c,v 1.2 2011/04/30 21:35:21 misho Exp $ +* $Id: aitsess.c,v 1.2.2.2 2011/05/10 21:06:13 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" @@ -22,17 +59,20 @@ 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; } // sess_GetError() Get error text of last operation -inline const char *sess_GetError() +inline const char * +sess_GetError() { return sessError; } // sessDbg() Debug/Logging operations -static inline int sessDbg(FILE *f, char *fmt, ...) +static inline int +sessDbg(FILE *f, char *fmt, ...) { int ret = 0; va_list lst; @@ -53,7 +93,8 @@ static inline int sessDbg(FILE *f, char *fmt, ...) * @Sess = Session item * 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) +inline int +initSession(const int cnID, const char *csFName, tagSess ** __restrict Sess) { int h, ret = 0; char szStr[MAX_STR + 1]; @@ -109,7 +150,8 @@ inline int initSession(const int cnID, const char *csF * @csFName = Session filename for delete, if NULL nothing delete * @Sess = Session item */ -inline void freeSession(const char *csFName, tagSess ** __restrict Sess) +inline void +freeSession(const char *csFName, tagSess ** __restrict Sess) { (*Sess)->type ^= (*Sess)->type; if (csFName) @@ -128,7 +170,8 @@ inline void freeSession(const char *csFName, tagSess * * @Sess = Session item * 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(const char *csFName, const int cnSeed, const u_int cnSize, tagSess ** __restrict Sess) { int ret = 0; char szSName[2][FILENAME_MAX + 1]; @@ -203,7 +246,8 @@ int map_createSession(const char *csFName, const int c * @csFName = Session name for delete * @Sess = Session item */ -void map_destroySession(const char *csFName, tagSess ** __restrict Sess) +void +map_destroySession(const char *csFName, tagSess ** __restrict Sess) { int flg = 1; char szSName[2][FILENAME_MAX + 1]; @@ -242,7 +286,8 @@ void map_destroySession(const char *csFName, tagSess * * @Sess = Session item * 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(const char *csFName, const int cnSeed, const u_int cnSize, tagSess ** __restrict Sess) { int ret = 0; union semun sems; @@ -293,7 +338,8 @@ int ipc_createSession(const char *csFName, const int c * @csFName = Session name for delete * @Sess = Session item */ -void ipc_destroySession(const char *csFName, tagSess ** __restrict Sess) +void +ipc_destroySession(const char *csFName, tagSess ** __restrict Sess) { int flg = 1; union semun sems; @@ -320,7 +366,8 @@ void ipc_destroySession(const char *csFName, tagSess * * @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) +inline void * +map_attachSession(tagSess * __restrict s, void *procMem) { struct stat sb; @@ -349,7 +396,8 @@ inline void *map_attachSession(tagSess * __restrict s, * map_detachSession() MMAP Detach from shared memory * @s = Session item */ -inline void map_detachSession(tagSess * __restrict s) +inline void +map_detachSession(tagSess * __restrict s) { if (!s) return; @@ -368,7 +416,8 @@ inline void map_detachSession(tagSess * __restrict s) * @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) +inline void * +ipc_attachSession(tagSess * __restrict s, void *procMem) { if (!s) return NULL; @@ -386,7 +435,8 @@ inline void *ipc_attachSession(tagSess * __restrict s, * ipc_detachSession() IPC Detach from shared memory * @s = Session item */ -inline void ipc_detachSession(tagSess * __restrict s) +inline void +ipc_detachSession(tagSess * __restrict s) { if (!s) return; @@ -402,7 +452,8 @@ inline void ipc_detachSession(tagSess * __restrict s) * @s = Session item * return: -1 null session item, 0 not attached, 1 attached memory */ -inline int isAttached(tagSess * __restrict s) +inline int +isAttached(tagSess * __restrict s) { if (!s) return -1; @@ -415,7 +466,8 @@ inline int isAttached(tagSess * __restrict s) * map_notSemaphore() MMAP negative block if semaphore isn`t signaled * @s = Session item */ -inline void map_notSemaphore(tagSess * __restrict s) +inline void +map_notSemaphore(tagSess * __restrict s) { int i = -1; @@ -432,7 +484,8 @@ inline void map_notSemaphore(tagSess * __restrict s) * @s = Session item * return: -1 error: can`t return semaphore, 0 = false, 1 = true */ -inline int map_isSemaphored(tagSess * __restrict s) +inline int +map_isSemaphored(tagSess * __restrict s) { int val = -1; @@ -448,7 +501,8 @@ inline int map_isSemaphored(tagSess * __restrict s) * @s = Session item * return: 0 Ok, -1 error: can`t increment */ -inline int map_addSemaphore(tagSess * __restrict s) +inline int +map_addSemaphore(tagSess * __restrict s) { if (!s) return -1; @@ -461,7 +515,8 @@ inline int map_addSemaphore(tagSess * __restrict s) * @s = Session item * return: 0 Ok, -1 error: can`t decrement */ -inline int map_decSemaphore(tagSess * __restrict s) +inline int +map_decSemaphore(tagSess * __restrict s) { if (!s) return -1; @@ -473,7 +528,8 @@ 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) +inline void +ipc_notSemaphore(tagSess * __restrict s) { struct sembuf sb = { 0, 0, 0 }; @@ -486,7 +542,8 @@ inline void ipc_notSemaphore(tagSess * __restrict s) * @s = Session item * return: -1 error: can`t return semaphore, 0 = false, 1 = true */ -inline int ipc_isSemaphored(tagSess * __restrict s) +inline int +ipc_isSemaphored(tagSess * __restrict s) { struct sembuf sb = { 0, 0, IPC_NOWAIT }; @@ -501,7 +558,8 @@ inline int ipc_isSemaphored(tagSess * __restrict s) * @s = Session item * return: 0 Ok, -1 error: can`t increment */ -inline int ipc_addSemaphore(tagSess * __restrict s) +inline int +ipc_addSemaphore(tagSess * __restrict s) { struct sembuf sb = { 0, 1, 0 }; @@ -516,7 +574,8 @@ inline int ipc_addSemaphore(tagSess * __restrict s) * @s = Session item * return: 0 Ok, -1 error: can`t decrement */ -inline int ipc_decSemaphore(tagSess * __restrict s) +inline int +ipc_decSemaphore(tagSess * __restrict s) { struct sembuf sb = { 0, -1, 0 };