snmp接收TRAP的线程出现堵塞问题

xggabc 2014-01-02 09:23:15
UINT SnmpTrap(LPVOID param)
{
HANDLE hNewTraps = NULL;

if (!SnmpMgrTrapListen(&hNewTraps)){
errMsg.Format("error on SnmpMgrTrapListen %d\n", GetLastError());
}
else{
errMsg.Format("TrapServer Started");
}
AfxMessageBox(errMsg);

while(TRUE){
DWORD dwResult;
if ((dwResult = WaitForSingleObject(hNewTraps, 0xffffffff))== 0xffffffff){
errMsg.Format("error on WaitForSingleObject %d\n",GetLastError());
AfxMessageBox(errMsg);
return 0;
}
else if (!ResetEvent(hNewTraps)){
errMsg.Format("error on ResetEvent %d\n", GetLastError());
AfxMessageBox(errMsg);
return 0;
}
else{
AsnObjectIdentifier enterprise;
AsnNetworkAddress IPAddress;
AsnInteger genericTrap;
AsnInteger specificTrap;
AsnTimeticks timeStamp;
RFC1157VarBindList variableBindings;

UINT i;
char *string = NULL;

while(SnmpMgrGetTrap(&enterprise, &IPAddress, &genericTrap,
&specificTrap, ×tamp, &variableBindings)) {
errMsg.Format("Trap Server : generic=%d specific=%d\n", genericTrap, specificTrap);
AfxMessageBox(errMsg);
if (IPAddress.length == 4) {
errMsg.Format(" from -> %d.%d.%d.%d\n",
(int)IPAddress.stream[0], (int)IPAddress.stream[1],
(int)IPAddress.stream[2], (int)IPAddress.stream[3]);
AfxMessageBox(errMsg);

}
if (IPAddress.dynamic) {
SNMP_free(IPAddress.stream);
}
for(i=0; i < variableBindings.len; i++) {
SnmpMgrOidToStr(&variableBindings.list[i].name, &string);
errMsg.Format("Variable = %s\n", string);
AfxMessageBox(errMsg);
if (string) {
SNMP_free(string);
}
//SnmpUtilPrintAsnAny(&variableBindings.list[i].value);
AsnPrint(&variableBindings.list[i].value,errMsg);
AfxMessageBox("Value = "+errMsg);
} // end for()
SnmpUtilOidFree(&enterprise);
SnmpUtilVarBindListFree(&variableBindings);
}
}
} // end while()
return 1;
}
用VC6.0生成一个线程,然后等待trap消息,发现一直堵塞在WaitForSingleObject ,有没有什么方法可以解决这个问题?
...全文
22 点赞 收藏 回复
写回复
回复

还没有回复,快来抢沙发~

发动态
发帖子
进程/线程/DLL
创建于2007-09-28

6376

社区成员

4.9w+

社区内容

VC/MFC 进程/线程/DLL
社区公告
暂无公告