Пример #1
0
static VALUE
rg_read_all(int argc, VALUE *argv, VALUE self)
{
        VALUE rbcount, cancellable, result;
        gsize count;
        GError *error = NULL;
        gsize bytes_read;

        rb_scan_args(argc, argv, "11", &rbcount, &cancellable);
        count = RVAL2GSIZE(rbcount);
        result = rb_str_new(NULL, count);
        if (!g_input_stream_read_all(_SELF(self),
                                     RSTRING_PTR(result),
                                     count,
                                     &bytes_read,
                                     RVAL2GCANCELLABLE(cancellable),
                                     &error))
                rbgio_raise_error(error);

        rb_str_set_len(result, bytes_read);
        rb_str_resize(result, bytes_read);
        OBJ_TAINT(result);

        return result;
}
Пример #2
0
/* TODO: Does it make sense to use buffer and count?  We should probably
 * provide a better wrapper that simply pumps out buffer while count hasn't
 * been reached, calling the callback with the bytes written, then with the
 * result. */
static VALUE
rg_write_async(int argc, VALUE *argv, VALUE self)
{
        VALUE rbbuffer, rbcount, rbio_priority, rbcancellable, block;
        const gchar *buffer;
        gsize count;
        int io_priority;
        GCancellable *cancellable;

        rb_scan_args(argc, argv, "22&", &rbbuffer, &rbcount, &rbio_priority, &rbcancellable, &block);
        buffer = RVAL2CSTR(rbbuffer);
        count = RVAL2GSIZE(rbcount);
        io_priority = RVAL2IOPRIORITYDEFAULT(rbio_priority);
        cancellable = RVAL2GCANCELLABLE(rbcancellable);
        SAVE_BLOCK(block);
        g_output_stream_write_async(_SELF(self),
                                    buffer,
                                    count,
                                    io_priority,
                                    cancellable,
                                    rbgio_async_ready_callback,
                                    (gpointer)block);

        return self;
}
Пример #3
0
static VALUE
rg_peek(VALUE self, VALUE rboffset, VALUE rbcount)
{
        gsize offset = RVAL2GSIZE(rboffset);
        gsize count = RVAL2GSIZE(rbcount);
        VALUE result = rb_str_new(NULL, count);
        gsize bytes_peeked = g_buffered_input_stream_peek(_SELF(self),
                                                          RSTRING_PTR(result),
                                                          offset,
                                                          count);

        rb_str_set_len(result, bytes_peeked);
        rb_str_resize(result, bytes_peeked);
        OBJ_TAINT(result);

        return result;
}
Пример #4
0
static VALUE
rg_initialize(int argc, VALUE *argv, VALUE self)
{
        VALUE rbbase_stream, size;
        GInputStream *base_stream, *stream;

        rb_scan_args(argc, argv, "11", &rbbase_stream, &size);
        base_stream = RVAL2GINPUTSTREAM(rbbase_stream);

        stream = NIL_P(size) ?
                g_buffered_input_stream_new(base_stream) :
                g_buffered_input_stream_new_sized(base_stream, RVAL2GSIZE(size));
        G_INITIALIZE(self, stream);

        return Qnil;
}
Пример #5
0
static VALUE
rg_skip(int argc, VALUE *argv, VALUE self)
{
        VALUE count, cancellable;
        GError *error = NULL;
        gssize bytes_skipped;

        rb_scan_args(argc, argv, "11", &count, &cancellable);
        bytes_skipped = g_input_stream_skip(_SELF(self),
                                            RVAL2GSIZE(count),
                                            RVAL2GCANCELLABLE(cancellable),
                                            &error);
        if (bytes_skipped == -1)
                rbgio_raise_error(error);

        return GSSIZE2RVAL(bytes_skipped);
}