On Thu, Aug 19, 2021 at 11:48:16AM -0400, John Snow wrote: > On Thu, Aug 19, 2021 at 10:50 AM Eric Blake <ebl...@redhat.com> wrote: > > > On Wed, Aug 18, 2021 at 10:24:52AM -0400, John Snow wrote: > > > > > > > > > > + @upper_half > > > > > + @require(Runstate.IDLE) > > > > > + async def accept(self, address: Union[str, Tuple[str, int]], > > > > > + ssl: Optional[SSLContext] = None) -> None: > > > > > + """ > > > > > + Accept a connection and begin processing message queues. > > > > > + > > > > > + If this call fails, `runstate` is guaranteed to be set back > > to > > > > `IDLE`. > > > > > + > > > > > + :param address: > > > > > + Address to listen to; UNIX socket path or TCP > > address/port. > > > > > > > > Can't TCP use a well-known port name instead of an int? But limiting > > > > clients to just int port for now isn't fatal to the patch. > > > > > > > > > > > The old QMP library didn't support this, and I used the old library as my > > > template here. I'm willing to change the address format and types to be > > > more comprehensive, but I was thinking that it should probably try to > > match > > > or adhere to some standard; de-facto or otherwise. I wasn't sure which to > > > pick, and we use a few different ones in QEMU itself. Any recommendations > > > for me? > > > > I asked because I know QAPI specifies TCP as string/string (the > > hostname as a string makes absolute sense, but the port number as a > > string is because of the less-used feature of a well-known port name). > > I'm fine if the initial patch uses an int for the port number here; we > > can always add support for more formats down the road when someone > > actually has a use for them. > > > > > https://docs.python.org/3/library/socket.html#socket-families > > "A pair (host, port) is used for the AF_INET address family, where host is > a string representing either a hostname in Internet domain notation like ' > daring.cwi.nl' or an IPv4 address like '100.50.200.5', and port is an > integer." > > The docs seem to suggest that I am actually limited only to integers here. > Do you have an example of using a string for a port number? I have to admit > I am not well acquainted with it.
QEMU uses getaddrinfo() at inet_parse_connect_saddr() to translate the string/string pair to a socket address. Python equivalent: >> socket.getaddrinfo('localhost', 'ssh') [(<AddressFamily.AF_INET6: 10>, <SocketKind.SOCK_STREAM: 1>, 6, '', ('::1', 22, 0, 0)), (<AddressFamily.AF_INET6: 10>, <SocketKind.SOCK_DGRAM: 2>, 17, '', ('::1', 22, 0, 0)), (<AddressFamily.AF_INET6: 10>, <SocketKind.SOCK_STREAM: 1>, 132, '', ('::1', 22, 0, 0)), (<AddressF amily.AF_INET6: 10>, <SocketKind.SOCK_SEQPACKET: 5>, 132, '', ('::1', 22, 0, 0)), (<AddressFamily.AF_INET: 2>, <SocketKind.SOCK_STREAM: 1>, 6, '', ('127.0.0.1', 22)), (<AddressFamily.AF_INET: 2>, <SocketKind.SOCK_DGRAM: 2>, 17, '', ('127.0.0.1', 22)), (<AddressFamily.AF_INE T: 2>, <SocketKind.SOCK_STREAM: 1>, 132, '', ('127.0.0.1', 22)), (<AddressFamily.AF_INET: 2>, <SocketKind.SOCK_SEQPACKET: 5>, 132, '', ('127.0.0.1', 22))] Translating this to the correct arguments to socket.socket() and socket.socket.connect() seems overly complicated, though. -- Eduardo