summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorelie <elie>2011-02-12 07:21:59 +0000
committerelie <elie>2011-02-12 07:21:59 +0000
commit54ce5195976aafd8c9436578a0c8b38b251d0226 (patch)
tree124c959d4d5a15f6f18ee320e46936eeac6e8d5c
parentedaec269890b5432590f81dd2e491898c855faf8 (diff)
downloadpysnmp-54ce5195976aafd8c9436578a0c8b38b251d0226.tar.gz
MsgAndPduDsp expectResponse parameters passing reworked.
-rw-r--r--CHANGES1
-rw-r--r--pysnmp/entity/rfc3413/cmdgen.py5
-rw-r--r--pysnmp/entity/rfc3413/ntforg.py12
-rw-r--r--pysnmp/proto/rfc3412.py23
4 files changed, 27 insertions, 14 deletions
diff --git a/CHANGES b/CHANGES
index 1b95a66..6849eb5 100644
--- a/CHANGES
+++ b/CHANGES
@@ -10,6 +10,7 @@ Revision 4.1.16a
- Internal caches structure improved.
- Sync versions of oneliner apps split off async implementation for clarity.
- Randomize initial in various numeric sequences.
+- MsgAndPduDsp expectResponse parameters passing reworked.
- Changes towards performance improvement:
+ all dict.has_key() & dict.get() invocations replaced with modern syntax
(this breaks compatibility with Python 2.1 and older).
diff --git a/pysnmp/entity/rfc3413/cmdgen.py b/pysnmp/entity/rfc3413/cmdgen.py
index 47efd96..9735031 100644
--- a/pysnmp/entity/rfc3413/cmdgen.py
+++ b/pysnmp/entity/rfc3413/cmdgen.py
@@ -170,7 +170,10 @@ class CommandGeneratorBase:
contextName,
pduVersion,
reqPDU,
- (processResponsePdu, float(timeout)/100 + time.time(), cbCtx)
+ 1, # expectResponse
+ float(timeout)/100 + time.time(), # timeout
+ processResponsePdu,
+ cbCtx
)
snmpEngine.transportDispatcher.jobStarted(id(self))
diff --git a/pysnmp/entity/rfc3413/ntforg.py b/pysnmp/entity/rfc3413/ntforg.py
index 3597078..8a05f74 100644
--- a/pysnmp/entity/rfc3413/ntforg.py
+++ b/pysnmp/entity/rfc3413/ntforg.py
@@ -73,8 +73,10 @@ class NotificationOriginator:
origContextName,
origPduVersion,
origPdu,
- (self.processResponsePdu, float(origTimeout)/100 + time.time(),
- (cbFun, cbCtx))
+ 1, # expectResponse
+ float(origTimeout)/100 + time.time(), # timeout
+ self.processResponsePdu,
+ (cbFun, cbCtx)
)
snmpEngine.transportDispatcher.jobStarted(id(self))
@@ -245,8 +247,10 @@ class NotificationOriginator:
contextName,
pduVersion,
pdu,
- (self.processResponsePdu, float(timeout)/100 + time.time(),
- (cbFun, cbCtx))
+ 1, # expectResponse
+ float(timeout)/100 + time.time(), # timeout
+ self.processResponsePdu,
+ (cbFun, cbCtx)
)
debug.logger & debug.flagApp and debug.logger('sendNoification: sendPduHandle %s, timeout %d' % (sendPduHandle, timeout))
diff --git a/pysnmp/proto/rfc3412.py b/pysnmp/proto/rfc3412.py
index c2db84a..3abc26e 100644
--- a/pysnmp/proto/rfc3412.py
+++ b/pysnmp/proto/rfc3412.py
@@ -102,7 +102,10 @@ class MsgAndPduDispatcher:
contextName,
pduVersion,
PDU,
- expectResponse
+ expectResponse,
+ timeout=0, # response items
+ cbFun=None,
+ cbCtx=None
):
"""PDU dispatcher -- prepare and serialize a request or notification"""
# 4.1.1.2
@@ -123,10 +126,12 @@ class MsgAndPduDispatcher:
sendPduHandle,
messageProcessingModel=messageProcessingModel,
sendPduHandle=sendPduHandle,
- expectResponse=expectResponse
+ timeout=timeout,
+ cbFun=cbFun,
+ cbCtx=cbCtx
)
- debug.logger & debug.flagDsp and debug.logger('sendPdu: new sendPduHandle %s, context %s' % (sendPduHandle, expectResponse))
+ debug.logger & debug.flagDsp and debug.logger('sendPdu: new sendPduHandle %s, timeout %s, cbFun %s' % (sendPduHandle, timeout, cbFun))
# 4.1.1.4 & 4.1.1.5
try:
@@ -419,9 +424,7 @@ class MsgAndPduDispatcher:
# no-op ? XXX
# 4.2.2.2.4
- processResponsePdu, timeoutAt, cbCtx = cachedParams[
- 'expectResponse'
- ]
+ processResponsePdu = cachedParams['cbFun']
processResponsePdu(
snmpEngine,
messageProcessingModel,
@@ -434,7 +437,7 @@ class MsgAndPduDispatcher:
PDU,
statusInformation,
cachedParams['sendPduHandle'],
- cbCtx
+ cachedParams['cbCtx']
)
debug.logger & debug.flagDsp and debug.logger('receiveMessage: processResponsePdu succeeded')
return restOfWholeMsg
@@ -451,10 +454,12 @@ class MsgAndPduDispatcher:
def __expireRequest(self, cacheKey, cachedParams, snmpEngine,
statusInformation=None):
- processResponsePdu, timeoutAt, cbCtx = cachedParams['expectResponse']
+ timeoutAt = cachedParams['timeout']
if statusInformation is None and time.time() < timeoutAt:
return
+ processResponsePdu = cachedParams['cbFun']
+
debug.logger & debug.flagDsp and debug.logger('__expireRequest: req cachedParams %s' % cachedParams)
# Fail timed-out requests
@@ -479,7 +484,7 @@ class MsgAndPduDispatcher:
None,
statusInformation,
cachedParams['sendPduHandle'],
- cbCtx
+ cachedParams['cbCtx']
)
return 1