diff options
author | elie <elie> | 2013-12-12 18:47:52 +0000 |
---|---|---|
committer | elie <elie> | 2013-12-12 18:47:52 +0000 |
commit | b3933c17a3501cdaca1b2c93e25497806a472ae0 (patch) | |
tree | 773c801e07c68dedf2a6497c234680a77378711d /pysnmp/carrier | |
parent | 93b411d91c1b1fcbd87f78ed9d6ca56ad4d8e067 (diff) | |
download | pysnmp-b3933c17a3501cdaca1b2c93e25497806a472ae0.tar.gz |
* broadcast socket option can now be enabled with the .enableBroadcast()
call for any datagram-based transport (namely, UDP and UDP6)
* AbstractTransportDispatcher's jobStarted() and jobFinished() methods
now accept optional 'count' parameter which is a way for an app to indicate
how many responses are expected or have been processed in bulk
Diffstat (limited to 'pysnmp/carrier')
-rw-r--r-- | pysnmp/carrier/asynsock/dgram/base.py | 13 | ||||
-rw-r--r-- | pysnmp/carrier/base.py | 10 |
2 files changed, 16 insertions, 7 deletions
diff --git a/pysnmp/carrier/asynsock/dgram/base.py b/pysnmp/carrier/asynsock/dgram/base.py index 45b73d7..5f20f4e 100644 --- a/pysnmp/carrier/asynsock/dgram/base.py +++ b/pysnmp/carrier/asynsock/dgram/base.py @@ -28,9 +28,9 @@ class DgramSocketTransport(AbstractSocketTransport): try: self.socket.bind(iface) except socket.error: - raise error.CarrierError('bind() for %s failed: %s' % (iface is None and "<all local>" or iface, sys.exc_info()[1],)) + raise error.CarrierError('bind() for %s failed: %s' % (iface is None and "<all local>" or iface, sys.exc_info()[1])) return self - + def openServerMode(self, iface): try: self.socket.bind(iface) @@ -38,6 +38,15 @@ class DgramSocketTransport(AbstractSocketTransport): raise error.CarrierError('bind() for %s failed: %s' % (iface, sys.exc_info()[1],)) return self + def enableBroadcast(self, flag=True): + try: + self.socket.setsockopt( + socket.SOL_SOCKET, socket.SO_BROADCAST, flag + ) + except socket.error: + raise error.CarrierError('setsockopt() for SO_BROADCAST failed: %s' % (sys.exc_info()[1],)) + return self + def sendMessage(self, outgoingMessage, transportAddress): self.__outQueue.append( (outgoingMessage, transportAddress) diff --git a/pysnmp/carrier/base.py b/pysnmp/carrier/base.py index d7b9d56..d3d9a6e 100644 --- a/pysnmp/carrier/base.py +++ b/pysnmp/carrier/base.py @@ -151,14 +151,14 @@ class AbstractTransportDispatcher: for timerCallable in self.__timerCallables: timerCallable(timeNow) - def jobStarted(self, jobId): + def jobStarted(self, jobId, count=1): if jobId in self.__jobs: - self.__jobs[jobId] = self.__jobs[jobId] + 1 + self.__jobs[jobId] += count else: - self.__jobs[jobId] = 1 + self.__jobs[jobId] = count - def jobFinished(self, jobId): - self.__jobs[jobId] = self.__jobs[jobId] - 1 + def jobFinished(self, jobId, count=1): + self.__jobs[jobId] -= count if self.__jobs[jobId] == 0: del self.__jobs[jobId] |