* { font-family: Consolas, Lucida Console, Courier New; font-size: 100%; }
h1 { font-size: 150%; }
td.linenos { background-color: #f0f0f0; padding-right: 10px; }
span.lineno { background-color: #f0f0f0; padding: 0 5px 0 5px; }
pre { line-height: 100%; width: 100%; }
.highlight span { width: 100%; display:-moz-inline-stack; display:inline-block; zoom:1; *display:inline; }
body { background: #ffffff; }
body .c { color: #999988; font-style: italic } /* Comment */
body .err { color: #a61717; background-color: #e3d2d2 } /* Error */
body .k { font-weight: bold } /* Keyword */
body .o { font-weight: bold } /* Operator */
body .cm { color: #999988; font-style: italic } /* Comment.Multiline */
body .cp { color: #999999; font-weight: bold } /* Comment.Preproc */
body .c1 { color: #999988; font-style: italic } /* Comment.Single */
body .cs { color: #999999; font-weight: bold; font-style: italic } /* Comment.Special */
body .gd { color: #000000; background-color: #ffdddd } /* Generic.Deleted */
body .ge { font-style: italic } /* Generic.Emph */
body .gr { color: #aa0000 } /* Generic.Error */
body .gh { color: #999999 } /* Generic.Heading */
body .gi { color: #000000; background-color: #ddffdd } /* Generic.Inserted */
body .go { color: #888888 } /* Generic.Output */
body .gp { color: #555555 } /* Generic.Prompt */
body .gs { font-weight: bold } /* Generic.Strong */
body .gu { color: #aaaaaa } /* Generic.Subheading */
body .gt { color: #aa0000 } /* Generic.Traceback */
body .kc { font-weight: bold } /* Keyword.Constant */
body .kd { font-weight: bold } /* Keyword.Declaration */
body .kp { font-weight: bold } /* Keyword.Pseudo */
body .kr { font-weight: bold } /* Keyword.Reserved */
body .kt { color: #445588; font-weight: bold } /* Keyword.Type */
body .m { color: #009999 } /* Literal.Number */
body .s { color: #bb8844 } /* Literal.String */
body .na { color: #008080 } /* Name.Attribute */
body .nb { color: #999999 } /* Name.Builtin */
body .nc { color: #445588; font-weight: bold } /* Name.Class */
body .no { color: #008080 } /* Name.Constant */
body .ni { color: #800080 } /* Name.Entity */
body .ne { color: #990000; font-weight: bold } /* Name.Exception */
body .nf { color: #990000; font-weight: bold } /* Name.Function */
body .nn { color: #555555 } /* Name.Namespace */
body .nt { color: #000080 } /* Name.Tag */
body .nv { color: #008080 } /* Name.Variable */
body .ow { font-weight: bold } /* Operator.Word */
body .w { color: #bbbbbb } /* Text.Whitespace */
body .mf { color: #009999 } /* Literal.Number.Float */
body .mh { color: #009999 } /* Literal.Number.Hex */
body .mi { color: #009999 } /* Literal.Number.Integer */
body .mo { color: #009999 } /* Literal.Number.Oct */
body .sb { color: #bb8844 } /* Literal.String.Backtick */
body .sc { color: #bb8844 } /* Literal.String.Char */
body .sd { color: #bb8844 } /* Literal.String.Doc */
body .s2 { color: #bb8844 } /* Literal.String.Double */
body .se { color: #bb8844 } /* Literal.String.Escape */
body .sh { color: #bb8844 } /* Literal.String.Heredoc */
body .si { color: #bb8844 } /* Literal.String.Interpol */
body .sx { color: #bb8844 } /* Literal.String.Other */
body .sr { color: #808000 } /* Literal.String.Regex */
body .s1 { color: #bb8844 } /* Literal.String.Single */
body .ss { color: #bb8844 } /* Literal.String.Symbol */
body .bp { color: #999999 } /* Name.Builtin.Pseudo */
body .vc { color: #008080 } /* Name.Variable.Class */
body .vg { color: #008080 } /* Name.Variable.Global */
body .vi { color: #008080 } /* Name.Variable.Instance */
body .il { color: #009999 } /* Literal.Number.Integer.Long */
Info
Revision:3329
Author:victor
Date:2008-06-21 21:37:51 +0300 (Sat, 21 Jun 2008)
Comment:minor bugfixes in trap sender
Changes
U trunk/include/nxqueue.h
U trunk/src/agent/core/nxagentd.cpp
U trunk/src/agent/core/sysinfo.cpp
U trunk/src/agent/core/trap.cpp
U trunk/src/agent/subagents/winnt/system.cpp
U trunk/src/libnetxms/queue.cpp
Diff
Modified: trunk/include/nxqueue.h
===================================================================
--- trunk/include/nxqueue.h 2008-06-20 14:02:21 UTC (rev 3328)
+++ trunk/include/nxqueue.h 2008-06-21 18:37:51 UTC (rev 3329)
@@ -41,10 +41,11 @@
DWORD m_dwFirst;
DWORD m_dwLast;
DWORD m_dwBufferIncrement;
+ BOOL m_bShutdownFlag;
void CommonInit(void);
- void Lock(void) { MutexLock(m_mutexQueueAccess, INFINITE); }
- void Unlock(void) { MutexUnlock(m_mutexQueueAccess); }
+ void Lock() { MutexLock(m_mutexQueueAccess, INFINITE); }
+ void Unlock() { MutexUnlock(m_mutexQueueAccess); }
public:
Queue();
@@ -52,10 +53,12 @@
~Queue();
void Put(void *pObject);
- void *Get(void);
- void *GetOrBlock(void);
- DWORD Size(void) { return m_dwNumElements; }
- void Clear(void);
+ void Insert(void *pObject);
+ void SetShutdownMode();
+ void *Get();
+ void *GetOrBlock();
+ DWORD Size() { return m_dwNumElements; }
+ void Clear();
};
#endif /* _nxqueue_h_ */
Modified: trunk/src/agent/core/nxagentd.cpp
===================================================================
--- trunk/src/agent/core/nxagentd.cpp 2008-06-20 14:02:21 UTC (rev 3328)
+++ trunk/src/agent/core/nxagentd.cpp 2008-06-21 18:37:51 UTC (rev 3329)
@@ -51,6 +51,8 @@
THREAD_RESULT THREAD_CALL SessionWatchdog(void *);
THREAD_RESULT THREAD_CALL TrapSender(void *);
+void ShutdownTrapSender();
+
#if !defined(_WIN32) && !defined(_NETWARE)
void InitStaticSubagents(void);
#endif
@@ -140,6 +142,7 @@
static DWORD m_dwEnabledCiphers = 0xFFFF;
static THREAD m_thSessionWatchdog = INVALID_THREAD_HANDLE;
static THREAD m_thListener = INVALID_THREAD_HANDLE;
+static THREAD m_thTrapSender = INVALID_THREAD_HANDLE;
static char m_szConfigServer[MAX_DB_STRING] = "not_set";
#if defined(_WIN32) || defined(_NETWARE)
@@ -821,7 +824,7 @@
// Start network listener and session watchdog
m_thListener = ThreadCreateEx(ListenerThread, 0, NULL);
m_thSessionWatchdog = ThreadCreateEx(SessionWatchdog, 0, NULL);
- ThreadCreate(TrapSender, 0, NULL);
+ m_thTrapSender = ThreadCreateEx(TrapSender, 0, NULL);
#if defined(_WIN32) || defined(_NETWARE)
m_hCondShutdown = ConditionCreate(TRUE);
@@ -840,8 +843,10 @@
{
// Set shutdowm flag
g_dwFlags |= AF_SHUTDOWN;
+ ShutdownTrapSender();
ThreadJoin(m_thSessionWatchdog);
ThreadJoin(m_thListener);
+ ThreadJoin(m_thTrapSender);
UnloadAllSubAgents();
WriteLog(MSG_AGENT_STOPPED, EVENTLOG_INFORMATION_TYPE, NULL);
Modified: trunk/src/agent/core/sysinfo.cpp
===================================================================
--- trunk/src/agent/core/sysinfo.cpp 2008-06-20 14:02:21 UTC (rev 3328)
+++ trunk/src/agent/core/sysinfo.cpp 2008-06-21 18:37:51 UTC (rev 3329)
@@ -1,7 +1,7 @@
/* $Id$ */
/*
** NetXMS multiplatform core agent
-** Copyright (C) 2003, 2004 Victor Kirhenshtein
+** Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008 Victor Kirhenshtein
**
** This program is free software; you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by
Modified: trunk/src/agent/core/trap.cpp
===================================================================
--- trunk/src/agent/core/trap.cpp 2008-06-20 14:02:21 UTC (rev 3328)
+++ trunk/src/agent/core/trap.cpp 2008-06-21 18:37:51 UTC (rev 3329)
@@ -49,33 +49,45 @@
break;
bTrapSent = FALSE;
- while(1)
- {
- MutexLock(g_hSessionListAccess, INFINITE);
- for(i = 0; i < g_dwMaxSessions; i++)
- if (g_pSessionList[i] != NULL)
- if (g_pSessionList[i]->AcceptTraps())
- {
- g_pSessionList[i]->SendRawMessage(pMsg);
- bTrapSent = TRUE;
- }
- MutexUnlock(g_hSessionListAccess);
- if (bTrapSent)
- break;
+ MutexLock(g_hSessionListAccess, INFINITE);
+ for(i = 0; i < g_dwMaxSessions; i++)
+ if (g_pSessionList[i] != NULL)
+ if (g_pSessionList[i]->AcceptTraps())
+ {
+ g_pSessionList[i]->SendRawMessage(pMsg);
+ bTrapSent = TRUE;
+ }
+ MutexUnlock(g_hSessionListAccess);
- ThreadSleep(1);
- }
-
- free(pMsg);
+ if (bTrapSent)
+ {
+ free(pMsg);
+ }
+ else
+ {
+ m_pTrapQueue->Insert(pMsg); // Re-queue trap
+ ThreadSleep(1);
+ }
}
delete m_pTrapQueue;
m_pTrapQueue = NULL;
+ DebugPrintf(INVALID_INDEX, _T("Trap sender thread terminated"));
return THREAD_OK;
}
//
+// Shutdown trap sender
+//
+
+void ShutdownTrapSender()
+{
+ m_pTrapQueue->SetShutdownMode();
+}
+
+
+//
// Send trap to server
//
@@ -129,7 +141,7 @@
sprintf(ppArgList[i], "%d", va_arg(args, LONG));
break;
case 'D':
- ppArgList[i] = (char *)malloc(24);
+ ppArgList[i] = (char *)malloc(32);
sprintf(ppArgList[i], INT64_FMT, va_arg(args, INT64));
break;
case 'x':
@@ -138,7 +150,7 @@
sprintf(ppArgList[i], "0x%08X", va_arg(args, DWORD));
break;
case 'X':
- ppArgList[i] = (char *)malloc(16);
+ ppArgList[i] = (char *)malloc(32);
#ifdef _WIN32
sprintf(ppArgList[i], "0x%016I64X", va_arg(args, QWORD));
#else
Modified: trunk/src/agent/subagents/winnt/system.cpp
===================================================================
--- trunk/src/agent/subagents/winnt/system.cpp 2008-06-20 14:02:21 UTC (rev 3328)
+++ trunk/src/agent/subagents/winnt/system.cpp 2008-06-21 18:37:51 UTC (rev 3329)
@@ -1,6 +1,7 @@
+/* $Id$ */
/*
** Windows NT/2000/XP/2003 NetXMS subagent
-** Copyright (C) 2003, 2004, 2005 Victor Kirhenshtein
+** Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008 Victor Kirhenshtein
**
** This program is free software; you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by
Modified: trunk/src/libnetxms/queue.cpp
===================================================================
--- trunk/src/libnetxms/queue.cpp 2008-06-20 14:02:21 UTC (rev 3328)
+++ trunk/src/libnetxms/queue.cpp 2008-06-21 18:37:51 UTC (rev 3329)
@@ -53,7 +53,7 @@
// Common initialization (used by all constructors)
//
-void Queue::CommonInit(void)
+void Queue::CommonInit()
{
m_mutexQueueAccess = MutexCreate();
m_condWakeup = ConditionCreate(FALSE);
@@ -61,6 +61,7 @@
m_dwFirst = 0;
m_dwLast = 0;
m_pElements = (void **)malloc(sizeof(void *) * m_dwBufferSize);
+ m_bShutdownFlag = FALSE;
}
@@ -104,15 +105,46 @@
//
+// Insert new element into the beginning of a queue
+//
+
+void Queue::Insert(void *pElement)
+{
+ Lock();
+ if (m_dwNumElements == m_dwBufferSize)
+ {
+ // Extend buffer
+ m_dwBufferSize += m_dwBufferIncrement;
+ m_pElements = (void **)realloc(m_pElements, sizeof(void *) * m_dwBufferSize);
+
+ // Move free space
+ memmove(&m_pElements[m_dwFirst + m_dwBufferIncrement], &m_pElements[m_dwFirst],
+ sizeof(void *) * (m_dwBufferSize - m_dwFirst - m_dwBufferIncrement));
+ m_dwFirst += m_dwBufferIncrement;
+ }
+ if (m_dwFirst == 0)
+ m_dwFirst = m_dwBufferSize - 1;
+ m_pElements[--m_dwFirst] = pElement;
+ m_dwNumElements++;
+ ConditionSet(m_condWakeup);
+ Unlock();
+}
+
+
+//
// Get object from queue. Return NULL if queue is empty
//
-void *Queue::Get(void)
+void *Queue::Get()
{
void *pElement = NULL;
Lock();
- if (m_dwNumElements != 0)
+ if (m_bShutdownFlag)
+ {
+ pElement = INVALID_POINTER_VALUE;
+ }
+ else if (m_dwNumElements != 0)
{
pElement = m_pElements[m_dwFirst++];
if (m_dwFirst == m_dwBufferSize)
@@ -128,7 +160,7 @@
// Get object from queue or block if queue if empty
//
-void *Queue::GetOrBlock(void)
+void *Queue::GetOrBlock()
{
void *pElement;
@@ -151,7 +183,7 @@
// Clear queue
//
-void Queue::Clear(void)
+void Queue::Clear()
{
Lock();
m_dwNumElements = 0;
@@ -159,3 +191,17 @@
m_dwLast = 0;
Unlock();
}
+
+
+//
+// Set shutdown flag
+// When this flag is set, Get() always return INVALID_POINTER_VALUE
+//
+
+void Queue::SetShutdownMode()
+{
+ Lock();
+ m_bShutdownFlag = TRUE;
+ ConditionSet(m_condWakeup);
+ Unlock();
+}
Received on Sat Jun 21 2008 - 21:37:53 EEST
This archive was generated by hypermail 2.2.0 : Sat Jun 21 2008 - 21:33:46 EEST