diff options
author | Luiz Augusto von Dentz <luiz.von.dentz@intel.com> | 2014-09-26 17:04:58 +0300 |
---|---|---|
committer | Luiz Augusto von Dentz <luiz.von.dentz@intel.com> | 2014-09-30 17:26:48 +0300 |
commit | 626f5678d6196916605070dc715963ec8c9355eb (patch) | |
tree | 585bc914cd7df63d33d588035b1f4d5d8bded08a | |
parent | b06af6d8aafddf56837e0d40a7dfc0c4df28922a (diff) | |
download | bluez-626f5678d6196916605070dc715963ec8c9355eb.tar.gz |
shared/io: Add io_send
-rw-r--r-- | src/shared/io-glib.c | 20 | ||||
-rw-r--r-- | src/shared/io-mainloop.c | 17 | ||||
-rw-r--r-- | src/shared/io.h | 2 |
3 files changed, 39 insertions, 0 deletions
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 <stdbool.h> +#include <sys/uio.h> 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); |