]> git.ipfire.org Git - thirdparty/qemu.git/commit
util/qemu-sockets: Refactor success and failure paths in inet_listen_saddr()
authorJuraj Marcin <jmarcin@redhat.com>
Wed, 21 May 2025 13:52:32 +0000 (15:52 +0200)
committerDaniel P. Berrangé <berrange@redhat.com>
Thu, 22 May 2025 10:24:41 +0000 (11:24 +0100)
commit911e0f2c6e2d00c985affa75ec188c8edcf480f2
tree00da4e67a23a4c2143a531dabd26d0b255287702
parentb8b5278aca78be4a1c2e7cbb11c6be176f63706d
util/qemu-sockets: Refactor success and failure paths in inet_listen_saddr()

To get a listening socket, we need to first create a socket, try binding
it to a certain port, and lastly starting listening to it. Each of these
operations can fail due to various reasons, one of them being that the
requested address/port is already in use. In such case, the function
tries the same process with a new port number.

This patch refactors the port number loop, so the success path is no
longer buried inside the 'if' statements in the middle of the loop. Now,
the success path is not nested and ends at the end of the iteration
after successful socket creation, binding, and listening. In case any of
the operations fails, it either continues to the next iteration (and the
next port) or jumps out of the loop to handle the error and exits the
function.

Signed-off-by: Juraj Marcin <jmarcin@redhat.com>
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
util/qemu-sockets.c