- fixed some issues related to "config listen 1" mode

i.e. do not write some lines twice when in this mode
This commit is contained in:
zolliker
2013-06-07 06:17:07 +00:00
parent 9a142c18bf
commit 3f6a76052d
2 changed files with 32 additions and 10 deletions

View File

@ -98,7 +98,8 @@ typedef struct {
static int iName = 0;
static long lastIdent = 0;
/*------------- sending connection (prevent double write when listening) ----*/
static int sendingConnection = 0;
static SConnection *sendingConnection = NULL;
static int sendingSockHandle = 0;
/*------------- storing connection and context for later use ----*/
struct SCStore {
SConnection *pCon;
@ -139,6 +140,23 @@ void KillFreeConnections()
{
}
/*---------------------------------------------------------------------------*/
SConnection *GetSendingConnection(void)
{
return sendingConnection;
}
/*---------------------------------------------------------------------------*/
static void SetSendingConnection(SConnection *pCon)
{
sendingConnection = pCon;
if (pCon) {
sendingSockHandle = pCon->sockHandle;
} else {
sendingSockHandle = 0;
}
}
/*-------------------------------------------------------------------------*/
static SConnection *SCMakeConnection()
{
@ -700,14 +718,14 @@ static void testAndWriteCommandLog(SConnection * pCon, char *buffer,
{
if (SCGetRights(pCon) <= usUser) {
if (SCinMacro(pCon) != 1) {
sendingConnection = pCon->sockHandle;
SetSendingConnection(pCon);
WriteToCommandLogId(NULL, pCon->sockHandle, buffer);
sendingConnection = 0;
SetSendingConnection(NULL);
} else {
if (iOut == eLog || iOut == eLogError) {
sendingConnection = pCon->sockHandle;
SetSendingConnection(pCon);
WriteToCommandLogId(NULL, pCon->sockHandle, buffer);
sendingConnection = 0;
SetSendingConnection(NULL);
}
}
}
@ -1000,7 +1018,9 @@ int SCLogWrite(SConnection * self, char *buffer, int iOut)
if (!VerifyConnection(self)) {
return 0;
}
SetSendingConnection(self);
WriteToCommandLogId(NULL, self->sockHandle, buffer);
SetSendingConnection(NULL);
if(self->iProtocolID == 5) {
if (strlen(buffer) + 30 > 1024) {
@ -1614,7 +1634,7 @@ int SCInvoke(SConnection * self, SicsInterp * pInter, char *pCommand)
* case
*/
if (SCGetWriteFunc(self) != SCNotWrite) {
sendingConnection = self->sockHandle;
SetSendingConnection(self);
if (self->sockHandle >= 0) {
if(strstr(pCommand,"Poch") == NULL){
WriteToCommandLogCmd(self->sockHandle, pCommand);
@ -1622,7 +1642,7 @@ int SCInvoke(SConnection * self, SicsInterp * pInter, char *pCommand)
} else {
WriteToCommandLog("CRON>>", pCommand);
}
sendingConnection = 0;
SetSendingConnection(NULL);
}
}
@ -2164,11 +2184,11 @@ void SCSignalFunction(void *pData, int iSignal, void *pSigData)
} else if (iSignal == SICSBROADCAST) {
pPtr = (char *) pSigData;
if (pPtr != NULL) {
SCWrite(self, pPtr, eWarning);
SCPureSockWrite(self, pPtr, eWarning);
}
} else if (iSignal == COMLOG && self->listening == 1) {
pPtr = (char *) pSigData;
if (pPtr != NULL && self->sockHandle != sendingConnection) {
if (pPtr != NULL && self->sockHandle != sendingSockHandle) {
doSockWrite(self, pPtr);
}
} else if (iSignal == TOKENRELEASE) {