/* Send file in chunked encoding. */
while (!cancel && (r = read (fd, buf, sizeof buf)) > 0) {
err = send_file_data_sync (g, buf, r);
- if (err < 0)
+ if (err < 0) {
+ if (err == -2) /* daemon sent cancellation */
+ send_file_cancellation_sync (g);
return err;
+ }
}
- if (cancel) {
+ if (cancel) { /* cancel from either end */
send_file_cancellation_sync (g);
return -1;
}
}
/* Did the daemon send a cancellation message? */
- if (check_for_daemon_cancellation (g))
+ if (check_for_daemon_cancellation (g)) {
+ if (g->verbose)
+ fprintf (stderr, "got daemon cancellation\n");
return -2;
+ }
/* Serialize the chunk. */
chunk.cancel = cancel;
chunk.data.data_len = len;
chunk.data.data_val = (char *) buf;
+ if (g->verbose)
+ fprintf (stderr,
+ "library sending chunk cancel = %d, len = %zu, buf = %p\n",
+ cancel, len, buf);
+
xdrmem_create (&xdr, data, sizeof data, XDR_ENCODE);
if (!xdr_guestfs_chunk (&xdr, &chunk)) {
error (g, "xdr_guestfs_chunk failed (buf = %p, len = %zu)", buf, len);