From bf6c21c38b9d07481dd34f7a0a2c37f800295ccb Mon Sep 17 00:00:00 2001 From: Aníbal Limón Date: Tue, 30 Jun 2015 09:39:10 -0500 Subject: bitbake: fetch2/__init__.py: Add FetchConnectionCache class MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit FetchConnectionCache class acts as a container for socket connections useful when implement connection cache into fetcher modules. (Bitbake rev: 454da2cd17539ceb9caad6d76f034757e44ee12f) Signed-off-by: Aníbal Limón Signed-off-by: Richard Purdie --- bitbake/lib/bb/fetch2/__init__.py | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/bitbake/lib/bb/fetch2/__init__.py b/bitbake/lib/bb/fetch2/__init__.py index cc772df498..7fd9ec7bf1 100644 --- a/bitbake/lib/bb/fetch2/__init__.py +++ b/bitbake/lib/bb/fetch2/__init__.py @@ -1711,6 +1711,42 @@ class Fetch(object): if ud.lockfile: bb.utils.unlockfile(lf) +class FetchConnectionCache(object): + """ + A class which represents an container for socket connections. + """ + def __init__(self): + self.cache = {} + + def get_connection_name(self, host, port): + return host + ':' + str(port) + + def add_connection(self, host, port, connection): + cn = self.get_connection_name(host, port) + + if cn not in self.cache: + self.cache[cn] = connection + + def get_connection(self, host, port): + connection = None + + cn = self.get_connection_name(host, port) + if cn in self.cache: + connection = self.cache[cn] + + return connection + + def remove_connection(self, host, port): + cn = self.get_connection_name(host, port) + if cn in self.cache: + self.cache[cn].close() + del self.cache[cn] + + def close_connections(self): + for cn in self.cache.keys(): + self.cache[cn].close() + del self.cache[cn] + from . import cvs from . import git from . import gitsm -- cgit v1.2.3-54-g00ecf