diff options
author | Aníbal Limón <anibal.limon@linux.intel.com> | 2015-06-30 09:39:10 -0500 |
---|---|---|
committer | Richard Purdie <richard.purdie@linuxfoundation.org> | 2015-07-09 18:00:21 +0100 |
commit | bf6c21c38b9d07481dd34f7a0a2c37f800295ccb (patch) | |
tree | 997591d2a42adcb5e7fbb818b87dce515ac47c5a /bitbake | |
parent | 3b5b74b430f0c62bcb4bbbcce02b18f2cb12d336 (diff) | |
download | poky-bf6c21c38b9d07481dd34f7a0a2c37f800295ccb.tar.gz |
bitbake: fetch2/__init__.py: Add FetchConnectionCache class
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 <anibal.limon@linux.intel.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Diffstat (limited to 'bitbake')
-rw-r--r-- | bitbake/lib/bb/fetch2/__init__.py | 36 |
1 files changed, 36 insertions, 0 deletions
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): | |||
1711 | if ud.lockfile: | 1711 | if ud.lockfile: |
1712 | bb.utils.unlockfile(lf) | 1712 | bb.utils.unlockfile(lf) |
1713 | 1713 | ||
1714 | class FetchConnectionCache(object): | ||
1715 | """ | ||
1716 | A class which represents an container for socket connections. | ||
1717 | """ | ||
1718 | def __init__(self): | ||
1719 | self.cache = {} | ||
1720 | |||
1721 | def get_connection_name(self, host, port): | ||
1722 | return host + ':' + str(port) | ||
1723 | |||
1724 | def add_connection(self, host, port, connection): | ||
1725 | cn = self.get_connection_name(host, port) | ||
1726 | |||
1727 | if cn not in self.cache: | ||
1728 | self.cache[cn] = connection | ||
1729 | |||
1730 | def get_connection(self, host, port): | ||
1731 | connection = None | ||
1732 | |||
1733 | cn = self.get_connection_name(host, port) | ||
1734 | if cn in self.cache: | ||
1735 | connection = self.cache[cn] | ||
1736 | |||
1737 | return connection | ||
1738 | |||
1739 | def remove_connection(self, host, port): | ||
1740 | cn = self.get_connection_name(host, port) | ||
1741 | if cn in self.cache: | ||
1742 | self.cache[cn].close() | ||
1743 | del self.cache[cn] | ||
1744 | |||
1745 | def close_connections(self): | ||
1746 | for cn in self.cache.keys(): | ||
1747 | self.cache[cn].close() | ||
1748 | del self.cache[cn] | ||
1749 | |||
1714 | from . import cvs | 1750 | from . import cvs |
1715 | from . import git | 1751 | from . import git |
1716 | from . import gitsm | 1752 | from . import gitsm |