projects
/
vpproxy.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Обработка таймаута при закрытии потока.
[vpproxy.git]
/
clientcounter.py
diff --git
a/clientcounter.py
b/clientcounter.py
index bcfd0b2eff746eb230f48297f6a1edf2e65d6d8e..a106d35d19733f20402cd093b9430029ad336239 100644
(file)
--- a/
clientcounter.py
+++ b/
clientcounter.py
@@
-2,37
+2,54
@@
Simple Client Counter for VLC VLM
'''
Simple Client Counter for VLC VLM
'''
+import gevent
+import logging
class ClientCounter(object):
def __init__(self):
self.clients = dict()
class ClientCounter(object):
def __init__(self):
self.clients = dict()
+ self._lock = gevent.coros.RLock()
self.total = 0
def get(self, id):
return self.clients.get(id, (False,))[0]
self.total = 0
def get(self, id):
return self.clients.get(id, (False,))[0]
- def add(self, id, ip):
+ def add(self, id, ip, unic):
+ self._lock.acquire()
+ logger = logging.getLogger('clientcounter_Add')
if self.clients.has_key(id):
self.clients[id][0] += 1
if self.clients.has_key(id):
self.clients[id][0] += 1
- self.clients[id][1].append(ip)
+ self.clients[id][1].append([ip,unic])
+ logger.info('counter for %s incremented to %s' % (id,self.clients[id][0]))
else:
else:
- self.clients[id] = [1, [ip]]
+ self.clients[id] = [1, [[ip,unic]]]
+ logger.info('counter for %s started (1)' % id)
self.total += 1
self.total += 1
+ logger.info('total count = %s' % self.total)
+
+ self._lock.release()
return self.clients[id][0]
return self.clients[id][0]
- def delete(self, id, ip):
+ def delete(self, id, ip, unic):
+ self._lock.acquire()
+ logger = logging.getLogger('clientcounter_Del')
if self.clients.has_key(id):
self.total -= 1
if self.clients.has_key(id):
self.total -= 1
+ logger.info('total count = %s' % self.total)
if self.clients[id][0] == 1:
del self.clients[id]
if self.clients[id][0] == 1:
del self.clients[id]
+ logger.info('counter for %s decremented to zero' % id )
+ self._lock.release()
return False
else:
self.clients[id][0] -= 1
return False
else:
self.clients[id][0] -= 1
- self.clients[id][1].remove(ip)
+ self.clients[id][1].remove([ip,unic])
+ logger.info('counter for %s decremented to %s' % (id,self.clients[id][0]))
else:
else:
+ self._lock.release()
return False
return False
+ self._lock.release()
return self.clients[id][0]
return self.clients[id][0]
-