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 bd86cbeeeb01c499dec022991b1b032fb56a9a29..a106d35d19733f20402cd093b9430029ad336239 100644
(file)
--- a/
clientcounter.py
+++ b/
clientcounter.py
@@
-2,38
+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
- print "Total:", self.total
+ self._lock.release()
return self.clients[id][0]
return self.clients[id][0]
-