#include "chardev/char.h"
#include "io/channel-socket.h"
#include "io/channel-tls.h"
+#include "io/net-listener.h"
#include "qemu/error-report.h"
#include "qapi/error.h"
#include "qapi/clone-visitor.h"
Chardev parent;
QIOChannel *ioc; /* Client I/O channel */
QIOChannelSocket *sioc; /* Client master channel */
- QIOChannelSocket *listen_ioc;
- guint listen_tag;
+ QIONetListener *listener;
QCryptoTLSCreds *tls_creds;
int connected;
int max_size;
qemu_chr_socket_restart_timer(chr);
}
-static gboolean tcp_chr_accept(QIOChannel *chan,
- GIOCondition cond,
- void *opaque);
+static void tcp_chr_accept(QIONetListener *listener,
+ QIOChannelSocket *cioc,
+ void *opaque);
static int tcp_chr_read_poll(void *opaque);
static void tcp_chr_disconnect(Chardev *chr);
tcp_chr_free_connection(chr);
- if (s->listen_ioc && s->listen_tag == 0) {
- s->listen_tag = qio_channel_add_watch(
- QIO_CHANNEL(s->listen_ioc), G_IO_IN, tcp_chr_accept, chr, NULL);
+ if (s->listener) {
+ qio_net_listener_set_client_func(s->listener, tcp_chr_accept,
+ chr, NULL);
}
update_disconnected_filename(s);
if (emit_close) {
if (s->do_nodelay) {
qio_channel_set_delay(s->ioc, false);
}
- if (s->listen_tag) {
- g_source_remove(s->listen_tag);
- s->listen_tag = 0;
+ if (s->listener) {
+ qio_net_listener_set_client_func(s->listener, NULL, NULL, NULL);
}
if (s->tls_creds) {
return ret;
}
-static gboolean tcp_chr_accept(QIOChannel *channel,
- GIOCondition cond,
- void *opaque)
+static void tcp_chr_accept(QIONetListener *listener,
+ QIOChannelSocket *cioc,
+ void *opaque)
{
Chardev *chr = CHARDEV(opaque);
- QIOChannelSocket *sioc;
-
- sioc = qio_channel_socket_accept(QIO_CHANNEL_SOCKET(channel),
- NULL);
- if (!sioc) {
- return TRUE;
- }
-
- tcp_chr_new_client(chr, sioc);
- object_unref(OBJECT(sioc));
-
- return TRUE;
+ tcp_chr_set_client_ioc_name(chr, cioc);
+ tcp_chr_new_client(chr, cioc);
}
static int tcp_chr_wait_connected(Chardev *chr, Error **errp)
if (s->is_listen) {
info_report("QEMU waiting for connection on: %s",
chr->filename);
- qio_channel_set_blocking(QIO_CHANNEL(s->listen_ioc), true, NULL);
- tcp_chr_accept(QIO_CHANNEL(s->listen_ioc), G_IO_IN, chr);
- qio_channel_set_blocking(QIO_CHANNEL(s->listen_ioc), false, NULL);
+ sioc = qio_net_listener_wait_client(s->listener);
+ tcp_chr_set_client_ioc_name(chr, sioc);
+ tcp_chr_new_client(chr, sioc);
+ object_unref(OBJECT(sioc));
} else {
sioc = qio_channel_socket_new();
tcp_chr_set_client_ioc_name(chr, sioc);
s->reconnect_timer = 0;
}
qapi_free_SocketAddress(s->addr);
- if (s->listen_tag) {
- g_source_remove(s->listen_tag);
- s->listen_tag = 0;
- }
- if (s->listen_ioc) {
- object_unref(OBJECT(s->listen_ioc));
+ if (s->listener) {
+ qio_net_listener_set_client_func(s->listener, NULL, NULL, NULL);
+ object_unref(OBJECT(s->listener));
}
if (s->tls_creds) {
object_unref(OBJECT(s->tls_creds));
} else {
if (s->is_listen) {
char *name;
- sioc = qio_channel_socket_new();
+ s->listener = qio_net_listener_new();
name = g_strdup_printf("chardev-tcp-listener-%s", chr->label);
- qio_channel_set_name(QIO_CHANNEL(sioc), name);
+ qio_net_listener_set_name(s->listener, name);
g_free(name);
- if (qio_channel_socket_listen_sync(sioc, s->addr, errp) < 0) {
+ if (qio_net_listener_open_sync(s->listener, s->addr, errp) < 0) {
+ object_unref(OBJECT(s->listener));
+ s->listener = NULL;
goto error;
}
qapi_free_SocketAddress(s->addr);
- s->addr = socket_local_address(sioc->fd, errp);
+ s->addr = socket_local_address(s->listener->sioc[0]->fd, errp);
update_disconnected_filename(s);
- s->listen_ioc = sioc;
if (is_waitconnect &&
qemu_chr_wait_connected(chr, errp) < 0) {
return;
}
if (!s->ioc) {
- s->listen_tag = qio_channel_add_watch(
- QIO_CHANNEL(s->listen_ioc), G_IO_IN,
- tcp_chr_accept, chr, NULL);
+ qio_net_listener_set_client_func(s->listener, tcp_chr_accept,
+ chr, NULL);
}
} else if (qemu_chr_wait_connected(chr, errp) < 0) {
goto error;