|
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [Xen-devel] [PATCH v3 21/31] libxl_qmp_ev: Handle write to socket
The libxl__ev_qmp_* will now send commands to QEMU when the socket is
ready for writes. Also stop pulling for POLLOUT events once the send
queue is empty.
Signed-off-by: Anthony PERARD <anthony.perard@xxxxxxxxxx>
---
tools/libxl/libxl_qmp.c | 48 +++++++++++++++++++++++++++++++++++++++++
1 file changed, 48 insertions(+)
diff --git a/tools/libxl/libxl_qmp.c b/tools/libxl/libxl_qmp.c
index 9b5eb8fd35..02eae1f5ce 100644
--- a/tools/libxl/libxl_qmp.c
+++ b/tools/libxl/libxl_qmp.c
@@ -1416,6 +1416,7 @@ static int ev_qmp_queue_command(libxl__gc *gc,
out->len = len;
out->efd = efd;
LIBXL_TAILQ_INSERT_TAIL(&qmp->tx_buf, out, entry);
+ libxl__ev_fd_modify(gc, &qmp->efd, qmp->efd.events | POLLOUT);
return 0;
}
@@ -1568,6 +1569,46 @@ static int ev_qmp_callback_readable(libxl__egc *egc,
libxl__ev_qmp_state *qmp,
return 0;
}
+static int ev_qmp_callback_writable(libxl__egc *egc,
+ libxl__ev_qmp_state *qmp,
+ int fd)
+{
+ EGC_GC;
+ libxl__qmp_tx_buf *buf;
+ int rc;
+
+ if (!qmp->ready) {
+ return 0;
+ }
+
+ if (LIBXL_TAILQ_EMPTY(&qmp->tx_buf))
+ return 0;
+
+ buf = LIBXL_TAILQ_FIRST(&qmp->tx_buf);
+
+ LOG_QMP("sending: '%.*s'", (int)buf->len, buf->buf);
+
+ if (buf->efd) {
+ int buf_fd = libxl__carefd_fd(buf->efd);
+ rc = libxl__sendmsg_fds(gc, fd, buf->buf, buf->len,
+ 1, &buf_fd, "QMP socket");
+ libxl__carefd_close(buf->efd);
+ } else {
+ rc = libxl_write_exactly(CTX, fd, buf->buf, buf->len,
+ "QMP command", "QMP socket");
+ }
+
+ if (rc)
+ goto out;
+
+ LIBXL_TAILQ_REMOVE(&qmp->tx_buf, buf, entry);
+ free(buf->buf);
+ free(buf);
+
+out:
+ return 1;
+}
+
/* When the QMP client reach the conclusion that the QMP connection doesn't
* work anymore, this function can be called to propagate the error to every
* callback registered. And stop the client. */
@@ -1617,6 +1658,13 @@ static void ev_qmp_fd_callback(libxl__egc *egc,
libxl__ev_fd *ev_fd,
return;
}
}
+ if (revents & POLLOUT) {
+ int ret = ev_qmp_callback_writable(egc, qmp, fd);
+ if (ret == 0) {
+ /* nothing to write, disable it. */
+ libxl__ev_fd_modify(gc, &qmp->efd, events & ~POLLOUT);
+ }
+ }
}
static void libxl__ev_qmp_state_init(libxl__ev_qmp_state *qmp)
--
Anthony PERARD
_______________________________________________
Xen-devel mailing list
Xen-devel@xxxxxxxxxxxxxxxxxxxx
https://lists.xenproject.org/mailman/listinfo/xen-devel
|
![]() |
Lists.xenproject.org is hosted with RackSpace, monitoring our |