blob: 9a85e9965b73ad538c73decedf5d23db13304017 [file] [log] [blame]
Andrew Geisslerc926e172021-05-07 16:11:35 -05001#
Patrick Williams92b42cb2022-09-03 06:53:57 -05002# Copyright BitBake Contributors
3#
Andrew Geisslerc926e172021-05-07 16:11:35 -05004# 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
Andrew Geissler7e0e3c02022-02-25 20:34:39 +000033from .serv import AsyncServer, AsyncServerConnection, ClientError, ServerError