From: John Snow <jsnow@redhat.com>
To: qemu-devel@nongnu.org
Cc: "John Snow" <jsnow@redhat.com>,
"Vladimir Sementsov-Ogievskiy" <vsementsov@yandex-team.ru>,
"Beraldo Leal" <bleal@redhat.com>,
"Daniel Berrange" <berrange@redhat.com>,
"Cleber Rosa" <crosa@redhat.com>,
"Marc-André Lureau" <marcandre.lureau@redhat.com>
Subject: [PATCH 1/5] python/qmp: allow sockets to be passed to connect()
Date: Wed, 17 May 2023 12:34:02 -0400 [thread overview]
Message-ID: <20230517163406.2593480-2-jsnow@redhat.com> (raw)
In-Reply-To: <20230517163406.2593480-1-jsnow@redhat.com>
Allow existing sockets to be passed to connect(). The changes are pretty
minimal, and this allows for far greater flexibility in setting up
communications with an endpoint.
Signed-off-by: John Snow <jsnow@redhat.com>
---
python/qemu/qmp/protocol.py | 21 +++++++++++++++------
1 file changed, 15 insertions(+), 6 deletions(-)
diff --git a/python/qemu/qmp/protocol.py b/python/qemu/qmp/protocol.py
index 22e60298d2..d534db4631 100644
--- a/python/qemu/qmp/protocol.py
+++ b/python/qemu/qmp/protocol.py
@@ -370,7 +370,7 @@ async def accept(self) -> None:
@upper_half
@require(Runstate.IDLE)
- async def connect(self, address: SocketAddrT,
+ async def connect(self, address: Union[SocketAddrT, socket.socket],
ssl: Optional[SSLContext] = None) -> None:
"""
Connect to the server and begin processing message queues.
@@ -615,7 +615,7 @@ async def _do_accept(self) -> None:
self.logger.debug("Connection accepted.")
@upper_half
- async def _do_connect(self, address: SocketAddrT,
+ async def _do_connect(self, address: Union[SocketAddrT, socket.socket],
ssl: Optional[SSLContext] = None) -> None:
"""
Acting as the transport client, initiate a connection to a server.
@@ -634,9 +634,17 @@ async def _do_connect(self, address: SocketAddrT,
# otherwise yield.
await asyncio.sleep(0)
- self.logger.debug("Connecting to %s ...", address)
-
- if isinstance(address, tuple):
+ if isinstance(address, socket.socket):
+ self.logger.debug("Connecting with existing socket: "
+ "fd=%d, family=%r, type=%r",
+ address.fileno(), address.family, address.type)
+ connect = asyncio.open_connection(
+ limit=self._limit,
+ ssl=ssl,
+ sock=address,
+ )
+ elif isinstance(address, tuple):
+ self.logger.debug("Connecting to %s ...", address)
connect = asyncio.open_connection(
address[0],
address[1],
@@ -644,13 +652,14 @@ async def _do_connect(self, address: SocketAddrT,
limit=self._limit,
)
else:
+ self.logger.debug("Connecting to file://%s ...", address)
connect = asyncio.open_unix_connection(
path=address,
ssl=ssl,
limit=self._limit,
)
+
self._reader, self._writer = await connect
-
self.logger.debug("Connected.")
@upper_half
--
2.40.0
next prev parent reply other threads:[~2023-05-17 16:35 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-05-17 16:34 [PATCH 0/5] python: backport socket changes from python-qemu-qmp John Snow
2023-05-17 16:34 ` John Snow [this message]
2023-05-17 16:34 ` [PATCH 2/5] python/qmp/legacy: allow using sockets for connect() John Snow
2023-05-17 16:34 ` [PATCH 3/5] python/machine: use connect-based interface for existing sockets John Snow
2023-05-17 16:34 ` [PATCH 4/5] python/qmp/legacy: remove open_with_socket() calls John Snow
2023-05-17 16:34 ` [PATCH 5/5] Revert "python/qmp/protocol: add open_with_socket()" John Snow
2023-05-23 14:40 ` [PATCH 0/5] python: backport socket changes from python-qemu-qmp John Snow
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20230517163406.2593480-2-jsnow@redhat.com \
--to=jsnow@redhat.com \
--cc=berrange@redhat.com \
--cc=bleal@redhat.com \
--cc=crosa@redhat.com \
--cc=marcandre.lureau@redhat.com \
--cc=qemu-devel@nongnu.org \
--cc=vsementsov@yandex-team.ru \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).