#include <stdio.h>
#include <time.h>
#include "../../basext.h"
Go to the source code of this file.
Data Structures | |
struct | _SessionInfo |
struct | _MtClass |
struct | _MTVariable |
Defines | |
#define | MT_ERROR_NOSESSION 0x00080001 |
#define | MT_ERROR_BAD_PROG 0x00080002 |
#define | MT_ERROR_BAD_SESS 0x00080003 |
#define | IsUndef(pVar) ((pVar) == NULL || (pVar)->vType == VTYPE_UNDEF) |
#define | SESSION__CONSTRAINT |
Typedefs | |
typedef _SessionInfo | SessionInfo |
typedef _SessionInfo * | pSessionInfo |
typedef _MtClass | MtClass |
typedef _MtClass * | pMtClass |
typedef _MTVariable | MTVariable |
typedef _MTVariable * | pMTVariable |
Functions | |
static pSessionInfo | AllocNewSession (pSupportTable pSt, void *p) |
static void | ReleaseSession (pSupportTable pSt, pSessionInfo pS) |
static void | time_out_work_thread (void *p) |
INC_THREAD_COUNTER INITLOCK | if (iFirst) |
if (pMT=besMODULEPOINTER==NULL) | |
if (pMT->pszSessionId==NULL) return COMMAND_ERROR_MEMORY_LOW | |
strcpy (pMT->pszSessionId, SymbolName(p)) | |
besUnlockSharedRead (&(pS->lckSession)) | |
besEND | besFUNCTION (chksession) |
besLockMutex (&mxSessionCounter) | |
besUnlockMutex (&mxSessionCounter) | |
besMD5INIT (&Context) | |
besMD5UPDATE (&Context,(unsigned char *)&lThisSession, sizeof(unsigned long)) | |
if (Argument) | |
STRINGVALUE (besRETURNVALUE)[32] | |
if (p==NULL) | |
static besEND void | FinishSegmentCallBack (char *SymbolName, void *SymbolValue, void *f) |
besFUNCTION (delsession) | |
pSt | DeleteSymbol (pszSession, SessionTable, pSt->Free, besPROCMEMORYSEGMENT) |
if (pS==NULL) | |
besLockSharedWrite (&(pS->lckSession)) | |
besTRAVERSESYMBOLTABLE (pS->stSession, FinishSegmentCallBack, pSt) | |
besFINISH_SEGMENT (pS->pMemSeg) | |
besFinishMutex (&(pS->mxSession)) | |
besUnlockSharedWrite (&(pS->lckSession)) | |
besFinishSharedLock (&(pS->lckSession)) | |
ReleaseSession (pSt, pS) | |
if (!bSessDef) besFREE(pszSession) | |
besEND | besFUNCTION (getsession) |
besLockSharedWrite (&((*p)->lckV)) | |
besDEREFERENCE (Argument) | |
if ((*p)->vV &&TYPE((*p)->vV)==VTYPE_STRING &&STRINGVALUE((*p)->vV)) | |
if (IsUndef(Argument)) | |
if ((*p)->vV==NULL)(*p)->vV = besPROCALLOC(sizeof(FixSizeMemoryObject)) | |
if (TYPE(Argument)==VTYPE_STRING) | |
besUnlockSharedWrite (&((*p)->lckV)) | |
besEND | besFUNCTION (getsvariable) |
besLockSharedRead (&((*p)->lckV)) | |
if (TYPE((*p)->vV)==VTYPE_STRING) | |
besEND | besFUNCTION (setmtvariable) |
besEND | besFUNCTION (getmtvariable) |
besEND | besFUNCTION (lockmtwrite) |
besEND | besFUNCTION (lockmtread) |
besEND | besFUNCTION (unlockmtwrite) |
besEND | besFUNCTION (unlockmtread) |
besUnlockSharedRead (&((*p)->lckV)) | |
besEND | besFUNCTION (sessionto) |
if (VARIABLE Argument==NULL) | |
LONGVALUE (besRETURNVALUE) | |
besEND | besFUNCTION (getsespt) |
besEND | besFUNCTION (listses) |
if (cSessionList==0) | |
while (pS) | |
besEND besVERSION_NEGOTIATE | return (int) |
Variables | |
static SUPPORT_MULTITHREAD SymbolTable | MtVariables |
static SUPPORT_MULTITHREAD SymbolTable | SessionTable |
static MUTEX | mxMTVariables |
static MUTEX | mxSessionCounter |
static MUTEX | mxSessionTable |
static unsigned long | lSessionCounter |
static pSessionInfo | pSessionRoot |
besSUB_SHUTDOWN besEND besSUB_START pMtClass | pMT |
INITUNLO | besMODULEPOINTER = besALLOC(sizeof(MtClass)) |
pMT | AssignedSession = pS |
pS | lPingTime = time(NULL) |
lThisSession = lSessionCounter++ | |
pMT | AssignedSession = NULL |
p = pSt->LookupSymbol(STRINGVALUE(besRETURNVALUE),SessionTable,1,pSt->Alloc,pSt->Free,besPROCMEMORYSEGMENT) | |
pMT | AssignedSession = pS |
pS | lPingTime = time(NULL) |
p = pSt->LookupSymbol(pszSession,SessionTable,0,pSt->Alloc,pSt->Free,besPROCMEMORYSEGMENT) | |
pS = *p | |
Argument = besARGUMENT(2) | |
p vV | sType = 0 |
p vV | State = STATE_UNKNOWN |
p vV | next = NULL |
p vV link | prev = NULL |
p vV | ArrayHighLimit = 0 |
p vV | ArrayLowLimit = 1 |
return | EXE_ERROR_INTERNAL |
return | EXE_ERROR_INTERNAL |
Argument = besARGUMENT(2) | |
p vV | sType = 0 |
p vV | State = STATE_UNKNOWN |
p vV | next = NULL |
p vV link | prev = NULL |
p vV | ArrayHighLimit = 0 |
p vV | ArrayLowLimit = 1 |
return | EXE_ERROR_INTERNAL |
return | EXE_ERROR_INTERNAL |
return | COMMAND_ERROR_SUCCESS |
return | COMMAND_ERROR_SUCCESS |
return | COMMAND_ERROR_SUCCESS |
return | COMMAND_ERROR_SUCCESS |
Argument = besARGUMENT(1) | |
p = pSt->LookupSymbol(pszSession,SessionTable,0,pSt->Alloc,pSt->Free,besPROCMEMORYSEGMENT) | |
pS = *p | |
besALLOC_RETURN_LONG | |
p = pSt->LookupSymbol(pszSession,SessionTable,0,pSt->Alloc,pSt->Free,besPROCMEMORYSEGMENT) | |
pS = *p | |
besALLOC_RETURN_LONG | |
* | Lval = besNEWARRAY(1,cSessionList) |
cSessionList = 0 | |
return | lTC |
besEND besSUB_PROCESS_START INIT_MULTITHREAD | return |
besEND besSUB_PROCESS_FINISH FINISH_MULTITHREAD besEND SLFST | MT_SLFST [] |
|
Definition at line 151 of file interface.c. |
|
Definition at line 98 of file interface.c. |
|
Definition at line 99 of file interface.c. |
|
Definition at line 97 of file interface.c. Referenced by besFUNCTION(). |
|
Value: ( lToMin < pS->lTimeout ) && \ ( lPtMin < pS->lPingTime) && \ ( lStMin < pS->lTimeStart) &&\ ( (!lToMax) || lToMax > pS->lTimeout) && \ ( (!lPtMax) || lPtMax > pS->lPingTime) && \ ( (!lStMax) || lStMax > pS->lTimeStart) Referenced by while(). |
|
|
|
|
|
|
|
|
|
|
|
|
|
Definition at line 104 of file interface.c. References NULL, pS, and pSessionRoot. |
|
|
|
|
|
|
|
Referenced by FinishSegmentCallBack(). |
|
=section ListSessions =H mt::ListSessions This subroutine collects the session ids. =verbatim call mt::ListSessions Array,Sm,SM,Pm,PM,Tm,TM =noverbatim The first argument to the subroutine should be a variable. This variable will loose its previous value and gets a new array value containing the session strings. If there is no more arguments to the subroutine call this array will contain all the existing sessions in the MT module. However the programmer may define six optional parameters that select only certain sessions that have time value parameters that are between the specified values. These are =itemize =item T<Sm> required minimal start time of the session =item T<SM> required maximal start time of the session =item T<Pm> required minimal ping time of the session =item T<PM> required maximal ping time of the session =item T<Tm> required minimal time-out time of the session =item T<TM> required maximal time-out time of the session =noitemize These time values have to be expressed as GTM time stamps. If a value is zero or T<undef> the value in the constraint is ignored. Unspecified arguments are T<undef> by ScriptBasic behaviour. For example to get the list of all sessions that are older than an hour =verbatim call mt::ListSession Array,undef,GmTime()-60*60 =noverbatim To get all session IDs that timed out: =verbatim call mt::ListSession Array,undef,undef,undef,undef,undef,GmTime() =noverbatim To get all sessions that are idle for more than ten minutes =verbatim call mt::ListSession Array,undef,undef,undef,GmTime()-600 =noverbatim Note that this subroutine is rarely used in "cgi" scripts. This subroutine has to be used in scripts that are run by the Eszter SB Engine asynchronously started using the configuration key T<httpd.run.[re]start>. Those scripts start before the engine starts to listen on a port and run so long as long the engine runs and are able to scan the sessions from time to time and delete the old sessions freeing the memoryof the module MT. Definition at line 1447 of file interface.c. |
|
=section GetSessionPingTime =H mt::GetSessionPingTime ["sessionid"] This function returns the time when the session was last used (assigned to a script). This value is expressed as GMT seconds since January 1, 1970. 0:00. If the argument is missing the actual argument is used. Definition at line 1330 of file interface.c. References MT_ERROR_NOSESSION, pMT, and _MtClass::pszSessionId. |
|
=section SessionTimeout =H mt::SessionTimeout [sec] Call this function to set session timeout (20 minutes in the example) =verbatim mt::SessionTimeout 20*60 =noverbatim or =verbatim mt::SessionTimeout =noverbatim cancelling session timeout. Definition at line 1223 of file interface.c. References COMMAND_ERROR_SUCCESS, and pS. |
|
=section UnlockRead =H mt::UnlockRead "variablename" Unlock mt variable from read protection Definition at line 1169 of file interface.c. References besUnlockMutex(), and COMMAND_ERROR_MEMORY_LOW. |
|
=section UnlockWrite =H mt::UnlockWrite "variablename" Unlock mt variable from write protection. Definition at line 1125 of file interface.c. References besUnlockMutex(), and COMMAND_ERROR_MEMORY_LOW. |
|
=section LockRead =H mt::LockRead "variablename" Lock mt variable for read protection. Several concurrent programs can read lock a variable, but so long as long there are read locks no program can write lock a variable. The function will wait until it can lock the variable. A variable can not be read locked if the variable is write locked or there is a write lock waiting for the variable. Definition at line 1081 of file interface.c. References besUnlockMutex(), and COMMAND_ERROR_MEMORY_LOW. |
|
=section LockWrite =H mt::LockWrite "variablename" Lock mt variable for write protection. While the variable is locked no programs can access it, not even the one that locked the variable. Usually there is no need to alter the MT variables, as the variables are automatically locked while their value is altered. Locking is needed when a program needs to alter more than one MT variable in a coincise manner. Another possibility is when a program wants to alter a variable and the new value depends on the previous value. As a simplest example is when aprogram wants to increment a variable. In either case the programs have to have a pseudo MT variable, which is used in the locking and unlocking functions. Usually the programs use these variables only to lock and to release and do not care their values, albeit there is nothing that would prohibit using the values. For example a program (X) wants to increment the MT variable "B" and it has to keep track of the variable "BB" to ensure that "BB" is the double of "B". In the meantime another (Y) program wants to decrement "BB" by two and set "B" to the half of "BB" to keep the rule. Program X: =verbatim mt::GetVariable "B",B B = B+1 mt::SetVariable "B",B mt::SetVariable "BB",2*B =noverbatim Program Y: =verbatim mt::GetVariable "BB",BB BB = BB-2 mt::SetVariable "BB",BB mt::SetVariable "B",B \ 2 =noverbatim The lines of the two programs can execute in any mixed order. See the following scenario: =itemize =item Program X examines B and sees that B is 3 (for example) =item Program Y examines BB and sees that BB is 6. =item Program X increments B to be 4. =item Program Y decrements BB to be 4. =item Program Y sets B to be the half of BB to 2. =item Program X sets the variable BB to the double of B, which is 8 for that program. =end itemize Instead a variable called "BLCK" has to be used (BLCK is just for example): Program X: =verbatim mt::LockWrite "BLCK" mt::GetVariable "B",B B = B+1 mt::SetVariable "B",B mt::SetVariable "BB",2*B mt::UnlockWrite "BLCK" =noverbatim Program Y: =verbatim mt::LockWrite "BLCK" mt::GetVariable "BB",BB BB = BB-2 mt::SetVariable "BB",BB mt::SetVariable "B",B \ 2 mt::UnlockWrite "BLCK" =noverbatim The locking at the start of the critical code segments prevents two programs to enter the critical part at the same time. Definition at line 1033 of file interface.c. References besUnlockMutex(), and COMMAND_ERROR_MEMORY_LOW. |
|
=section GetVariable =H mt::GetVariable("variablename") Get Mt variable. This function gets the value of an Mt variable. Definition at line 901 of file interface.c. References besUnlockMutex(), and COMMAND_ERROR_SUCCESS. |
|
=section SetVariable =H mt::SetVariable "variablename",value Set the value of an MT variable. The first argument has to be a string that identifies the variable. The second argument is the new value of the variable. MT variables are global, all running scripts like the same values. Definition at line 803 of file interface.c. References besUnlockMutex(), and COMMAND_ERROR_MEMORY_LOW. |
|
=section GetSessionVariable =H mt::GetSessionVariabe("variablename") Get the value of a session variable. The argument has to be a string that identifies the session variable. The value of a session variable can be set using R<SetSessionVariable>. Definition at line 732 of file interface.c. References besUnlockMutex(), COMMAND_ERROR_SUCCESS, and pS. |
|
=section GetSessionId =H mt::GetSessionId() This function returns the actual session id. This is usually known by the program because this is the id that was set calling R<SetSessionId> or was created and returned by R<NewSessionId>. However some programs may need to call this function. Definition at line 606 of file interface.c. References besUnlockMutex(), COMMAND_ERROR_MEMORY_LOW, and pS. |
|
=section DeleteSession =H mt::DeleteSession ["sessionid"] Call this function to delete a session. The function deletes the session and releases all memory that was allocated to store session variables. If no argumentum is supplied then the function deletes the actual session. Definition at line 508 of file interface.c. References MT_ERROR_NOSESSION, pMT, and _MtClass::pszSessionId. |
|
=section CheckSessionId =H mt::CheckSessionId("sessionid") Checks that a session already exists. The function returns T<TRUE> if the session id already exists. This function can and should be used to check that a session is valid or not based on its existence. If the session is not existent the program can still call the function R<SetSessionId> to set the session and the new session is autmatically created. However calling this function is a good chanhe to check if any session initialization is needed, for example password check. Definition at line 349 of file interface.c. References besCONVERT2STRING(), and besDEREFERENCE(). |
|
Referenced by alloc_Wrapper(), delete_Wrapper(), ReleaseSession(), rpm_ager(), rpm_close_excess(), rpm_GetResource(), rpm_open(), rpm_PutResource(), and rpm_thread(). |
|
|
|
|
|
|
|
|
|
|
|
|
|
Referenced by alloc_Wrapper(), besFUNCTION(), delete_Wrapper(), if(), ReleaseSession(), rpm_ager(), rpm_close_excess(), rpm_GetResource(), rpm_open(), rpm_PutResource(), rpm_thread(), and while(). |
|
|
|
Referenced by if(). |
|
|
|
Referenced by if(). |
|
|
|
Definition at line 489 of file interface.c. References besFinishSharedLock(), p, and pSt. |
|
Definition at line 1480 of file interface.c. References besUnlockMutex(), COMMAND_ERROR_SUCCESS, and mxSessionTable. |
|
Definition at line 1245 of file interface.c. |
|
Definition at line 769 of file interface.c. References besALLOC_RETURN_STRING(), besRETURNVALUE, besUnlockSharedRead(), COMMAND_ERROR_SUCCESS, memcpy(), STRINGVALUE(), and STRLEN(). |
|
Definition at line 696 of file interface.c. References besUnlockSharedWrite(), COMMAND_ERROR_MEMORY_LOW, COMMAND_ERROR_SUCCESS, memcpy(), NULL, pS, pSt, STRINGVALUE(), and STRLEN(). |
|
Definition at line 684 of file interface.c. References besUnlockSharedWrite(), and COMMAND_ERROR_MEMORY_LOW. |
|
Definition at line 676 of file interface.c. References besUnlockSharedWrite(), COMMAND_ERROR_SUCCESS, NULL, pS, and pSt. |
|
Definition at line 670 of file interface.c. References NULL, pS, pSt, and STRINGVALUE(). |
|
|
|
Definition at line 561 of file interface.c. References besFREE(), and EXE_ERROR_INTERNAL. |
|
Definition at line 454 of file interface.c. References besUnlockMutex(), COMMAND_ERROR_MEMORY_LOW, and mxSessionTable. |
|
Definition at line 438 of file interface.c. |
|
|
|
Definition at line 193 of file interface.c. References besFREE(), besUnlockMutex(), and COMMAND_ERROR_MEMORY_LOW. |
|
Definition at line 169 of file interface.c. References COMMAND_ERROR_MEMORY_LOW, lSessionCounter, MtVariables, mxMTVariables, mxSessionCounter, mxSessionTable, NULL, pSessionRoot, pSt, and SessionTable. |
|
|
|
|
|
Definition at line 117 of file interface.c. References besLockMutex(), besUnlockMutex(), mxSessionTable, pS, and pSessionRoot. |
|
Definition at line 1514 of file interface.c. |
|
|
Referenced by _GetData(), basext_GetArgsF(), besFUNCTION(), CHECK_OPTION(), FileIsSecure(), if(), IsTrue(), scriba_CallArg(), scriba_CallArgEx(), serconv(), serconvXML(), STRCMP(), switch(), varcmp(), varhashpjw(), and while(). |
|
Definition at line 134 of file interface.c. References besCONFIGEX(), NULL, pS, pSessionRoot, and pSt. |
|
Definition at line 1493 of file interface.c. References besUnlockMutex(), COMMAND_ERROR_MEMORY_LOW, memcpy(), mxSessionTable, SESSION__CONSTRAINT, and STRINGVALUE(). |
|
Definition at line 1242 of file interface.c. |
|
Definition at line 840 of file interface.c. |
|
Definition at line 667 of file interface.c. |
|
Definition at line 867 of file interface.c. |
|
Definition at line 693 of file interface.c. Referenced by memory_ReleaseVariable(), return(), serconv(), serconvXML(), and unserconv(). |
|
Definition at line 868 of file interface.c. |
|
Definition at line 694 of file interface.c. Referenced by memory_ReDimArray(), and unserconv(). |
|
Definition at line 483 of file interface.c. |
|
Definition at line 450 of file interface.c. |
|
Definition at line 328 of file interface.c. |
|
Definition at line 1381 of file interface.c. |
|
Definition at line 1313 of file interface.c. |
|
Definition at line 192 of file interface.c. |
|
Definition at line 1205 of file interface.c. |
|
Definition at line 1161 of file interface.c. |
|
Definition at line 1116 of file interface.c. |
|
Definition at line 1068 of file interface.c. |
|
Definition at line 1492 of file interface.c. |
|
Definition at line 954 of file interface.c. |
|
Definition at line 892 of file interface.c. |
|
Definition at line 790 of file interface.c. |
|
Definition at line 720 of file interface.c. Referenced by execute_Evaluate(), execute_LeftValue(), execute_LeftValueArray(), execute_LeftValueSarray(), and if(). |
|
Definition at line 484 of file interface.c. |
|
Definition at line 329 of file interface.c. |
|
Definition at line 69 of file interface.c. Referenced by if(). |
|
Definition at line 1553 of file interface.c. |
|
Definition at line 432 of file interface.c. |
|
Definition at line 1485 of file interface.c. Referenced by if(). |
|
Initial value: { { "keepmodu" , keepmodu }, { "shutmodu" , shutmodu }, { "bootmodu" , bootmodu }, { "setsession" , setsession }, { "chksession" , chksession }, { "sessioncount" , sessioncount }, { "newsession" , newsession }, { "delsession" , delsession }, { "getsession" , getsession }, { "setsvariable" , setsvariable }, { "getsvariable" , getsvariable }, { "setmtvariable" , setmtvariable }, { "getmtvariable" , getmtvariable }, { "lockmtwrite" , lockmtwrite }, { "lockmtread" , lockmtread }, { "unlockmtwrite" , unlockmtwrite }, { "unlockmtread" , unlockmtread }, { "sessionto" , sessionto }, { "getsesto" , getsesto }, { "getsespt" , getsespt }, { "listses" , listses }, { "versmodu" , versmodu }, { "finimodu" , finimodu }, { "keepmodu" , keepmodu }, { "_init" , _init }, { "_fini" , _fini }, { NULL , NULL } } Definition at line 1565 of file interface.c. |
|
=H The module MT =abstract Support for multi-thread implementation web applications. =end This module delivers functions that can be used by ScriptBasic programs executed by a multi-thread basic interpreter. This means that the programs are executed in the same process one after the other or in synchron. The typical example is the Eszter SB Engine that is a standalone webserver execution BASIC programs to answer http questions. Those programs may ask this module to store session variables, wait for eachother. Definition at line 67 of file interface.c. Referenced by if(). |
|
Definition at line 68 of file interface.c. Referenced by if(). |
|
Definition at line 68 of file interface.c. Referenced by if(). |
|
Definition at line 68 of file interface.c. Referenced by if(), ReleaseSession(), and while(). |
|
Definition at line 865 of file interface.c. |
|
Definition at line 691 of file interface.c. Referenced by alloc_Merge(), and reader_ReadLines(). |
|
Definition at line 1357 of file interface.c. |
|
Definition at line 1289 of file interface.c. |
|
Definition at line 545 of file interface.c. |
|
Definition at line 453 of file interface.c. |
|
Definition at line 159 of file interface.c. Referenced by besFUNCTION(). |
|
Definition at line 866 of file interface.c. |
|
Definition at line 692 of file interface.c. |
|
Definition at line 1368 of file interface.c. |
|
Definition at line 1300 of file interface.c. |
|
Definition at line 554 of file interface.c. Referenced by AllocNewSession(), besFUNCTION(), if(), ReleaseSession(), and time_out_work_thread(). |
|
Definition at line 84 of file interface.c. Referenced by AllocNewSession(), if(), ReleaseSession(), and time_out_work_thread(). |
|
Definition at line 1558 of file interface.c. |
|
Definition at line 67 of file interface.c. Referenced by if(). |
|
Definition at line 864 of file interface.c. |
|
Definition at line 690 of file interface.c. |
|
Definition at line 863 of file interface.c. |
|
Definition at line 689 of file interface.c. |