Re: [rfc] hide rs_buffers_t from public interface

David Helgason <[email protected]> Mon, 16 Feb 2004 16:27:02 +0100
Newsgroups gmane.network.librsync.general
Message-ID <[email protected]>
On 16. feb 2004, at 05:36, Martin Pool wrote:

> I was thinking on the weekend about what could be done to make the
> librsync interface a bit simpler.
>
> It might be better to have the library do all input and output through
> user callbacks, rather than exposing its buffering at all.  This is to
> say that something like rs_job_drive would be the main interface, and
> rs_buffers_t would be removed, or at least not public.  When the
> library needs some input data, it calls the input callback.  Similarly
> for output and for reading blocks from the basis file.

I don't mind this interface at all, but I need the buffer interface to 
do my work (run the algorithms on data inside postgresql) as I've got 
no file descriptors  in there. So please don't remove or hide it.

I also avoided the callback stuff as there wouldn't have been any win 
there (and a net loss in more complex code and having the code spread 
out: something I dislike when doing C). The buffer interface may take a 
few minutes to wrap ones head around, but it's really golden in its 
straight-forwardness. I'd almost say its a doc problem if anything.

...

Now, looking at my code again, I see that the postgresql read and write 
functions do have a signature exactly like the normal read/write 
functions. So your suggestion might just plug'n'play. Hey, cool. Do 
your worst :)



David Helgason,
Over the Edge Entertainments



Ps. I've got:

	do {
		// Read in more data when emptying the in-buffer
		if (bufs.avail_in == 0 && ! bufs.eof_in) {
			total_read_delta += bufs.avail_in = lo_read(fd_delta, inBuffer, 
bufSize);
			bufs.next_in = inBuffer;
			if (total_read_delta == length_delta)
				bufs.eof_in = 1;

			elog(DEBUG, "Reading %d bytes (eof %d)", bufs.avail_in, bufs.eof_in);
		}
		
		// Iterate the job
		ok = rs_job_iter (job, &bufs);

		// Write out data when filling the out-buffer
		if (bufs.avail_out == 0 || bufs.eof_in) {
			int bytes = lo_write(fd_out, outBuffer, bufs.next_out - outBuffer);
			bufs.next_out = outBuffer;
			bufs.avail_out = bufSize;
			elog(DEBUG, "Writing %d bytes (eof %d)", bytes, bufs.eof_in);
		}

		if (ok == RS_DONE)
			break;
		if (ok != RS_BLOCKED)
			elog(ERROR, "An error occured creating the patch (%s)", 
rs_strerror(ok));
	} while (ok == RS_BLOCKED);



-------------------------------------------------------
SF.Net is sponsored by: Speed Start Your Linux Apps Now.
Build and deploy apps & Web services for Linux with
a free DVD software kit from IBM. Click Now!
http://ads.osdn.com/?ad_id=1356&alloc_id=3438&op=click