+static int
+check_for_daemon_cancellation (guestfs_h *g)
+{
+ fd_set rset;
+ struct timeval tv;
+ int r;
+ char buf[4];
+ uint32_t flag;
+ XDR xdr;
+
+ FD_ZERO (&rset);
+ FD_SET (g->sock, &rset);
+ tv.tv_sec = 0;
+ tv.tv_usec = 0;
+ r = select (g->sock+1, &rset, NULL, NULL, &tv);
+ if (r == -1) {
+ perrorf (g, "select");
+ return 0;
+ }
+ if (r == 0)
+ return 0;
+
+ /* Read the message from the daemon. */
+ r = xread (g->sock, buf, sizeof buf);
+ if (r == -1) {
+ perrorf (g, "read");
+ return 0;
+ }
+
+ xdrmem_create (&xdr, buf, sizeof buf, XDR_DECODE);
+ xdr_uint32_t (&xdr, &flag);
+ xdr_destroy (&xdr);
+
+ if (flag != GUESTFS_CANCEL_FLAG) {
+ error (g, "check_for_daemon_cancellation: read 0x%x from daemon, expected 0x%x\n",
+ flag, GUESTFS_CANCEL_FLAG);
+ return 0;
+ }
+
+ return 1;
+}
+
+/* Synchronously receive a file. */
+
+/* Returns -1 = error, 0 = EOF, 1 = more data */
+static int receive_file_data_sync (guestfs_h *g, void **buf, int *len);