From cba7d8f361bbb49021055fc820a68a8198b85f1d Mon Sep 17 00:00:00 2001 From: Paul Barker Date: Fri, 28 May 2021 09:42:06 +0100 Subject: bitbake: asyncrpc: Add ping method This method is needed to support startup of the prservice. As it is so generic we can add it to the common asyncrpc module. (Bitbake rev: 25ccd697ea76f66b813be2296866b2d3405b079c) Signed-off-by: Paul Barker Signed-off-by: Richard Purdie --- bitbake/lib/bb/asyncrpc/client.py | 7 ++++++- bitbake/lib/bb/asyncrpc/serv.py | 5 +++++ 2 files changed, 11 insertions(+), 1 deletion(-) (limited to 'bitbake') diff --git a/bitbake/lib/bb/asyncrpc/client.py b/bitbake/lib/bb/asyncrpc/client.py index 4cdad9ac3c..79919c5be6 100644 --- a/bitbake/lib/bb/asyncrpc/client.py +++ b/bitbake/lib/bb/asyncrpc/client.py @@ -103,13 +103,18 @@ class AsyncClient(object): return await self._send_wrapper(proc) + async def ping(self): + return await self.send_message( + {'ping': {}} + ) + class Client(object): def __init__(self): self.client = self._get_async_client() self.loop = asyncio.new_event_loop() - self._add_methods('connect_tcp', 'close') + self._add_methods('connect_tcp', 'close', 'ping') @abc.abstractmethod def _get_async_client(self): diff --git a/bitbake/lib/bb/asyncrpc/serv.py b/bitbake/lib/bb/asyncrpc/serv.py index cb3384639d..fd91aa71a2 100644 --- a/bitbake/lib/bb/asyncrpc/serv.py +++ b/bitbake/lib/bb/asyncrpc/serv.py @@ -28,6 +28,7 @@ class AsyncServerConnection(object): self.max_chunk = DEFAULT_MAX_CHUNK self.handlers = { 'chunk-stream': self.handle_chunk, + 'ping': self.handle_ping, } self.logger = logger @@ -123,6 +124,10 @@ class AsyncServerConnection(object): await self.dispatch_message(msg) + async def handle_ping(self, request): + response = {'alive': True} + self.write_message(response) + class AsyncServer(object): def __init__(self, logger, loop=None): -- cgit v1.2.3-54-g00ecf