summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2009-04-29 04:14:52 +0200
committerLennart Poettering <lennart@poettering.net>2009-04-29 04:14:52 +0200
commitc2150118bfded6dab8c3023ee5b21f87204b8228 (patch)
tree367a8d47abe21961e8bfca7c1bd3c6bb5da1087a
parenta64097ab1f3be781aae36f8e66a3ce03987629c3 (diff)
ioline: add new calls pa_ioline_detach_iochannel() and pa_ioline_is_drained()
-rw-r--r--src/pulsecore/ioline.c26
-rw-r--r--src/pulsecore/ioline.h7
2 files changed, 31 insertions, 2 deletions
diff --git a/src/pulsecore/ioline.c b/src/pulsecore/ioline.c
index 7f252bc4..7afdb08c 100644
--- a/src/pulsecore/ioline.c
+++ b/src/pulsecore/ioline.c
@@ -283,7 +283,7 @@ static int do_read(pa_ioline *l) {
pa_assert(l);
pa_assert(PA_REFCNT_VALUE(l) >= 1);
- while (!l->dead && pa_iochannel_is_readable(l->io)) {
+ while (l->io && !l->dead && pa_iochannel_is_readable(l->io)) {
ssize_t r;
size_t len;
@@ -348,7 +348,7 @@ static int do_write(pa_ioline *l) {
pa_assert(l);
pa_assert(PA_REFCNT_VALUE(l) >= 1);
- while (!l->dead && pa_iochannel_is_writable(l->io) && l->wbuf_valid_length) {
+ while (l->io && !l->dead && pa_iochannel_is_writable(l->io) && l->wbuf_valid_length > 0) {
if ((r = pa_iochannel_write(l->io, l->wbuf+l->wbuf_index, l->wbuf_valid_length)) <= 0) {
@@ -443,3 +443,25 @@ void pa_ioline_printf(pa_ioline *l, const char *format, ...) {
pa_ioline_puts(l, t);
pa_xfree(t);
}
+
+pa_iochannel* pa_ioline_detach_iochannel(pa_ioline *l) {
+ pa_iochannel *r;
+
+ pa_assert(l);
+
+ if (!l->io)
+ return NULL;
+
+ r = l->io;
+ l->io = NULL;
+
+ pa_iochannel_set_callback(r, NULL, NULL);
+
+ return r;
+}
+
+pa_bool_t pa_ioline_is_drained(pa_ioline *l) {
+ pa_assert(l);
+
+ return l->wbuf_valid_length <= 0;
+}
diff --git a/src/pulsecore/ioline.h b/src/pulsecore/ioline.h
index 26e2a22c..d973a3c7 100644
--- a/src/pulsecore/ioline.h
+++ b/src/pulsecore/ioline.h
@@ -54,4 +54,11 @@ void pa_ioline_set_drain_callback(pa_ioline*io, pa_ioline_drain_cb_t callback, v
/* Make sure to close the ioline object as soon as the send buffer is emptied */
void pa_ioline_defer_close(pa_ioline *io);
+/* Returns TRUE when everything was written */
+pa_bool_t pa_ioline_is_drained(pa_ioline *io);
+
+/* Detaches from the iochannel and returns it. Data that has already
+ * been read will not be available in the detached iochannel */
+pa_iochannel* pa_ioline_detach_iochannel(pa_ioline *l);
+
#endif