diff options
Diffstat (limited to 'bitbake/lib/hashserv/__init__.py')
| -rw-r--r-- | bitbake/lib/hashserv/__init__.py | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/bitbake/lib/hashserv/__init__.py b/bitbake/lib/hashserv/__init__.py index c3318620f5..f95e8f43f1 100644 --- a/bitbake/lib/hashserv/__init__.py +++ b/bitbake/lib/hashserv/__init__.py | |||
| @@ -6,12 +6,20 @@ | |||
| 6 | from contextlib import closing | 6 | from contextlib import closing |
| 7 | import re | 7 | import re |
| 8 | import sqlite3 | 8 | import sqlite3 |
| 9 | import itertools | ||
| 10 | import json | ||
| 9 | 11 | ||
| 10 | UNIX_PREFIX = "unix://" | 12 | UNIX_PREFIX = "unix://" |
| 11 | 13 | ||
| 12 | ADDR_TYPE_UNIX = 0 | 14 | ADDR_TYPE_UNIX = 0 |
| 13 | ADDR_TYPE_TCP = 1 | 15 | ADDR_TYPE_TCP = 1 |
| 14 | 16 | ||
| 17 | # The Python async server defaults to a 64K receive buffer, so we hardcode our | ||
| 18 | # maximum chunk size. It would be better if the client and server reported to | ||
| 19 | # each other what the maximum chunk sizes were, but that will slow down the | ||
| 20 | # connection setup with a round trip delay so I'd rather not do that unless it | ||
| 21 | # is necessary | ||
| 22 | DEFAULT_MAX_CHUNK = 32 * 1024 | ||
| 15 | 23 | ||
| 16 | def setup_database(database, sync=True): | 24 | def setup_database(database, sync=True): |
| 17 | db = sqlite3.connect(database) | 25 | db = sqlite3.connect(database) |
| @@ -66,6 +74,20 @@ def parse_address(addr): | |||
| 66 | return (ADDR_TYPE_TCP, (host, int(port))) | 74 | return (ADDR_TYPE_TCP, (host, int(port))) |
| 67 | 75 | ||
| 68 | 76 | ||
| 77 | def chunkify(msg, max_chunk): | ||
| 78 | if len(msg) < max_chunk - 1: | ||
| 79 | yield ''.join((msg, "\n")) | ||
| 80 | else: | ||
| 81 | yield ''.join((json.dumps({ | ||
| 82 | 'chunk-stream': None | ||
| 83 | }), "\n")) | ||
| 84 | |||
| 85 | args = [iter(msg)] * (max_chunk - 1) | ||
| 86 | for m in map(''.join, itertools.zip_longest(*args, fillvalue='')): | ||
| 87 | yield ''.join(itertools.chain(m, "\n")) | ||
| 88 | yield "\n" | ||
| 89 | |||
| 90 | |||
| 69 | def create_server(addr, dbname, *, sync=True): | 91 | def create_server(addr, dbname, *, sync=True): |
| 70 | from . import server | 92 | from . import server |
| 71 | db = setup_database(dbname, sync=sync) | 93 | db = setup_database(dbname, sync=sync) |
