Re: *UPDATE* Binary writing to an input pipe and ASCII reading from an output one



Colossus wrote:

Sometimes the console gives no output but the output of the command cpio (redirected in a GtkTextBuffer) is:

cpio: warning: skipped 7099 bytes of junk
cpio: warning: skipped 13776 bytes of junk
cpio: warning: skipped 22769 bytes of junk
cpio: warning: skipped 104333 bytes of junk

while some other times the output (the list of files in the cpio archive) is incomplete. I believed is was a matter of encoding but the cpio archive is binary I'm sure of this while its ouput is ASCII and I have correctly set the encoding, so what can be ?

Ok I got where the error is but I don't know how fix it :-)

ioc = g_io_channel_new_file ( tmp , "r" , NULL );
        g_io_channel_set_encoding (ioc, NULL , NULL);
    g_io_channel_set_flags ( ioc , G_IO_FLAG_NONBLOCK , NULL );

while ( g_io_channel_read_chars ( ioc, buffer, sizeof(buffer), &bytes_read, &error ) == G_IO_STATUS_NORMAL )
    {
        if ( error != NULL )
        {
            g_print ("Read Error: %s\n" , error->message);
            g_error_free ( error );
            g_io_channel_shutdown ( ioc,TRUE,NULL );
                    g_io_channel_unref (ioc);
                    g_spawn_close_pid ( child_pid );
            g_free (tmp);
        }
        g_print ("Bytes letti: %d\t" , bytes_read);
status = g_io_channel_write_chars ( input_ioc , buffer , bytes_read , &bytes_write , &error );
        g_print ("Bytes scritti: %d\n" , bytes_write);
        if ( status == G_IO_STATUS_ERROR )
        {
            g_print ("Write Error: %s\n" , error->message);
            g_error_free ( error );
            g_io_channel_shutdown ( ioc,TRUE,NULL );
                    g_io_channel_unref (ioc);
                    g_spawn_close_pid ( child_pid );
            g_free (tmp);
        }
    }

The red bytes do not correspond to the written ones:
Bytes letti: 65536      Bytes scritti: 65536
Bytes letti: 65536      Bytes scritti: 2015
Bytes letti: 65536      Bytes scritti: 0
Bytes letti: 65536      Bytes scritti: 0
Bytes letti: 65536      Bytes scritti: 0
Bytes letti: 12288      Bytes scritti: 0

The strangeness is that I do not have any error, the status of operation is always G_IO_STATUS_NORMAL; any clue ?

Thank you,
--
Colossus
Xarchiver, a GTK2 only archive manager - http://xarchiver.sourceforge.net
Cpsed, a Linux OpenGL 3D scene editor - http://cpsed.sourceforge.net
Mizio, a QT proxy hunter scanner tool - http://mizio.sourceforge.net



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]