summaryrefslogtreecommitdiff
path: root/pysnmp/entity/config.py
diff options
context:
space:
mode:
Diffstat (limited to 'pysnmp/entity/config.py')
-rw-r--r--pysnmp/entity/config.py25
1 files changed, 18 insertions, 7 deletions
diff --git a/pysnmp/entity/config.py b/pysnmp/entity/config.py
index f9018e9..085eea5 100644
--- a/pysnmp/entity/config.py
+++ b/pysnmp/entity/config.py
@@ -325,12 +325,17 @@ def addTransport(snmpEngine, transportDomain, transport):
transport.protoTransportDispatcher()
)
# here we note that we have created transportDispatcher automatically
- snmpEngine.cache['automaticTransportDispatcher'] = 0
+ snmpEngine.setUserContext(automaticTransportDispatcher=0)
snmpEngine.transportDispatcher.registerTransport(
transportDomain, transport
)
- if 'automaticTransportDispatcher' in snmpEngine.cache:
- snmpEngine.cache['automaticTransportDispatcher'] += 1
+ automaticTransportDispatcher = snmpEngine.getUserContext(
+ 'automaticTransportDispatcher'
+ )
+ if automaticTransportDispatcher is not None:
+ snmpEngine.setUserContext(
+ automaticTransportDispatcher=automaticTransportDispatcher+1
+ )
def getTransport(snmpEngine, transportDomain):
if not snmpEngine.transportDispatcher:
@@ -346,12 +351,18 @@ def delTransport(snmpEngine, transportDomain):
transport = getTransport(snmpEngine, transportDomain)
snmpEngine.transportDispatcher.unregisterTransport(transportDomain)
# automatically shutdown automatically created transportDispatcher
- if 'automaticTransportDispatcher' in snmpEngine.cache:
- snmpEngine.cache['automaticTransportDispatcher'] -= 1
- if not snmpEngine.cache['automaticTransportDispatcher']:
+ automaticTransportDispatcher = snmpEngine.getUserContext(
+ 'automaticTransportDispatcher'
+ )
+ if automaticTransportDispatcher is not None:
+ automaticTransportDispatcher -= 1
+ snmpEngine.setUserContext(
+ automaticTransportDispatcher=automaticTransportDispatcher
+ )
+ if not automaticTransportDispatcher:
snmpEngine.transportDispatcher.closeDispatcher()
snmpEngine.unregisterTransportDispatcher()
- del snmpEngine.cache['automaticTransportDispatcher']
+ snmpEngine.delUserContext(automaticTransportDispatcher)
return transport
addSocketTransport = addTransport