Andrew Geissler | c926e17 | 2021-05-07 16:11:35 -0500 | [diff] [blame] | 1 | # |
Patrick Williams | 92b42cb | 2022-09-03 06:53:57 -0500 | [diff] [blame^] | 2 | # Copyright BitBake Contributors |
| 3 | # |
Andrew Geissler | c926e17 | 2021-05-07 16:11:35 -0500 | [diff] [blame] | 4 | # SPDX-License-Identifier: GPL-2.0-only |
| 5 | # |
| 6 | |
| 7 | import itertools |
| 8 | import 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 |
| 15 | DEFAULT_MAX_CHUNK = 32 * 1024 |
| 16 | |
| 17 | |
| 18 | def 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 | |
| 32 | from .client import AsyncClient, Client |
Andrew Geissler | 7e0e3c0 | 2022-02-25 20:34:39 +0000 | [diff] [blame] | 33 | from .serv import AsyncServer, AsyncServerConnection, ClientError, ServerError |