[rfc] hide rs_buffers_t from public interface
Martin Pool <[email protected]> Mon, 16 Feb 2004 15:36:16 +1100
| Newsgroups | gmane.network.librsync.general |
|---|---|
| Message-ID | <[email protected]> |
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. The application might not necessarily be able to provide all the data when the library needs it. The callback should have the option to either indicate that it is blocked (return RS_BLOCKED) or to process only part of the data. In short the callbacks would work a lot like unix read/write/pread on a nonblocking socket. Attached is a sample of how it might work. I think I like it. Any comments? -- Martin
simple-sig.c
(text/x-csrc, 566 B)
#include <unistd.h>
#include <librsync.h>
int main(void)
{
const int in_fd = STDIN_FILENO, out_fd = STDOUT_FILENO;
rs_job_t *job;
rs_result result;
rs_gensig_begin(&job,
rs_fd_read, &in_fd,
rs_fd_write, &out_fd);
while ((result = rs_job_drive(job)) == RS_BLOCKED) {
/* imagine a select() on stdin/stdout here, if we
* expected them to be nonblocking */
;
}
rs_job_free(job);
return result;
}
signature.asc
(application/pgp-signature, 189 B)
-----BEGIN PGP SIGNATURE----- Version: GnuPG v1.2.4 (GNU/Linux) iD8DBQFAMEi+PGPKP6Cz6IsRAvKaAJ9t93vtNCcpRVBQj9PscH7szOvaRgCgymZK wgqSED7SwzO5O3M3y6Y36s8= =Rjvm -----END PGP SIGNATURE-----