@@ -78,21 +78,29 @@ static void reset_buffer(pipe_buffer *target) {
7878
7979static gboolean async_read_chan (GIOChannel * source , GIOCondition condition , gpointer data ) {
8080 pipe_buffer * target = data ;
81- gsize len = 0 ;
82- GIOStatus status = g_io_channel_read_chars (source , target -> buffer , target -> size , & len , NULL );
83- if (status != G_IO_STATUS_NORMAL ) {
84- printf ("read status: %d\n" , status );
85- exit (EXIT_FAILURE );
81+ while (TRUE) {
82+ gsize len = 0 ;
83+ GIOStatus status = g_io_channel_read_chars (source , target -> buffer , target -> size , & len , NULL );
84+ switch (status ) {
85+ case G_IO_STATUS_NORMAL :
86+ if (len < target -> size ) {
87+ // shift
88+ target -> buffer += len ;
89+ target -> size -= len ;
90+ // no more data
91+ return TRUE;
92+ }
93+ // else call next func after getting data
94+ target -> next_func (target );
95+ break ;
96+ case G_IO_STATUS_AGAIN :
97+ // no more data
98+ return TRUE;
99+ default :
100+ printf ("read status: %d\n" , status );
101+ exit (EXIT_FAILURE );
102+ }
86103 }
87- if (len < target -> size ) {
88- // shift
89- target -> buffer += len ;
90- target -> size -= len ;
91- } else {
92- // call next func after getting data
93- target -> next_func (target );
94- }
95- return TRUE;
96104}
97105
98106static gboolean chan_error_func (GIOChannel * source , GIOCondition condition , gpointer data ) {
@@ -115,7 +123,7 @@ static void io_start(FILE *source, pipe_buffer *target, gboolean is_stream) {
115123 exit (EXIT_FAILURE );
116124 }
117125 if (is_stream ) {
118- g_io_channel_set_buffer_size (chan , 64LU * 1024LU );
126+ g_io_channel_set_buffer_size (chan , 65536UL );
119127 }
120128 target -> in_id = g_io_add_watch (chan , G_IO_IN , async_read_chan , target );
121129 target -> hup_id = g_io_add_watch (chan , G_IO_HUP , chan_error_func , target );
0 commit comments