summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--qacp.c32
1 files changed, 17 insertions, 15 deletions
diff --git a/qacp.c b/qacp.c
index 39fffba..f441e07 100644
--- a/qacp.c
+++ b/qacp.c
@@ -259,7 +259,7 @@ qacp_recvonefile(const char *host, const char *srcfile, const char *destfile)
struct qa_packet *qp;
struct qa_packet *rp;
int outfd;
- ssize_t nwrote;
+ ssize_t ret, nwrote;
struct qp_rstat_pkt *rstatp;
int rstaterrno;
fd_set rfds;
@@ -317,20 +317,22 @@ qacp_recvonefile(const char *host, const char *srcfile, const char *destfile)
if (qp->qp_data.qp_count == 0) {
break;
}
- if ((nwrote = write(outfd, qp->qp_data.qp_blob, qp->qp_data.qp_count)) == -1) {
- fprintf(stderr, "write() error: %s\n", strerror(errno));
- rp = make_qp_returncode(-1, errno, strerror(errno));
- send_packet(qacp_fd, rp);
- qpfree(rp);
- break;
- } else if (nwrote == qp->qp_data.qp_count) {
- rp = make_qp_data_allow(0, nwrote);
- send_packet(qacp_fd, rp);
- qpfree(rp);
- } else {
- fprintf(stderr, "short write\n");
- break;
- }
+ nwrote = 0;
+ do {
+ ret = write(outfd, qp->qp_data.qp_blob, qp->qp_data.qp_count);
+ if (ret < 0) {
+ fprintf(stderr, "write() error: %s\n", strerror(errno));
+ rp = make_qp_returncode(-1, errno, strerror(errno));
+ send_packet(qacp_fd, rp);
+ qpfree(rp);
+ break;
+ }
+ nwrote += ret;
+ } while (nwrote < qp->qp_data.qp_count);
+
+ rp = make_qp_data_allow(0, nwrote);
+ send_packet(qacp_fd, rp);
+ qpfree(rp);
} else if (qp->qp_type == QP_RETURNCODE) {
if (qp->qp_returncode.qp_rc == 0) { /* success */
break;