aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--blockdev-nbd.c50
1 files changed, 16 insertions, 34 deletions
diff --git a/blockdev-nbd.c b/blockdev-nbd.c
index 28f551a7b0..9e3c22109c 100644
--- a/blockdev-nbd.c
+++ b/blockdev-nbd.c
@@ -18,10 +18,10 @@
#include "qmp-commands.h"
#include "block/nbd.h"
#include "io/channel-socket.h"
+#include "io/net-listener.h"
typedef struct NBDServerData {
- QIOChannelSocket *listen_ioc;
- int watch;
+ QIONetListener *listener;
QCryptoTLSCreds *tlscreds;
} NBDServerData;
@@ -32,27 +32,13 @@ static void nbd_blockdev_client_closed(NBDClient *client, bool ignored)
nbd_client_put(client);
}
-static gboolean nbd_accept(QIOChannel *ioc, GIOCondition condition,
- gpointer opaque)
+static void nbd_accept(QIONetListener *listener, QIOChannelSocket *cioc,
+ gpointer opaque)
{
- QIOChannelSocket *cioc;
-
- if (!nbd_server) {
- return FALSE;
- }
-
- cioc = qio_channel_socket_accept(QIO_CHANNEL_SOCKET(ioc),
- NULL);
- if (!cioc) {
- return TRUE;
- }
-
qio_channel_set_name(QIO_CHANNEL(cioc), "nbd-server");
nbd_client_new(NULL, cioc,
nbd_server->tlscreds, NULL,
nbd_blockdev_client_closed);
- object_unref(OBJECT(cioc));
- return TRUE;
}
@@ -62,10 +48,8 @@ static void nbd_server_free(NBDServerData *server)
return;
}
- if (server->watch != -1) {
- g_source_remove(server->watch);
- }
- object_unref(OBJECT(server->listen_ioc));
+ qio_net_listener_disconnect(server->listener);
+ object_unref(OBJECT(server->listener));
if (server->tlscreds) {
object_unref(OBJECT(server->tlscreds));
}
@@ -112,12 +96,12 @@ void nbd_server_start(SocketAddress *addr, const char *tls_creds,
}
nbd_server = g_new0(NBDServerData, 1);
- nbd_server->watch = -1;
- nbd_server->listen_ioc = qio_channel_socket_new();
- qio_channel_set_name(QIO_CHANNEL(nbd_server->listen_ioc),
- "nbd-listener");
- if (qio_channel_socket_listen_sync(
- nbd_server->listen_ioc, addr, errp) < 0) {
+ nbd_server->listener = qio_net_listener_new();
+
+ qio_net_listener_set_name(nbd_server->listener,
+ "nbd-listener");
+
+ if (qio_net_listener_open_sync(nbd_server->listener, addr, errp) < 0) {
goto error;
}
@@ -134,12 +118,10 @@ void nbd_server_start(SocketAddress *addr, const char *tls_creds,
}
}
- nbd_server->watch = qio_channel_add_watch(
- QIO_CHANNEL(nbd_server->listen_ioc),
- G_IO_IN,
- nbd_accept,
- NULL,
- NULL);
+ qio_net_listener_set_client_func(nbd_server->listener,
+ nbd_accept,
+ NULL,
+ NULL);
return;