summaryrefslogtreecommitdiffstats
path: root/qacp.c
diff options
context:
space:
mode:
authorNathan Straz <nstraz@redhat.com>2013-08-13 16:53:37 -0400
committerNathan Straz <nstraz@redhat.com>2013-09-11 17:49:18 -0400
commit0fbaf9ea5bdd6b7a347d09dc4bb135cc777c7543 (patch)
treea5ae55c2b888325c702fb4639e30769c6162a90d /qacp.c
parent5be1f6c7a3dbfd172c243a08d9f46867b3ca413f (diff)
downloadqarsh-0fbaf9ea5bdd6b7a347d09dc4bb135cc777c7543.tar.gz
qarsh-0fbaf9ea5bdd6b7a347d09dc4bb135cc777c7543.tar.xz
qarsh-0fbaf9ea5bdd6b7a347d09dc4bb135cc777c7543.zip
Get qacp remote to local working
Diffstat (limited to 'qacp.c')
-rw-r--r--qacp.c48
1 files changed, 19 insertions, 29 deletions
diff --git a/qacp.c b/qacp.c
index 63cedf9..db6fb90 100644
--- a/qacp.c
+++ b/qacp.c
@@ -30,6 +30,7 @@
#include <unistd.h>
#include <fcntl.h>
#include <errno.h>
+#include <assert.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <sys/socket.h>
@@ -186,6 +187,7 @@ qacp_sendonefile(const char *host, const char *srcfile, const char *destfile)
}
send_packet(qacp_fd, qp);
offset += nbytes;
+ qpfree(qp);
} while (nbytes > 0);
sendone_failure:
@@ -219,14 +221,8 @@ void
qacp_recvonefile(const char *host, const char *srcfile, const char *destfile)
{
struct qa_packet *qp;
- struct sockaddr_in daddr;
- socklen_t dlen;
- int sd;
- int port;
- int insd;
int outfd;
- char buf[BUFSIZ];
- ssize_t nread, nwrote;
+ ssize_t nwrote;
off_t nleft;
struct qp_rstat_pkt *rstatp;
int rstaterrno;
@@ -245,38 +241,35 @@ qacp_recvonefile(const char *host, const char *srcfile, const char *destfile)
fchmod(outfd, rstatp->qp_st_mode);
- sd = bind_any(QARSH_MINPORT, qarsh_ss_family);
- port = getsockport(sd);
-
/* Recall that the packet types are qarshd-centric, so if we want
* to recv a file from the host running qarshd we have to tell
* qarshd to send a file. */
- qp = make_qp_sendfile(srcfile, port);
+ qp = make_qp_sendfile(srcfile, outfd);
send_packet(qacp_fd, qp);
qpfree(qp);
- dlen = sizeof daddr;
- insd = accept(sd, (struct sockaddr *) &daddr, &dlen);
-
/* Read/write file */
nleft = rstatp->qp_st_size;
while (nleft > 0) {
- nread = read(insd, buf, BUFSIZ);
- if (nread < 0) {
- fprintf(stderr, "read() error: %s\n", strerror(errno));
- break;
- } else if (nread == 0) { /* EOF */
- break;
- }
-
- nwrote = write(outfd, buf, nread);
- if (nwrote < 0) {
- fprintf(stderr, "write() error: %s\n", strerror(errno));
+ qp = recv_packet(qacp_fd);
+ if (qp) {
+ assert(qp->qp_type == QP_DATA);
+ assert(qp->qp_data.qp_remfd == outfd);
+ assert(rstatp->qp_st_size - nleft == qp->qp_data.qp_offset);
+ nwrote = write(outfd, qp->qp_data.qp_blob, qp->qp_data.qp_count);
+ if (nwrote < 0) {
+ fprintf(stderr, "write() error: %s\n", strerror(errno));
+ break;
+ }
+ assert(nwrote == qp->qp_data.qp_count);
+ nleft -= qp->qp_data.qp_count;
+ qpfree(qp);
+ } else {
+ fprintf(stderr, "Did not receive a packet\n");
break;
}
- nleft -= nread;
}
if (nleft != 0) {
@@ -286,9 +279,6 @@ qacp_recvonefile(const char *host, const char *srcfile, const char *destfile)
(long long int)nleft,
(long long int)rstatp->qp_st_size);
}
-
- close(sd);
- close(insd);
close(outfd);
/* Await our return code from qarshd */