--- libaitsess/src/sess.c 2012/05/23 15:14:41 1.4.4.1 +++ libaitsess/src/sess.c 2013/01/17 13:26:37 1.5.4.2 @@ -3,7 +3,7 @@ * by Michael Pounov * * $Author: misho $ -* $Id: sess.c,v 1.4.4.1 2012/05/23 15:14:41 misho Exp $ +* $Id: sess.c,v 1.5.4.2 2013/01/17 13:26:37 misho Exp $ * ************************************************************************** The ELWIX and AITNET software is distributed under the following @@ -12,7 +12,7 @@ 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 +Copyright 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2013 by Michael Pounov . All rights reserved. Redistribution and use in source and binary forms, with or without @@ -44,11 +44,10 @@ OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF TH SUCH DAMAGE. */ #include "global.h" -#include "aitsess.h" /* - * sess_FreeValues() Free all values from value array allocated from sess_GetValues() + * sess_FreeValues() - Free all values from value array allocated from sess_GetValues() * * @ppsVals = Array strings * return: none @@ -63,17 +62,18 @@ sess_FreeValues(char *** __restrict ppsVals) return; for (ptr = *ppsVals; *ptr; ptr++) - io_free(*ptr); - io_free(*ppsVals); + e_free(*ptr); + e_free(*ppsVals); *ppsVals = NULL; } /* - * sess_GetValues() Get all values from session shared memory + * 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!) + * return: -1 error: in parameter, !=-1 count of returned strings in ppsVals + * (must be sess_FreeValues after use!) */ int sess_GetValues(ait_sess_t * __restrict s, char ***ppsVals) @@ -84,18 +84,18 @@ sess_GetValues(ait_sess_t * __restrict s, char ***ppsV if (!s || !ppsVals) return -1; - valz = io_malloc(sizeof(caddr_t)); + valz = e_malloc(sizeof(caddr_t)); if (!valz) { LOGERR; return -1; } else *valz = NULL; - // allocated memory & mirrored shared memory into this - Shared = io_malloc(s->eom); + /* allocated memory & mirrored shared memory into this */ + Shared = e_malloc(s->eom); if (!Shared) { LOGERR; - io_free(valz); + e_free(valz); return -1; } else memcpy(Shared, s->addr, s->eom); @@ -107,31 +107,32 @@ sess_GetValues(ait_sess_t * __restrict s, char ***ppsV else i++; - valz = io_realloc(valz, (i + 1) * sizeof(caddr_t)); + valz = e_realloc(valz, (i + 1) * sizeof(caddr_t)); if (!valz) { LOGERR; - io_free(Shared); + e_free(Shared); return -1; } else valz[i] = NULL; - valz[i - 1] = io_strdup(peer); + valz[i - 1] = e_strdup(peer); } - io_free(Shared); + e_free(Shared); *ppsVals = valz; return i; } /* - * sess_GetValue() Get value from session shared memory from attribute + * 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 + * return: 0 not found, -1 error: in parameter, >0 get position, + * if define item merged with IS_DEF */ int sess_GetValue(ait_sess_t * __restrict s, const char *csAttr, char *psVal, int *pnLen) @@ -150,8 +151,8 @@ sess_GetValue(ait_sess_t * __restrict s, const char *c return -1; } - // allocated memory & mirrored shared memory into this - Shared = io_malloc(s->eom); + /* allocated memory & mirrored shared memory into this */ + Shared = e_malloc(s->eom); if (!Shared) { LOGERR; return -1; @@ -171,17 +172,17 @@ sess_GetValue(ait_sess_t * __restrict s, const char *c } else def = IS_DEF; - io_free(Shared); + e_free(Shared); return i | def; } } - io_free(Shared); + e_free(Shared); return 0; } /* - * sess_DelValue() Delete item from session shared memory + * sess_DelValue() - Delete item from session shared memory * * @s = Session item * @csAttr = Attribute for erasing @@ -203,16 +204,16 @@ sess_DelValue(ait_sess_t * __restrict s, const char *c strlcpy(szAttr, csAttr, sizeof szAttr); strlcat(szAttr, "=", sizeof szAttr); - Buffer = io_malloc(s->eom); + Buffer = e_malloc(s->eom); if (!Buffer) { LOGERR; return -1; } else memset(Buffer, 0, s->eom); - Shared = io_malloc(s->eom); + Shared = e_malloc(s->eom); if (!Shared) { LOGERR; - io_free(Buffer); + e_free(Buffer); return -1; } else { DEC_SEM(s); @@ -236,13 +237,13 @@ sess_DelValue(ait_sess_t * __restrict s, const char *c msync(s->addr, 0, MS_SYNC | MS_INVALIDATE); INC_SEM(s); - io_free(Shared); - io_free(Buffer); + e_free(Shared); + e_free(Buffer); return 0; } /* - * sess_SetValue() Set item into session shared memory or update if find it + * sess_SetValue() - Set item into session shared memory or update if exists * * @s = Session item * @csAttr = Attribute @@ -265,16 +266,16 @@ sess_SetValue(ait_sess_t * __restrict s, const char *c strlcpy(szAttr, csAttr, sizeof szAttr); strlcat(szAttr, "=", sizeof szAttr); - Buffer = io_malloc(s->eom); + Buffer = e_malloc(s->eom); if (!Buffer) { LOGERR; return -1; } else memset(Buffer, 0, s->eom); - Shared = io_malloc(s->eom); + Shared = e_malloc(s->eom); if (!Shared) { LOGERR; - io_free(Buffer); + e_free(Buffer); return -1; } else { DEC_SEM(s); @@ -320,14 +321,14 @@ sess_SetValue(ait_sess_t * __restrict s, const char *c msync(s->addr, 0, MS_SYNC | MS_INVALIDATE); INC_SEM(s); - io_free(Shared); - io_free(Buffer); + e_free(Shared); + e_free(Buffer); return upd | def; } /* - * sess_prepareSession() Attach to shared memory and de-marshaling data + * 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 @@ -342,11 +343,11 @@ sess_prepareSession(ait_sess_t * __restrict s, char us assert(s); if (!s) { - sess_SetErr(EINVAL, "Error:: invalid argument\n"); + sess_SetErr(EINVAL, "Invalid argument\n"); return NULL; } if (s->addr) { - sess_SetErr(EINVAL, "Error:: already attached memory\n"); + sess_SetErr(EINVAL, "Already attached memory\n"); return NULL; } @@ -358,13 +359,13 @@ sess_prepareSession(ait_sess_t * __restrict s, char us if (hdr->hdr_magic != SESS_AIT_MAGIC) { DETACH_MEMORY(s); - sess_SetErr(EINVAL, "Error:: shared memory not contains values with proper format\n"); + sess_SetErr(EINVAL, "Shared memory not contains values with proper format\n"); return NULL; } DEC_SEM(s); s->zcpy = useDirect; - arr = io_map2vars(s->addr + sizeof(sess_hdr_t), s->eom - sizeof(sess_hdr_t), + arr = ait_map2vars(s->addr + sizeof(sess_hdr_t), s->eom - sizeof(sess_hdr_t), hdr->hdr_argc, useDirect); INC_SEM(s); @@ -374,7 +375,7 @@ sess_prepareSession(ait_sess_t * __restrict s, char us } /* - * sess_doneSession() Free resources allocated with sess_prepareSession() + * sess_doneSession() - Free resources allocated with sess_prepareSession() * * @s = Session * @arr = Array with variables for free @@ -385,19 +386,19 @@ sess_doneSession(ait_sess_t * __restrict s, array_t ** { assert(s); if (!s) { - sess_SetErr(EINVAL, "Error:: invalid argument\n"); + sess_SetErr(EINVAL, "Invalid argument\n"); return; } if (!s->zcpy) - io_arrayFree(*arr); + array_Free(*arr); else DETACH_MEMORY(s); - io_arrayDestroy(arr); + array_Destroy(arr); } /* - * sess_commitSession() Commit data to shared memory + * sess_commitSession() - Commit data to shared memory * * @s = Session * @arr = Array with variables for save @@ -411,7 +412,7 @@ sess_commitSession(ait_sess_t * __restrict s, array_t assert(s && arr); if (!s || !arr) { - sess_SetErr(EINVAL, "Error:: invalid argument\n"); + sess_SetErr(EINVAL, "Invalid argument\n"); return -1; } @@ -423,9 +424,10 @@ sess_commitSession(ait_sess_t * __restrict s, array_t hdr = (sess_hdr_t*) s->addr; DEC_SEM(s); - if ((ret = io_vars2map(s->addr + sizeof(sess_hdr_t), s->eom - sizeof(sess_hdr_t), arr)) != -1) { + if ((ret = ait_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); + hdr->hdr_argc = array_Size(arr); ret += sizeof(sess_hdr_t); } INC_SEM(s);