[pulseaudio-commits] r2343 - in /branches/glitch-free/src/pulsecore: ioline.c ioline.h
svnmailer-noreply at 0pointer.de
svnmailer-noreply at 0pointer.de
Thu May 1 18:23:33 PDT 2008
Author: lennart
Date: Fri May 2 03:23:32 2008
New Revision: 2343
URL: http://0pointer.de/cgi-bin/viewcvs.cgi?rev=2343&root=pulseaudio&view=rev
Log:
some modernizations
Modified:
branches/glitch-free/src/pulsecore/ioline.c
branches/glitch-free/src/pulsecore/ioline.h
Modified: branches/glitch-free/src/pulsecore/ioline.c
URL: http://0pointer.de/cgi-bin/viewcvs.cgi/branches/glitch-free/src/pulsecore/ioline.c?rev=2343&root=pulseaudio&r1=2342&r2=2343&view=diff
==============================================================================
--- branches/glitch-free/src/pulsecore/ioline.c (original)
+++ branches/glitch-free/src/pulsecore/ioline.c Fri May 2 03:23:32 2008
@@ -49,7 +49,6 @@
pa_iochannel *io;
pa_defer_event *defer_event;
pa_mainloop_api *mainloop;
- int dead;
char *wbuf;
size_t wbuf_length, wbuf_index, wbuf_valid_length;
@@ -57,10 +56,11 @@
char *rbuf;
size_t rbuf_length, rbuf_index, rbuf_valid_length;
- void (*callback)(pa_ioline*io, const char *s, void *userdata);
+ pa_ioline_cb_t callback;
void *userdata;
- int defer_close;
+ pa_bool_t dead:1;
+ pa_bool_t defer_close:1;
};
static void io_callback(pa_iochannel*io, void *userdata);
@@ -73,7 +73,6 @@
l = pa_xnew(pa_ioline, 1);
PA_REFCNT_INIT(l);
l->io = io;
- l->dead = 0;
l->wbuf = NULL;
l->wbuf_length = l->wbuf_index = l->wbuf_valid_length = 0;
@@ -89,7 +88,8 @@
l->defer_event = l->mainloop->defer_new(l->mainloop, defer_callback, l);
l->mainloop->defer_enable(l->defer_event, 0);
- l->defer_close = 0;
+ l->dead = FALSE;
+ l->defer_close = FALSE;
pa_iochannel_set_callback(io, io_callback, l);
@@ -130,7 +130,7 @@
pa_assert(l);
pa_assert(PA_REFCNT_VALUE(l) >= 1);
- l->dead = 1;
+ l->dead = TRUE;
if (l->io) {
pa_iochannel_free(l->io);
@@ -166,11 +166,13 @@
/* In case the allocated buffer is too small, enlarge it. */
if (l->wbuf_valid_length + len > l->wbuf_length) {
size_t n = l->wbuf_valid_length+len;
- char *new = pa_xmalloc(n);
+ char *new = pa_xnew(char, n);
+
if (l->wbuf) {
memcpy(new, l->wbuf+l->wbuf_index, l->wbuf_valid_length);
pa_xfree(l->wbuf);
}
+
l->wbuf = new;
l->wbuf_length = n;
l->wbuf_index = 0;
@@ -191,15 +193,18 @@
}
}
-void pa_ioline_set_callback(pa_ioline*l, void (*callback)(pa_ioline*io, const char *s, void *userdata), void *userdata) {
- pa_assert(l);
- pa_assert(PA_REFCNT_VALUE(l) >= 1);
+void pa_ioline_set_callback(pa_ioline*l, pa_ioline_cb_t callback, void *userdata) {
+ pa_assert(l);
+ pa_assert(PA_REFCNT_VALUE(l) >= 1);
+
+ if (l->dead)
+ return;
l->callback = callback;
l->userdata = userdata;
}
-static void failure(pa_ioline *l, int process_leftover) {
+static void failure(pa_ioline *l, pa_bool_t process_leftover) {
pa_assert(l);
pa_assert(PA_REFCNT_VALUE(l) >= 1);
pa_assert(!l->dead);
@@ -282,7 +287,7 @@
memmove(l->rbuf, l->rbuf+l->rbuf_index, l->rbuf_valid_length);
} else {
/* Enlarge the buffer */
- char *new = pa_xmalloc(n);
+ char *new = pa_xnew(char, n);
if (l->rbuf_valid_length)
memcpy(new, l->rbuf+l->rbuf_index, l->rbuf_valid_length);
pa_xfree(l->rbuf);
@@ -305,9 +310,9 @@
if (r < 0 && errno != ECONNRESET) {
pa_log("read(): %s", pa_cstrerror(errno));
- failure(l, 0);
+ failure(l, FALSE);
} else
- failure(l, 1);
+ failure(l, TRUE);
return -1;
}
@@ -338,7 +343,7 @@
if (r < 0 && errno != EPIPE)
pa_log("write(): %s", pa_cstrerror(errno));
- failure(l, 0);
+ failure(l, FALSE);
return -1;
}
@@ -370,7 +375,7 @@
do_write(l);
if (l->defer_close && !l->wbuf_valid_length)
- failure(l, 1);
+ failure(l, TRUE);
pa_ioline_unref(l);
}
@@ -400,7 +405,7 @@
pa_assert(l);
pa_assert(PA_REFCNT_VALUE(l) >= 1);
- l->defer_close = 1;
+ l->defer_close = TRUE;
if (!l->wbuf_valid_length)
l->mainloop->defer_enable(l->defer_event, 1);
Modified: branches/glitch-free/src/pulsecore/ioline.h
URL: http://0pointer.de/cgi-bin/viewcvs.cgi/branches/glitch-free/src/pulsecore/ioline.h?rev=2343&root=pulseaudio&r1=2342&r2=2343&view=diff
==============================================================================
--- branches/glitch-free/src/pulsecore/ioline.h (original)
+++ branches/glitch-free/src/pulsecore/ioline.h Fri May 2 03:23:32 2008
@@ -33,6 +33,8 @@
typedef struct pa_ioline pa_ioline;
+typedef void (*pa_ioline_cb_t)(pa_ioline*io, const char *s, void *userdata);
+
pa_ioline* pa_ioline_new(pa_iochannel *io);
void pa_ioline_unref(pa_ioline *l);
pa_ioline* pa_ioline_ref(pa_ioline *l);
@@ -45,7 +47,7 @@
void pa_ioline_printf(pa_ioline *s, const char *format, ...) PA_GCC_PRINTF_ATTR(2,3);
/* Set the callback function that is called for every recieved line */
-void pa_ioline_set_callback(pa_ioline*io, void (*callback)(pa_ioline*io, const char *s, void *userdata), void *userdata);
+void pa_ioline_set_callback(pa_ioline*io, pa_ioline_cb_t callback, void *userdata);
/* Make sure to close the ioline object as soon as the send buffer is emptied */
void pa_ioline_defer_close(pa_ioline *io);
More information about the pulseaudio-commits
mailing list