xref: /OK3568_Linux_fs/yocto/poky/bitbake/lib/bb/asyncrpc/__init__.py (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1#
2# Copyright BitBake Contributors
3#
4# SPDX-License-Identifier: GPL-2.0-only
5#
6
7import itertools
8import json
9
10# The Python async server defaults to a 64K receive buffer, so we hardcode our
11# maximum chunk size. It would be better if the client and server reported to
12# each other what the maximum chunk sizes were, but that will slow down the
13# connection setup with a round trip delay so I'd rather not do that unless it
14# is necessary
15DEFAULT_MAX_CHUNK = 32 * 1024
16
17
18def chunkify(msg, max_chunk):
19    if len(msg) < max_chunk - 1:
20        yield ''.join((msg, "\n"))
21    else:
22        yield ''.join((json.dumps({
23                'chunk-stream': None
24            }), "\n"))
25
26        args = [iter(msg)] * (max_chunk - 1)
27        for m in map(''.join, itertools.zip_longest(*args, fillvalue='')):
28            yield ''.join(itertools.chain(m, "\n"))
29        yield "\n"
30
31
32from .client import AsyncClient, Client
33from .serv import AsyncServer, AsyncServerConnection, ClientError, ServerError
34