static gboolean _channel_out(Copy * copy, GIOChannel * source) { gsize written; GError * error = NULL; copy->out_id = 0; /* write data */ if(g_io_channel_write_chars(source, copy->buf, copy->buf_cnt, &written, &error) == G_IO_STATUS_ERROR) return _channel_out_error(copy, source, error); if(copy->buf_cnt == sizeof(copy->buf)) g_idle_add(_regular_idle_in, copy); /* read again */ copy->buf_cnt -= written; memmove(copy->buf, ©->buf[written], copy->buf_cnt); copy->cnt += written; _out_rate(copy); if(copy->buf_cnt > 0) g_idle_add(_regular_idle_out, copy); /* continue to write */ else if(copy->eof == 1) /* reached end of input */ { if(g_io_channel_shutdown(copy->out_channel, TRUE, &error) == G_IO_STATUS_ERROR) return _channel_out_error(copy, source, error); gtk_main_quit(); /* XXX ugly */ } return FALSE; }
static gboolean _channel_out(Progress * p, GIOChannel * source) { GIOStatus status; gsize written; GError * error = NULL; #ifdef DEBUG fprintf(stderr, "DEBUG: %s()\n", __func__); #endif p->out_id = 0; /* write data */ status = g_io_channel_write_chars(source, p->buf, p->buf_cnt, &written, &error); if(status == G_IO_STATUS_ERROR) { _progress_gerror(p, p->prefs->filename, error, 1); gtk_main_quit(); return FALSE; } else if(status == G_IO_STATUS_EOF) { p->eof = 1; /* reached end of output file */ _progress_error(p, p->prefs->filename, 1); g_io_channel_shutdown(source, TRUE, NULL); } else if(p->buf_cnt == p->bufsiz) g_idle_add(_progress_idle_in, p); /* read again */ p->buf_cnt -= written; memmove(p->buf, &p->buf[written], p->buf_cnt); p->cnt += written; _out_rate(p); if(p->buf_cnt > 0) g_idle_add(_progress_idle_out, p); /* continue to write */ else if(p->eof == 1) /* reached end of output */ { g_io_channel_shutdown(p->out_channel, TRUE, NULL); gtk_main_quit(); } return FALSE; }