summaryrefslogtreecommitdiffstats
path: root/sockutil.c
diff options
context:
space:
mode:
authorNathan Straz <nstraz@redhat.com>2013-08-01 01:58:09 -0400
committerNathan Straz <nstraz@redhat.com>2013-09-11 17:33:17 -0400
commitbbceec6030f8501ce129a93980c0f2e045cce562 (patch)
tree025006d9d7dbc7808065dc2f78671eda725a2042 /sockutil.c
parent063f117b1dbe3868bcfe1933967d2a665b3de0db (diff)
downloadqarsh-bbceec6030f8501ce129a93980c0f2e045cce562.tar.gz
qarsh-bbceec6030f8501ce129a93980c0f2e045cce562.tar.xz
qarsh-bbceec6030f8501ce129a93980c0f2e045cce562.zip
Rewrite qptostr to store binary bits into an existing buffer
Diffstat (limited to 'sockutil.c')
-rw-r--r--sockutil.c22
1 files changed, 11 insertions, 11 deletions
diff --git a/sockutil.c b/sockutil.c
index 4ccca03..954297a 100644
--- a/sockutil.c
+++ b/sockutil.c
@@ -255,21 +255,21 @@ recv_read:
int
send_packet(int fd, struct qa_packet *qp)
{
- char *packetbuf;
- int packetsize;
+ Buffer pb = { "", 0, 0};
uint32_t netsize;
- ssize_t ret;
+ ssize_t ret = -1;
struct iovec iovs[2];
- packetbuf = qptostr(qp, &packetbuf, &packetsize);
+ pb.end = qptostr(qp, pb.buf, QARSH_MAX_PACKET_SIZE - sizeof netsize);
- netsize = htonl(packetsize);
- iovs[0].iov_base = &netsize;
- iovs[0].iov_len = sizeof netsize;
- iovs[1].iov_base = packetbuf;
- iovs[1].iov_len = packetsize;
+ if (pb.end > 0) {
+ netsize = htonl(pb.end);
+ iovs[0].iov_base = &netsize;
+ iovs[0].iov_len = sizeof netsize;
+ iovs[1].iov_base = pb.buf;
+ iovs[1].iov_len = pb.end;
- ret = writev(fd, iovs, 2);
- free(packetbuf);
+ ret = writev(fd, iovs, 2);
+ }
return ret;
}