summaryrefslogtreecommitdiff
path: root/tests/test-io-channel-socket.c
diff options
context:
space:
mode:
authorMarkus Armbruster <armbru@redhat.com>2017-04-26 09:36:41 +0200
committerMarkus Armbruster <armbru@redhat.com>2017-05-09 09:14:40 +0200
commitbd269ebc82fbaa5fe7ce5bc7c1770ac8acecd884 (patch)
tree82ef0cd9da0812afc7021d5690c14f72e8e13177 /tests/test-io-channel-socket.c
parent62cf396b5d397948c5ac4d04d09596ca14f6c173 (diff)
downloadqemu-bd269ebc82fbaa5fe7ce5bc7c1770ac8acecd884.tar.gz
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 <armbru@redhat.com> Message-Id: <1493192202-3184-7-git-send-email-armbru@redhat.com> Reviewed-by: Eric Blake <eblake@redhat.com> [Minor editing accident fixed, commit message and a comment tweaked] Signed-off-by: Markus Armbruster <armbru@redhat.com>
Diffstat (limited to 'tests/test-io-channel-socket.c')
-rw-r--r--tests/test-io-channel-socket.c104
1 files changed, 48 insertions, 56 deletions
diff --git a/tests/test-io-channel-socket.c b/tests/test-io-channel-socket.c
index a66ffc2fbc..d357cd2a8e 100644
--- a/tests/test-io-channel-socket.c
+++ b/tests/test-io-channel-socket.c
@@ -115,8 +115,8 @@ static void test_io_channel_set_socket_bufs(QIOChannel *src,
}
-static void test_io_channel_setup_sync(SocketAddressLegacy *listen_addr,
- SocketAddressLegacy *connect_addr,
+static void test_io_channel_setup_sync(SocketAddress *listen_addr,
+ SocketAddress *connect_addr,
QIOChannel **src,
QIOChannel **dst)
{
@@ -125,14 +125,14 @@ static void test_io_channel_setup_sync(SocketAddressLegacy *listen_addr,
lioc = qio_channel_socket_new();
qio_channel_socket_listen_sync(lioc, listen_addr, &error_abort);
- if (listen_addr->type == SOCKET_ADDRESS_LEGACY_KIND_INET) {
- SocketAddressLegacy *laddr = qio_channel_socket_get_local_address(
+ if (listen_addr->type == SOCKET_ADDRESS_TYPE_INET) {
+ SocketAddress *laddr = qio_channel_socket_get_local_address(
lioc, &error_abort);
- g_free(connect_addr->u.inet.data->port);
- connect_addr->u.inet.data->port = g_strdup(laddr->u.inet.data->port);
+ g_free(connect_addr->u.inet.port);
+ connect_addr->u.inet.port = g_strdup(laddr->u.inet.port);
- qapi_free_SocketAddressLegacy(laddr);
+ qapi_free_SocketAddress(laddr);
}
*src = QIO_CHANNEL(qio_channel_socket_new());
@@ -165,8 +165,8 @@ static void test_io_channel_complete(QIOTask *task,
}
-static void test_io_channel_setup_async(SocketAddressLegacy *listen_addr,
- SocketAddressLegacy *connect_addr,
+static void test_io_channel_setup_async(SocketAddress *listen_addr,
+ SocketAddress *connect_addr,
QIOChannel **src,
QIOChannel **dst)
{
@@ -186,14 +186,14 @@ static void test_io_channel_setup_async(SocketAddressLegacy *listen_addr,
g_assert(!data.err);
- if (listen_addr->type == SOCKET_ADDRESS_LEGACY_KIND_INET) {
- SocketAddressLegacy *laddr = qio_channel_socket_get_local_address(
+ if (listen_addr->type == SOCKET_ADDRESS_TYPE_INET) {
+ SocketAddress *laddr = qio_channel_socket_get_local_address(
lioc, &error_abort);
- g_free(connect_addr->u.inet.data->port);
- connect_addr->u.inet.data->port = g_strdup(laddr->u.inet.data->port);
+ g_free(connect_addr->u.inet.port);
+ connect_addr->u.inet.port = g_strdup(laddr->u.inet.port);
- qapi_free_SocketAddressLegacy(laddr);
+ qapi_free_SocketAddress(laddr);
}
*src = QIO_CHANNEL(qio_channel_socket_new());
@@ -221,8 +221,8 @@ static void test_io_channel_setup_async(SocketAddressLegacy *listen_addr,
static void test_io_channel(bool async,
- SocketAddressLegacy *listen_addr,
- SocketAddressLegacy *connect_addr,
+ SocketAddress *listen_addr,
+ SocketAddress *connect_addr,
bool passFD)
{
QIOChannel *src, *dst;
@@ -297,27 +297,25 @@ static void test_io_channel(bool async,
static void test_io_channel_ipv4(bool async)
{
- SocketAddressLegacy *listen_addr = g_new0(SocketAddressLegacy, 1);
- SocketAddressLegacy *connect_addr = g_new0(SocketAddressLegacy, 1);
+ SocketAddress *listen_addr = g_new0(SocketAddress, 1);
+ SocketAddress *connect_addr = g_new0(SocketAddress, 1);
- listen_addr->type = SOCKET_ADDRESS_LEGACY_KIND_INET;
- listen_addr->u.inet.data = g_new(InetSocketAddress, 1);
- *listen_addr->u.inet.data = (InetSocketAddress) {
+ listen_addr->type = SOCKET_ADDRESS_TYPE_INET;
+ listen_addr->u.inet = (InetSocketAddress) {
.host = g_strdup("127.0.0.1"),
.port = NULL, /* Auto-select */
};
- connect_addr->type = SOCKET_ADDRESS_LEGACY_KIND_INET;
- connect_addr->u.inet.data = g_new(InetSocketAddress, 1);
- *connect_addr->u.inet.data = (InetSocketAddress) {
+ connect_addr->type = SOCKET_ADDRESS_TYPE_INET;
+ connect_addr->u.inet = (InetSocketAddress) {
.host = g_strdup("127.0.0.1"),
.port = NULL, /* Filled in later */
};
test_io_channel(async, listen_addr, connect_addr, false);
- qapi_free_SocketAddressLegacy(listen_addr);
- qapi_free_SocketAddressLegacy(connect_addr);
+ qapi_free_SocketAddress(listen_addr);
+ qapi_free_SocketAddress(connect_addr);
}
@@ -335,27 +333,25 @@ static void test_io_channel_ipv4_async(void)
static void test_io_channel_ipv6(bool async)
{
- SocketAddressLegacy *listen_addr = g_new0(SocketAddressLegacy, 1);
- SocketAddressLegacy *connect_addr = g_new0(SocketAddressLegacy, 1);
+ SocketAddress *listen_addr = g_new0(SocketAddress, 1);
+ SocketAddress *connect_addr = g_new0(SocketAddress, 1);
- listen_addr->type = SOCKET_ADDRESS_LEGACY_KIND_INET;
- listen_addr->u.inet.data = g_new(InetSocketAddress, 1);
- *listen_addr->u.inet.data = (InetSocketAddress) {
+ listen_addr->type = SOCKET_ADDRESS_TYPE_INET;
+ listen_addr->u.inet = (InetSocketAddress) {
.host = g_strdup("::1"),
.port = NULL, /* Auto-select */
};
- connect_addr->type = SOCKET_ADDRESS_LEGACY_KIND_INET;
- connect_addr->u.inet.data = g_new(InetSocketAddress, 1);
- *connect_addr->u.inet.data = (InetSocketAddress) {
+ connect_addr->type = SOCKET_ADDRESS_TYPE_INET;
+ connect_addr->u.inet = (InetSocketAddress) {
.host = g_strdup("::1"),
.port = NULL, /* Filled in later */
};
test_io_channel(async, listen_addr, connect_addr, false);
- qapi_free_SocketAddressLegacy(listen_addr);
- qapi_free_SocketAddressLegacy(connect_addr);
+ qapi_free_SocketAddress(listen_addr);
+ qapi_free_SocketAddress(connect_addr);
}
@@ -374,22 +370,20 @@ static void test_io_channel_ipv6_async(void)
#ifndef _WIN32
static void test_io_channel_unix(bool async)
{
- SocketAddressLegacy *listen_addr = g_new0(SocketAddressLegacy, 1);
- SocketAddressLegacy *connect_addr = g_new0(SocketAddressLegacy, 1);
+ SocketAddress *listen_addr = g_new0(SocketAddress, 1);
+ SocketAddress *connect_addr = g_new0(SocketAddress, 1);
#define TEST_SOCKET "test-io-channel-socket.sock"
- listen_addr->type = SOCKET_ADDRESS_LEGACY_KIND_UNIX;
- listen_addr->u.q_unix.data = g_new0(UnixSocketAddress, 1);
- listen_addr->u.q_unix.data->path = g_strdup(TEST_SOCKET);
+ listen_addr->type = SOCKET_ADDRESS_TYPE_UNIX;
+ listen_addr->u.q_unix.path = g_strdup(TEST_SOCKET);
- connect_addr->type = SOCKET_ADDRESS_LEGACY_KIND_UNIX;
- connect_addr->u.q_unix.data = g_new0(UnixSocketAddress, 1);
- connect_addr->u.q_unix.data->path = g_strdup(TEST_SOCKET);
+ connect_addr->type = SOCKET_ADDRESS_TYPE_UNIX;
+ connect_addr->u.q_unix.path = g_strdup(TEST_SOCKET);
test_io_channel(async, listen_addr, connect_addr, true);
- qapi_free_SocketAddressLegacy(listen_addr);
- qapi_free_SocketAddressLegacy(connect_addr);
+ qapi_free_SocketAddress(listen_addr);
+ qapi_free_SocketAddress(connect_addr);
g_assert(g_file_test(TEST_SOCKET, G_FILE_TEST_EXISTS) == FALSE);
}
@@ -407,8 +401,8 @@ static void test_io_channel_unix_async(void)
static void test_io_channel_unix_fd_pass(void)
{
- SocketAddressLegacy *listen_addr = g_new0(SocketAddressLegacy, 1);
- SocketAddressLegacy *connect_addr = g_new0(SocketAddressLegacy, 1);
+ SocketAddress *listen_addr = g_new0(SocketAddress, 1);
+ SocketAddress *connect_addr = g_new0(SocketAddress, 1);
QIOChannel *src, *dst;
int testfd;
int fdsend[3];
@@ -427,13 +421,11 @@ static void test_io_channel_unix_fd_pass(void)
fdsend[1] = testfd;
fdsend[2] = testfd;
- listen_addr->type = SOCKET_ADDRESS_LEGACY_KIND_UNIX;
- listen_addr->u.q_unix.data = g_new0(UnixSocketAddress, 1);
- listen_addr->u.q_unix.data->path = g_strdup(TEST_SOCKET);
+ listen_addr->type = SOCKET_ADDRESS_TYPE_UNIX;
+ listen_addr->u.q_unix.path = g_strdup(TEST_SOCKET);
- connect_addr->type = SOCKET_ADDRESS_LEGACY_KIND_UNIX;
- connect_addr->u.q_unix.data = g_new0(UnixSocketAddress, 1);
- connect_addr->u.q_unix.data->path = g_strdup(TEST_SOCKET);
+ connect_addr->type = SOCKET_ADDRESS_TYPE_UNIX;
+ connect_addr->u.q_unix.path = g_strdup(TEST_SOCKET);
test_io_channel_setup_sync(listen_addr, connect_addr, &src, &dst);
@@ -488,8 +480,8 @@ static void test_io_channel_unix_fd_pass(void)
object_unref(OBJECT(src));
object_unref(OBJECT(dst));
- qapi_free_SocketAddressLegacy(listen_addr);
- qapi_free_SocketAddressLegacy(connect_addr);
+ qapi_free_SocketAddress(listen_addr);
+ qapi_free_SocketAddress(connect_addr);
unlink(TEST_SOCKET);
unlink(TEST_FILE);
close(testfd);