summaryrefslogtreecommitdiffstats
path: root/sockutil.c
diff options
context:
space:
mode:
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;
}