--- libaitsess/src/sess.c 2011/11/03 15:36:03 1.3.2.7 +++ libaitsess/src/sess.c 2012/02/10 16:45:36 1.3.2.8 @@ -3,7 +3,7 @@ * by Michael Pounov * * $Author: misho $ -* $Id: sess.c,v 1.3.2.7 2011/11/03 15:36:03 misho Exp $ +* $Id: sess.c,v 1.3.2.8 2012/02/10 16:45:36 misho Exp $ * ************************************************************************** The ELWIX and AITNET software is distributed under the following @@ -49,9 +49,10 @@ SUCH DAMAGE. /* * sess_FreeValues() Free all values from value array allocated from sess_GetValues() + * * @ppsVals = Array strings * return: none -*/ + */ inline void sess_FreeValues(char *** __restrict ppsVals) { @@ -69,12 +70,13 @@ sess_FreeValues(char *** __restrict ppsVals) /* * sess_GetValues() Get all values from session shared memory + * * @s = Session item * @ppsVals = Return array strings * return: -1 error: in parameter, !=-1 count of returned strings in ppsVals (must be free after use!) -*/ + */ int -sess_GetValues(tagSess * __restrict s, char ***ppsVals) +sess_GetValues(ait_sess_t * __restrict s, char ***ppsVals) { register int i; char **valz, *Shared = NULL; @@ -123,15 +125,16 @@ sess_GetValues(tagSess * __restrict s, char ***ppsVals /* * sess_GetValue() Get value from session shared memory from attribute + * * @s = Session item * @csAttr = Attribute for search * @psVal = Return string buffer * @pnLen = Length of return string buffer, // *{pnLen} input is max_size of buffer & output is really taken bytes * return: 0 not found, -1 error: in parameter, >0 get position, if define item merged with IS_DEF -*/ + */ int -sess_GetValue(tagSess * __restrict s, const char *csAttr, char *psVal, int *pnLen) +sess_GetValue(ait_sess_t * __restrict s, const char *csAttr, char *psVal, int *pnLen) { register int i; int def = IS_VAL; @@ -179,15 +182,16 @@ sess_GetValue(tagSess * __restrict s, const char *csAt /* * sess_DelValue() Delete item from session shared memory + * * @s = Session item * @csAttr = Attribute for erasing * return: 0 Ok, -1 error: in parameter -*/ + */ int -sess_DelValue(tagSess * __restrict s, const char *csAttr) +sess_DelValue(ait_sess_t * __restrict s, const char *csAttr) { register int i; - int ret, attrlen; + int attrlen; char *Buffer, *Shared, szAttr[MAX_ATTRIBUTE]; char *peer, *p_brk; @@ -211,7 +215,7 @@ sess_DelValue(tagSess * __restrict s, const char *csAt free(Buffer); return -1; } else { - DEC_SEMAPHORE(s, ret); + DEC_SEM(s); memcpy(Shared, s->addr, s->eom); } @@ -231,7 +235,7 @@ sess_DelValue(tagSess * __restrict s, const char *csAt if (s->type == SHARED_MAP) msync(s->addr, 0, MS_SYNC | MS_INVALIDATE); - ADD_SEMAPHORE(s, ret); + INC_SEM(s); free(Shared); free(Buffer); return 0; @@ -239,17 +243,18 @@ sess_DelValue(tagSess * __restrict s, const char *csAt /* * sess_SetValue() Set item into session shared memory or update if find it + * * @s = Session item * @csAttr = Attribute * @psVal = Value * return: 0 nothing, -1 error: in parameter, >0 set position, if add item merged with IS_ADD and if define item merged with IS_DEF -*/ + */ int -sess_SetValue(tagSess * __restrict s, const char *csAttr, const char *psVal) +sess_SetValue(ait_sess_t * __restrict s, const char *csAttr, const char *psVal) { register int i; - int upd, ret, def = IS_VAL; + int upd, def = IS_VAL; char *Buffer, *Shared, szAttr[MAX_ATTRIBUTE]; char *peer, *p_brk; @@ -272,7 +277,7 @@ sess_SetValue(tagSess * __restrict s, const char *csAt free(Buffer); return -1; } else { - DEC_SEMAPHORE(s, ret); + DEC_SEM(s); memcpy(Shared, s->addr, s->eom); } @@ -314,7 +319,7 @@ sess_SetValue(tagSess * __restrict s, const char *csAt if (s->type == SHARED_MAP) msync(s->addr, 0, MS_SYNC | MS_INVALIDATE); - ADD_SEMAPHORE(s, ret); + INC_SEM(s); free(Shared); free(Buffer); return upd | def; @@ -323,17 +328,17 @@ sess_SetValue(tagSess * __restrict s, const char *csAt /* * sess_prepareSession() Attach to shared memory and de-marshaling data + * * @s = Session * @useDirect = Use direct shared memory if !=0 or snapshot of data to array * return: NULL error or no data, !=NULL array with variables, * after use must free resources with sess_doneSession() */ array_t * -sess_prepareSession(tagSess * __restrict s, u_char useDirect) +sess_prepareSession(ait_sess_t * __restrict s, char useDirect) { array_t *arr = NULL; sess_hdr_t *hdr; - int ret; assert(s); if (!s) { @@ -357,25 +362,26 @@ sess_prepareSession(tagSess * __restrict s, u_char use return NULL; } - DEC_SEMAPHORE(s, ret); - s->zcopy = useDirect; + DEC_SEM(s); + s->zcpy = useDirect; arr = io_map2vars(s->addr + sizeof(sess_hdr_t), s->eom - sizeof(sess_hdr_t), hdr->hdr_argc, useDirect); - ADD_SEMAPHORE(s, ret); + INC_SEM(s); - if (!s->zcopy) + if (!s->zcpy) DETACH_MEMORY(s); return arr; } /* * sess_doneSession() Free resources allocated with sess_prepareSession() + * * @s = Session * @arr = Array with variables for free * return: none */ void -sess_doneSession(tagSess * __restrict s, array_t ** __restrict arr) +sess_doneSession(ait_sess_t * __restrict s, array_t ** __restrict arr) { assert(s); if (!s) { @@ -383,7 +389,7 @@ sess_doneSession(tagSess * __restrict s, array_t ** __ return; } - if (!s->zcopy) + if (!s->zcpy) io_arrayFree(*arr); else DETACH_MEMORY(s); @@ -392,15 +398,16 @@ sess_doneSession(tagSess * __restrict s, array_t ** __ /* * sess_commitSession() Commit data to shared memory + * * @s = Session * @arr = Array with variables for save * return -1 error or !=-1 size of stored variables into shared memory */ int -sess_commitSession(tagSess * __restrict s, array_t * __restrict arr) +sess_commitSession(ait_sess_t * __restrict s, array_t * __restrict arr) { sess_hdr_t *hdr; - int rs, ret = 0; + int ret = 0; assert(s && arr); if (!s || !arr) { @@ -415,13 +422,13 @@ sess_commitSession(tagSess * __restrict s, array_t * _ } else hdr = (sess_hdr_t*) s->addr; - DEC_SEMAPHORE(s, rs); + DEC_SEM(s); if ((ret = io_vars2map(s->addr + sizeof(sess_hdr_t), s->eom - sizeof(sess_hdr_t), arr)) != -1) { hdr->hdr_magic = SESS_AIT_MAGIC; hdr->hdr_argc = io_arraySize(arr); ret += sizeof(sess_hdr_t); } - ADD_SEMAPHORE(s, rs); + INC_SEM(s); DETACH_MEMORY(s); return ret;