From 0785bd7a7c58ffaf533f484cb0661671a64ecffd Mon Sep 17 00:00:00 2001 From: Markus Armbruster Date: Wed, 26 Apr 2017 09:36:37 +0200 Subject: sockets: Prepare inet_parse() for flattened SocketAddress I'm going to flatten SocketAddress: rename SocketAddress to SocketAddressLegacy, SocketAddressFlat to SocketAddress, eliminate SocketAddressLegacy except in external interfaces. inet_parse() returns a newly allocated InetSocketAddress. Lift the allocation from inet_parse() into its caller socket_parse() to prepare for flattening SocketAddress. Signed-off-by: Markus Armbruster Message-Id: <1493192202-3184-3-git-send-email-armbru@redhat.com> Reviewed-by: Eric Blake [Straightforward rebase] --- include/qemu/sockets.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'include/qemu') diff --git a/include/qemu/sockets.h b/include/qemu/sockets.h index af28532..8b9325c 100644 --- a/include/qemu/sockets.h +++ b/include/qemu/sockets.h @@ -34,7 +34,7 @@ typedef void NonBlockingConnectHandler(int fd, Error *err, void *opaque); int inet_ai_family_from_address(InetSocketAddress *addr, Error **errp); -InetSocketAddress *inet_parse(const char *str, Error **errp); +int inet_parse(InetSocketAddress *addr, const char *str, Error **errp); int inet_connect(const char *str, Error **errp); int inet_connect_saddr(InetSocketAddress *saddr, NonBlockingConnectHandler *callback, void *opaque, -- cgit v1.1 From dfd100f242370886bb6732f70f1f7cbd8eb9fedc Mon Sep 17 00:00:00 2001 From: Markus Armbruster Date: Wed, 26 Apr 2017 09:36:39 +0200 Subject: sockets: Rename SocketAddress to SocketAddressLegacy The next commit will rename SocketAddressFlat to SocketAddress, and the commit after that will replace most uses of SocketAddressLegacy by SocketAddress, replacing most of this commit's renames right back. Note that checkpatch emits a few "line over 80 characters" warnings. The long lines are all temporary; the SocketAddressLegacy replacement will shorten them again. Signed-off-by: Markus Armbruster Message-Id: <1493192202-3184-5-git-send-email-armbru@redhat.com> Reviewed-by: Eric Blake Signed-off-by: Markus Armbruster --- include/qemu/sockets.h | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) (limited to 'include/qemu') diff --git a/include/qemu/sockets.h b/include/qemu/sockets.h index 8b9325c..f4a4b10 100644 --- a/include/qemu/sockets.h +++ b/include/qemu/sockets.h @@ -45,12 +45,12 @@ NetworkAddressFamily inet_netfamily(int family); int unix_listen(const char *path, char *ostr, int olen, Error **errp); int unix_connect(const char *path, Error **errp); -SocketAddress *socket_parse(const char *str, Error **errp); -int socket_connect(SocketAddress *addr, NonBlockingConnectHandler *callback, +SocketAddressLegacy *socket_parse(const char *str, Error **errp); +int socket_connect(SocketAddressLegacy *addr, NonBlockingConnectHandler *callback, void *opaque, Error **errp); -int socket_listen(SocketAddress *addr, Error **errp); +int socket_listen(SocketAddressLegacy *addr, Error **errp); void socket_listen_cleanup(int fd, Error **errp); -int socket_dgram(SocketAddress *remote, SocketAddress *local, Error **errp); +int socket_dgram(SocketAddressLegacy *remote, SocketAddressLegacy *local, Error **errp); /* Old, ipv4 only bits. Don't use for new code. */ int parse_host_port(struct sockaddr_in *saddr, const char *str); @@ -65,12 +65,12 @@ int socket_init(void); * Get the string representation of the socket * address. A pointer to the allocated address information * struct will be returned, which the caller is required to - * release with a call qapi_free_SocketAddress when no + * release with a call qapi_free_SocketAddressLegacy() when no * longer required. * * Returns: the socket address struct, or NULL on error */ -SocketAddress * +SocketAddressLegacy * socket_sockaddr_to_address(struct sockaddr_storage *sa, socklen_t salen, Error **errp); @@ -83,12 +83,12 @@ socket_sockaddr_to_address(struct sockaddr_storage *sa, * Get the string representation of the local socket * address. A pointer to the allocated address information * struct will be returned, which the caller is required to - * release with a call qapi_free_SocketAddress when no + * release with a call qapi_free_SocketAddressLegacy() when no * longer required. * * Returns: the socket address struct, or NULL on error */ -SocketAddress *socket_local_address(int fd, Error **errp); +SocketAddressLegacy *socket_local_address(int fd, Error **errp); /** * socket_remote_address: @@ -98,12 +98,12 @@ SocketAddress *socket_local_address(int fd, Error **errp); * Get the string representation of the remote socket * address. A pointer to the allocated address information * struct will be returned, which the caller is required to - * release with a call qapi_free_SocketAddress when no + * release with a call qapi_free_SocketAddressLegacy() when no * longer required. * * Returns: the socket address struct, or NULL on error */ -SocketAddress *socket_remote_address(int fd, Error **errp); +SocketAddressLegacy *socket_remote_address(int fd, Error **errp); /** * socket_address_to_string: @@ -118,17 +118,17 @@ SocketAddress *socket_remote_address(int fd, Error **errp); * * Returns: the socket address in string format, or NULL on error */ -char *socket_address_to_string(struct SocketAddress *addr, Error **errp); +char *socket_address_to_string(struct SocketAddressLegacy *addr, Error **errp); /** * socket_address_crumple: * @addr_flat: the socket address to crumple * - * Convert SocketAddressFlat to SocketAddress. Caller is responsible - * for freeing with qapi_free_SocketAddress(). + * Convert SocketAddressFlat to SocketAddressLegacy. Caller is responsible + * for freeing with qapi_free_SocketAddressLegacy(). * - * Returns: the argument converted to SocketAddress. + * Returns: the argument converted to SocketAddressLegacy. */ -SocketAddress *socket_address_crumple(SocketAddressFlat *addr_flat); +SocketAddressLegacy *socket_address_crumple(SocketAddressFlat *addr_flat); #endif /* QEMU_SOCKETS_H */ -- cgit v1.1 From 62cf396b5d397948c5ac4d04d09596ca14f6c173 Mon Sep 17 00:00:00 2001 From: Markus Armbruster Date: Wed, 26 Apr 2017 09:36:40 +0200 Subject: sockets: Rename SocketAddressFlat to SocketAddress Signed-off-by: Markus Armbruster Message-Id: <1493192202-3184-6-git-send-email-armbru@redhat.com> Reviewed-by: Eric Blake Reviewed-by: Prasanna Kumar Kalever --- include/qemu/sockets.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'include/qemu') diff --git a/include/qemu/sockets.h b/include/qemu/sockets.h index f4a4b10..82b7460 100644 --- a/include/qemu/sockets.h +++ b/include/qemu/sockets.h @@ -124,11 +124,11 @@ char *socket_address_to_string(struct SocketAddressLegacy *addr, Error **errp); * socket_address_crumple: * @addr_flat: the socket address to crumple * - * Convert SocketAddressFlat to SocketAddressLegacy. Caller is responsible + * Convert SocketAddress to SocketAddressLegacy. Caller is responsible * for freeing with qapi_free_SocketAddressLegacy(). * * Returns: the argument converted to SocketAddressLegacy. */ -SocketAddressLegacy *socket_address_crumple(SocketAddressFlat *addr_flat); +SocketAddressLegacy *socket_address_crumple(SocketAddress *addr); #endif /* QEMU_SOCKETS_H */ -- cgit v1.1 From bd269ebc82fbaa5fe7ce5bc7c1770ac8acecd884 Mon Sep 17 00:00:00 2001 From: Markus Armbruster Date: Wed, 26 Apr 2017 09:36:41 +0200 Subject: sockets: Limit SocketAddressLegacy to external interfaces SocketAddressLegacy is a simple union, and simple unions are awkward: they have their variant members wrapped in a "data" object on the wire, and require additional indirections in C. SocketAddress is the equivalent flat union. Convert all users of SocketAddressLegacy to SocketAddress, except for existing external interfaces. See also commit fce5d53..9445673 and 85a82e8..c5f1ae3. Signed-off-by: Markus Armbruster Message-Id: <1493192202-3184-7-git-send-email-armbru@redhat.com> Reviewed-by: Eric Blake [Minor editing accident fixed, commit message and a comment tweaked] Signed-off-by: Markus Armbruster --- include/qemu/sockets.h | 33 ++++++++++++++++++++++----------- 1 file changed, 22 insertions(+), 11 deletions(-) (limited to 'include/qemu') diff --git a/include/qemu/sockets.h b/include/qemu/sockets.h index 82b7460..a0b5cae 100644 --- a/include/qemu/sockets.h +++ b/include/qemu/sockets.h @@ -45,12 +45,12 @@ NetworkAddressFamily inet_netfamily(int family); int unix_listen(const char *path, char *ostr, int olen, Error **errp); int unix_connect(const char *path, Error **errp); -SocketAddressLegacy *socket_parse(const char *str, Error **errp); -int socket_connect(SocketAddressLegacy *addr, NonBlockingConnectHandler *callback, +SocketAddress *socket_parse(const char *str, Error **errp); +int socket_connect(SocketAddress *addr, NonBlockingConnectHandler *callback, void *opaque, Error **errp); -int socket_listen(SocketAddressLegacy *addr, Error **errp); +int socket_listen(SocketAddress *addr, Error **errp); void socket_listen_cleanup(int fd, Error **errp); -int socket_dgram(SocketAddressLegacy *remote, SocketAddressLegacy *local, Error **errp); +int socket_dgram(SocketAddress *remote, SocketAddress *local, Error **errp); /* Old, ipv4 only bits. Don't use for new code. */ int parse_host_port(struct sockaddr_in *saddr, const char *str); @@ -65,12 +65,12 @@ int socket_init(void); * Get the string representation of the socket * address. A pointer to the allocated address information * struct will be returned, which the caller is required to - * release with a call qapi_free_SocketAddressLegacy() when no + * release with a call qapi_free_SocketAddress() when no * longer required. * * Returns: the socket address struct, or NULL on error */ -SocketAddressLegacy * +SocketAddress * socket_sockaddr_to_address(struct sockaddr_storage *sa, socklen_t salen, Error **errp); @@ -83,12 +83,12 @@ socket_sockaddr_to_address(struct sockaddr_storage *sa, * Get the string representation of the local socket * address. A pointer to the allocated address information * struct will be returned, which the caller is required to - * release with a call qapi_free_SocketAddressLegacy() when no + * release with a call qapi_free_SocketAddress() when no * longer required. * * Returns: the socket address struct, or NULL on error */ -SocketAddressLegacy *socket_local_address(int fd, Error **errp); +SocketAddress *socket_local_address(int fd, Error **errp); /** * socket_remote_address: @@ -98,12 +98,12 @@ SocketAddressLegacy *socket_local_address(int fd, Error **errp); * Get the string representation of the remote socket * address. A pointer to the allocated address information * struct will be returned, which the caller is required to - * release with a call qapi_free_SocketAddressLegacy() when no + * release with a call qapi_free_SocketAddress() when no * longer required. * * Returns: the socket address struct, or NULL on error */ -SocketAddressLegacy *socket_remote_address(int fd, Error **errp); +SocketAddress *socket_remote_address(int fd, Error **errp); /** * socket_address_to_string: @@ -118,7 +118,7 @@ SocketAddressLegacy *socket_remote_address(int fd, Error **errp); * * Returns: the socket address in string format, or NULL on error */ -char *socket_address_to_string(struct SocketAddressLegacy *addr, Error **errp); +char *socket_address_to_string(struct SocketAddress *addr, Error **errp); /** * socket_address_crumple: @@ -131,4 +131,15 @@ char *socket_address_to_string(struct SocketAddressLegacy *addr, Error **errp); */ SocketAddressLegacy *socket_address_crumple(SocketAddress *addr); +/** + * socket_address_flatten: + * @addr: the socket address to flatten + * + * Convert SocketAddressLegacy to SocketAddress. Caller is responsible + * for freeing with qapi_free_SocketAddress(). + * + * Returns: the argument converted to SocketAddress. + */ +SocketAddress *socket_address_flatten(SocketAddressLegacy *addr); + #endif /* QEMU_SOCKETS_H */ -- cgit v1.1 From 0c099fa7e9248a97c7854e5af84fc2479477ed5d Mon Sep 17 00:00:00 2001 From: Markus Armbruster Date: Wed, 26 Apr 2017 09:36:42 +0200 Subject: sockets: Delete unused helper socket_address_crumple() Signed-off-by: Markus Armbruster Message-Id: <1493192202-3184-8-git-send-email-armbru@redhat.com> Reviewed-by: Eric Blake [Commit message typo fixed] --- include/qemu/sockets.h | 11 ----------- 1 file changed, 11 deletions(-) (limited to 'include/qemu') diff --git a/include/qemu/sockets.h b/include/qemu/sockets.h index a0b5cae..5c326db 100644 --- a/include/qemu/sockets.h +++ b/include/qemu/sockets.h @@ -121,17 +121,6 @@ SocketAddress *socket_remote_address(int fd, Error **errp); char *socket_address_to_string(struct SocketAddress *addr, Error **errp); /** - * socket_address_crumple: - * @addr_flat: the socket address to crumple - * - * Convert SocketAddress to SocketAddressLegacy. Caller is responsible - * for freeing with qapi_free_SocketAddressLegacy(). - * - * Returns: the argument converted to SocketAddressLegacy. - */ -SocketAddressLegacy *socket_address_crumple(SocketAddress *addr); - -/** * socket_address_flatten: * @addr: the socket address to flatten * -- cgit v1.1