From: Amit Shah <amit.shah@redhat.com>
To: qemu list <qemu-devel@nongnu.org>
Cc: Amit Shah <amit.shah@redhat.com>,
Anthony Liguori <aliguori@us.ibm.com>,
Anthony Liguori <anthony@codemonkey.ws>
Subject: [Qemu-devel] [PATCH 07/20] qemu-char: tcp: make use GIOChannel
Date: Tue, 5 Mar 2013 23:21:22 +0530 [thread overview]
Message-ID: <002f726576dfb51bca4854aa257b74d77c1cd4e8.1362505276.git.amit.shah@redhat.com> (raw)
In-Reply-To: <cover.1362505276.git.amit.shah@redhat.com>
In-Reply-To: <cover.1362505276.git.amit.shah@redhat.com>
From: Anthony Liguori <aliguori@us.ibm.com>
I didn't bother switching to g_io_channel_read/write because we need to use
sendmsg on Unix. No problem though since we're using an unbuffered channel.
Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
Signed-off-by: Amit Shah <amit.shah@redhat.com>
---
qemu-char.c | 60 ++++++++++++++++++++++++++++++++++++++++++------------------
1 file changed, 42 insertions(+), 18 deletions(-)
diff --git a/qemu-char.c b/qemu-char.c
index 94ff332..5a53491 100644
--- a/qemu-char.c
+++ b/qemu-char.c
@@ -2285,6 +2285,9 @@ return_err:
/* TCP Net console */
typedef struct {
+
+ GIOChannel *chan, *listen_chan;
+ guint tag, listen_tag;
int fd, listen_fd;
int connected;
int max_size;
@@ -2294,13 +2297,13 @@ typedef struct {
int msgfd;
} TCPCharDriver;
-static void tcp_chr_accept(void *opaque);
+static gboolean tcp_chr_accept(GIOChannel *chan, GIOCondition cond, void *opaque);
static int tcp_chr_write(CharDriverState *chr, const uint8_t *buf, int len)
{
TCPCharDriver *s = chr->opaque;
if (s->connected) {
- return send_all(s->fd, buf, len);
+ return io_channel_send_all(s->chan, buf, len);
} else {
/* XXX: indicate an error ? */
return len;
@@ -2440,15 +2443,16 @@ static ssize_t tcp_chr_recv(CharDriverState *chr, char *buf, size_t len)
}
#endif
-static void tcp_chr_read(void *opaque)
+static gboolean tcp_chr_read(GIOChannel *chan, GIOCondition cond, void *opaque)
{
CharDriverState *chr = opaque;
TCPCharDriver *s = chr->opaque;
uint8_t buf[READ_BUF_LEN];
int len, size;
- if (!s->connected || s->max_size <= 0)
- return;
+ if (!s->connected || s->max_size <= 0) {
+ return FALSE;
+ }
len = sizeof(buf);
if (len > s->max_size)
len = s->max_size;
@@ -2456,10 +2460,13 @@ static void tcp_chr_read(void *opaque)
if (size == 0) {
/* connection closed */
s->connected = 0;
- if (s->listen_fd >= 0) {
- qemu_set_fd_handler2(s->listen_fd, NULL, tcp_chr_accept, NULL, chr);
+ if (s->listen_chan) {
+ s->listen_tag = g_io_add_watch(s->listen_chan, G_IO_IN, tcp_chr_accept, chr);
}
- qemu_set_fd_handler2(s->fd, NULL, NULL, NULL, NULL);
+ g_source_remove(s->tag);
+ s->tag = 0;
+ g_io_channel_unref(s->chan);
+ s->chan = NULL;
closesocket(s->fd);
s->fd = -1;
qemu_chr_be_event(chr, CHR_EVENT_CLOSED);
@@ -2469,6 +2476,8 @@ static void tcp_chr_read(void *opaque)
if (size > 0)
qemu_chr_be_write(chr, buf, size);
}
+
+ return TRUE;
}
#ifndef _WIN32
@@ -2484,9 +2493,8 @@ static void tcp_chr_connect(void *opaque)
TCPCharDriver *s = chr->opaque;
s->connected = 1;
- if (s->fd >= 0) {
- qemu_set_fd_handler2(s->fd, tcp_chr_read_poll,
- tcp_chr_read, NULL, chr);
+ if (s->chan) {
+ s->tag = io_add_watch_poll(s->chan, tcp_chr_read_poll, tcp_chr_read, chr);
}
qemu_chr_generic_open(chr);
}
@@ -2516,13 +2524,15 @@ static int tcp_chr_add_client(CharDriverState *chr, int fd)
if (s->do_nodelay)
socket_set_nodelay(fd);
s->fd = fd;
- qemu_set_fd_handler2(s->listen_fd, NULL, NULL, NULL, NULL);
+ s->chan = io_channel_from_socket(fd);
+ g_source_remove(s->listen_tag);
+ s->listen_tag = 0;
tcp_chr_connect(chr);
return 0;
}
-static void tcp_chr_accept(void *opaque)
+static gboolean tcp_chr_accept(GIOChannel *channel, GIOCondition cond, void *opaque)
{
CharDriverState *chr = opaque;
TCPCharDriver *s = chr->opaque;
@@ -2547,7 +2557,7 @@ static void tcp_chr_accept(void *opaque)
}
fd = qemu_accept(s->listen_fd, addr, &len);
if (fd < 0 && errno != EINTR) {
- return;
+ return FALSE;
} else if (fd >= 0) {
if (s->do_telnetopt)
tcp_chr_telnet_init(fd);
@@ -2556,17 +2566,29 @@ static void tcp_chr_accept(void *opaque)
}
if (tcp_chr_add_client(chr, fd) < 0)
close(fd);
+
+ return TRUE;
}
static void tcp_chr_close(CharDriverState *chr)
{
TCPCharDriver *s = chr->opaque;
if (s->fd >= 0) {
- qemu_set_fd_handler2(s->fd, NULL, NULL, NULL, NULL);
+ if (s->tag) {
+ g_source_remove(s->tag);
+ }
+ if (s->chan) {
+ g_io_channel_unref(s->chan);
+ }
closesocket(s->fd);
}
if (s->listen_fd >= 0) {
- qemu_set_fd_handler2(s->listen_fd, NULL, NULL, NULL, NULL);
+ if (s->listen_tag) {
+ g_source_remove(s->listen_tag);
+ }
+ if (s->listen_chan) {
+ g_io_channel_unref(s->listen_chan);
+ }
closesocket(s->listen_fd);
}
g_free(s);
@@ -2632,7 +2654,8 @@ static CharDriverState *qemu_chr_open_socket_fd(int fd, bool do_nodelay,
if (is_listen) {
s->listen_fd = fd;
- qemu_set_fd_handler2(s->listen_fd, NULL, tcp_chr_accept, NULL, chr);
+ s->listen_chan = io_channel_from_socket(s->listen_fd);
+ s->listen_tag = g_io_add_watch(s->listen_chan, G_IO_IN, tcp_chr_accept, chr);
if (is_telnet) {
s->do_telnetopt = 1;
}
@@ -2640,13 +2663,14 @@ static CharDriverState *qemu_chr_open_socket_fd(int fd, bool do_nodelay,
s->connected = 1;
s->fd = fd;
socket_set_nodelay(fd);
+ s->chan = io_channel_from_socket(s->fd);
tcp_chr_connect(chr);
}
if (is_listen && is_waitconnect) {
printf("QEMU waiting for connection on: %s\n",
chr->filename);
- tcp_chr_accept(chr);
+ tcp_chr_accept(s->listen_chan, G_IO_IN, chr);
socket_set_nonblock(s->listen_fd);
}
return chr;
--
1.8.1.2
next prev parent reply other threads:[~2013-03-05 17:54 UTC|newest]
Thread overview: 32+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-03-05 17:51 [Qemu-devel] [PATCH 00/20] chardev flow control Amit Shah
2013-03-05 17:51 ` [Qemu-devel] [PATCH 01/20] char-socket: fix error reporting Amit Shah
2013-03-05 17:51 ` [Qemu-devel] [PATCH 02/20] qemu-char: remove dead/confusing logic with nb_stdio_clients Amit Shah
2013-03-05 17:51 ` [Qemu-devel] [PATCH 03/20] char: add IOWatchPoll support Amit Shah
2013-03-29 9:53 ` Amit Shah
2013-03-29 12:24 ` Anthony Liguori
2013-03-29 12:42 ` Amit Shah
2013-03-29 14:03 ` Anthony Liguori
2013-03-29 16:08 ` Amit Shah
2013-03-05 17:51 ` [Qemu-devel] [PATCH 04/20] qemu-char: convert fd_chr to use a GIOChannel Amit Shah
2013-03-05 17:51 ` [Qemu-devel] [PATCH 05/20] qemu-char: convert pty to GIOChannel Amit Shah
2013-03-05 17:51 ` [Qemu-devel] [PATCH 06/20] qemu-char: convert UDP " Amit Shah
2013-03-05 17:51 ` Amit Shah [this message]
2013-03-05 17:51 ` [Qemu-devel] [PATCH 08/20] qemu-char: add watch support Amit Shah
2013-03-05 17:51 ` [Qemu-devel] [PATCH 09/20] qemu-char: add pty watch Amit Shah
2013-03-05 17:51 ` [Qemu-devel] [PATCH 10/20] char: add gio watch fn for tcp backends Amit Shah
2013-03-05 17:51 ` [Qemu-devel] [PATCH 11/20] qemu-char: use a glib timeout instead of qemu-timer Amit Shah
2013-03-15 15:06 ` Laurent Desnogues
2013-03-15 15:44 ` Anthony Liguori
2013-03-15 16:19 ` Laurent Desnogues
2013-03-25 9:38 ` Stefan Hajnoczi
2013-03-05 17:51 ` [Qemu-devel] [PATCH 12/20] qemu-char: remove use of QEMUTimer in favor of glib idle function Amit Shah
2013-03-05 17:51 ` [Qemu-devel] [PATCH 13/20] qemu-char: make char drivers dynamically registerable Amit Shah
2013-03-05 17:51 ` [Qemu-devel] [PATCH 14/20] qemu-char: move spice registration to spice-qemu-char.c Amit Shah
2013-03-05 17:51 ` [Qemu-devel] [PATCH 15/20] qemu-char: move baum registration to baum.c Amit Shah
2013-03-05 17:51 ` [Qemu-devel] [PATCH 16/20] qemu-char: move msmouse registeration to msmouse.c Amit Shah
2013-03-05 17:51 ` [Qemu-devel] [PATCH 17/20] qemu-char: move text console init to console.c Amit Shah
2013-03-13 17:19 ` Anthony Liguori
2013-03-05 17:51 ` [Qemu-devel] [PATCH 18/20] serial: add flow control to transmit Amit Shah
2013-03-05 17:51 ` [Qemu-devel] [PATCH 19/20] virtio: console: add flow control Amit Shah
2013-03-05 17:51 ` [Qemu-devel] [PATCH 20/20] virtio-serial: make flow control explicit in virtio-console Amit Shah
2013-03-12 2:02 ` [Qemu-devel] [PATCH 00/20] chardev flow control Anthony Liguori
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=002f726576dfb51bca4854aa257b74d77c1cd4e8.1362505276.git.amit.shah@redhat.com \
--to=amit.shah@redhat.com \
--cc=aliguori@us.ibm.com \
--cc=anthony@codemonkey.ws \
--cc=qemu-devel@nongnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).