From 626f5678d6196916605070dc715963ec8c9355eb Mon Sep 17 00:00:00 2001 From: Luiz Augusto von Dentz Date: Fri, 26 Sep 2014 17:04:58 +0300 Subject: [PATCH] shared/io: Add io_send --- src/shared/io-glib.c | 20 ++++++++++++++++++++ src/shared/io-mainloop.c | 17 +++++++++++++++++ src/shared/io.h | 2 ++ 3 files changed, 39 insertions(+) diff --git a/src/shared/io-glib.c b/src/shared/io-glib.c index 882ebd623..a2ada66df 100644 --- a/src/shared/io-glib.c +++ b/src/shared/io-glib.c @@ -326,6 +326,26 @@ done: return true; } +ssize_t io_send(struct io *io, const struct iovec *iov, int iovcnt) +{ + int fd; + ssize_t ret; + + if (!io || !io->channel) + return -ENOTCONN; + + fd = io_get_fd(io); + + do { + ret = writev(fd, iov, iovcnt); + } while (ret < 0 && errno == EINTR); + + if (ret < 0) + return -errno; + + return ret; +} + bool io_shutdown(struct io *io) { if (!io || !io->channel) diff --git a/src/shared/io-mainloop.c b/src/shared/io-mainloop.c index b7e0f5f26..7f80d8f57 100644 --- a/src/shared/io-mainloop.c +++ b/src/shared/io-mainloop.c @@ -301,6 +301,23 @@ bool io_set_disconnect_handler(struct io *io, io_callback_func_t callback, return true; } +ssize_t io_send(struct io *io, const struct iovec *iov, int iovcnt) +{ + ssize_t ret; + + if (!io || io->fd < 0) + return -ENOTCONN; + + do { + ret = writev(io->fd, iov, iovcnt); + } while (ret < 0 && errno == EINTR); + + if (ret < 0) + return -errno; + + return ret; +} + bool io_shutdown(struct io *io) { if (!io || io->fd < 0) diff --git a/src/shared/io.h b/src/shared/io.h index 8897964a8..8bc1111d0 100644 --- a/src/shared/io.h +++ b/src/shared/io.h @@ -22,6 +22,7 @@ */ #include +#include typedef void (*io_destroy_func_t)(void *data); @@ -33,6 +34,7 @@ void io_destroy(struct io *io); int io_get_fd(struct io *io); bool io_set_close_on_destroy(struct io *io, bool do_close); +ssize_t io_send(struct io *io, const struct iovec *iov, int iovcnt); bool io_shutdown(struct io *io); typedef bool (*io_callback_func_t)(struct io *io, void *user_data); -- 2.47.3