diff options
author | Nathan Straz <nstraz@redhat.com> | 2013-08-13 16:53:37 -0400 |
---|---|---|
committer | Nathan Straz <nstraz@redhat.com> | 2013-09-11 17:49:18 -0400 |
commit | 0fbaf9ea5bdd6b7a347d09dc4bb135cc777c7543 (patch) | |
tree | a5ae55c2b888325c702fb4639e30769c6162a90d /qarshd.c | |
parent | 5be1f6c7a3dbfd172c243a08d9f46867b3ca413f (diff) | |
download | qarsh-0fbaf9ea5bdd6b7a347d09dc4bb135cc777c7543.tar.gz qarsh-0fbaf9ea5bdd6b7a347d09dc4bb135cc777c7543.tar.xz qarsh-0fbaf9ea5bdd6b7a347d09dc4bb135cc777c7543.zip |
Get qacp remote to local working
Diffstat (limited to 'qarshd.c')
-rw-r--r-- | qarshd.c | 59 |
1 files changed, 35 insertions, 24 deletions
@@ -181,45 +181,57 @@ receive_data(struct remotefd *rfd, struct qa_packet *qp) } ssize_t -pushfile(const char *path, int of_port) +pushfile(const char *path, int remfd) { - int outsd; int infd; - off_t offset = 0; - ssize_t nbytes; + off_t offset; + ssize_t nbytes, fsize = 0; struct stat sb; - - outsd = connect_to_peer(&peername, of_port); - if (outsd == -1) { - syslog(LOG_WARNING, "Connect to of_port (%d) failed: %s\n", - of_port, strerror(errno)); - return -1; - } + const int bufsize = 16384; + char buf[bufsize]; + struct qa_packet *qp; infd = open(path, O_RDONLY); if (infd == -1) { syslog(LOG_WARNING, "Could not open %s: %s\n", path, strerror(errno)); - close(outsd); return -1; } - if (strcmp(saved_path, path) == 0) { - nbytes = sendfile(outsd, infd, &offset, saved_stat.st_size); - } else if (fstat(infd, &sb) < 0) { - syslog(LOG_WARNING, "Could not stat %s: %s\n", - path, strerror(errno)); + if (strcmp(saved_path, path)) { + if (fstat(infd, &sb) < 0) { + syslog(LOG_WARNING, "Could not stat %s: %s\n", + path, strerror(errno)); + close(infd); + return -1; + } else { + fsize = sb.st_size; + } + } else { + fsize = saved_stat.st_size; + } + if (!fsize) { + fprintf(stderr, "Unknown file size to send\n"); close(infd); - close(outsd); return -1; - } else { /* fstat filled in sb */ - nbytes = sendfile(outsd, infd, &offset, sb.st_size); } + offset = 0; + do { + nbytes = read(infd, buf, bufsize); + if (nbytes < 0) { + fprintf(stderr, "read() error: %s\n", strerror(errno)); + qp = make_qp_returncode(-1, errno, strerror(errno)); + } else { + qp = make_qp_data(remfd, offset, nbytes, buf); + } + send_packet(fileno(stdout), qp); + offset += nbytes; + qpfree(qp); + } while (nbytes > 0); close(infd); - close(outsd); - return nbytes; + return offset; } void @@ -342,8 +354,7 @@ handle_packets(int infd) } break; case QP_SENDFILE: - syslog(LOG_INFO, "Got a QP_SENDFILE with path = %s, " - "remfd = %d\n", + syslog(LOG_INFO, "Sending file %s, remfd = %d\n", qp->qp_sendfile.qp_path, qp->qp_sendfile.qp_remfd); nbytes = pushfile(qp->qp_sendfile.qp_path, |