From: Christian Pointner Date: Fri, 1 Jul 2011 03:15:56 +0000 (+0000) Subject: improvements (closing on error or EOF at STDIN) X-Git-Url: https://git.realraum.at/?a=commitdiff_plain;h=bb4b02d4516ff88410e423050acf335798d30b4f;p=svn42.git improvements (closing on error or EOF at STDIN) --- diff --git a/dart-sounds/src/dart-sounds.c b/dart-sounds/src/dart-sounds.c index d22ac51..58931ac 100644 --- a/dart-sounds/src/dart-sounds.c +++ b/dart-sounds/src/dart-sounds.c @@ -138,9 +138,13 @@ static gpointer play_file(gpointer data) GMutex* mutex = p->mutex; free(p); + if(!name) + return NULL; + g_print("playing '../media/%s.ogg'\n", name); char* path; asprintf(&path, "../media/%s.ogg", name); + free(name); if(!path) return NULL; @@ -179,17 +183,19 @@ static gboolean stdin_read(GIOChannel* src, GIOCondition cond, gpointer data) g_main_loop_quit(p->loop); } + g_print("read %d bytes from STDIN\n", len); + offset+=len; if(offset > sizeof(buf)) offset = sizeof(buf); - size_t i; - for(i=0; i < offset; ++i) { + size_t i = 0; + for(;i < offset;) { if(buf[i] == '\n') { buf[i] = 0; struct play_file_param* data = malloc(sizeof(struct play_file_param)); if(data) { - data->name = buf; + data->name = strdup(buf); data->pipeline = p->pipeline; data->source = p->source; data->sval = p->sval; @@ -201,8 +207,13 @@ static gboolean stdin_read(GIOChannel* src, GIOCondition cond, gpointer data) if(i < offset) { memmove(buf, &(buf[i+1]), offset - (i+1)); offset -= i+1; - } else offset = 0; + i = 0; + } else { + offset = 0; + break; + } } + else i++; } return 1; @@ -244,7 +255,7 @@ int main(int argc, char *argv[]) p.sval = &sval; p.cond = cond; p.mutex = mutex; - if(!g_io_add_watch(chan, G_IO_IN, (GIOFunc)stdin_read, &p)) { + if(!g_io_add_watch(chan, G_IO_IN | G_IO_ERR | G_IO_HUP, (GIOFunc)stdin_read, &p)) { g_printerr("watch for IO Channel could not be added.\n"); return 1; }