Hi all 

I have a little problem on working with buffer offsets in vala.
In C doing an offset for a "char buf[SOME_SIZE];" is easy, but I have
difficulties doing it in vala.

I attach a testcase with gio async file reading to this mail. In this
testcase there is no buffer offset, so the chunks of the file read are
always put to the beginning of the buffer, overwriting themselves. I
will only get the last chunk that was read from the file.
In the testcase I use a "char[] buffer;".

So how can I do an offset for a reading (and/or writing) buffer in vala?
Any hints appreciated!
Regards 
Jörn

PS: I am not interested in a read_line_async workaround as I have more
cases where a buffer is needed.
public class Test : Object {

	private char[] buffer;
	private const size_t LENGTH = 8192;

	private File file;
	private FileInputStream input_stream;
	private ssize_t bytes_read;

	public Test(File f) {
		this.file = f;
		this.buffer = new char[LENGTH];
	}

	private async void read_contents () {
		print("start reading\n");

		do {
			try {
				bytes_read = yield this.input_stream.read_async(this.buffer,
				                                                10,
				                                                Priority.DEFAULT,
				                                                null);
			}
			catch(Error e) {
				print("%s\n", e.message);
			}
		} while(bytes_read > 0);
		
		print("%s\n", (string)buffer); //Print buffer
	}

	public async void start() {
		try {
			this.input_stream = yield this.file.read_async(Priority.DEFAULT,
			                                               null);
		} 
		catch(Error err) {
			print("%s\n", err.message);
			return;
		}
		yield this.read_contents();
	}

	public static int main() {
		File f = File.new_for_path("/home/qnull/downloader.vala");
		var t = new Test(f);
		t.start();
		new MainLoop(null, false).run();
		return 0;
	}
}

_______________________________________________
Vala-list mailing list
[email protected]
http://mail.gnome.org/mailman/listinfo/vala-list

Reply via email to