summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--sockutil.c35
1 files changed, 24 insertions, 11 deletions
diff --git a/sockutil.c b/sockutil.c
index c180eb3..a86290d 100644
--- a/sockutil.c
+++ b/sockutil.c
@@ -143,23 +143,36 @@ int
send_packet(int fd, struct qa_packet *qp)
{
char buf[QARSH_MAX_PACKET_SIZE];
- uint32_t netsize;
+ uint32_t packetsize;
+ void *psbuf = &packetsize;
int len;
ssize_t ret = -1;
- struct iovec iovs[2];
+ int bufused = 0;
qp->qp_seq = packet_seq++;
- len = qptostr(qp, buf, QARSH_MAX_PACKET_SIZE - sizeof netsize);
+ len = qptostr(qp, buf, QARSH_MAX_PACKET_SIZE - sizeof packetsize);
- if (len > 0) {
- netsize = htonl(len);
- iovs[0].iov_base = &netsize;
- iovs[0].iov_len = sizeof netsize;
- iovs[1].iov_base = buf;
- iovs[1].iov_len = len;
+ if (len == 0) return 0;
+
+ packetsize = htonl(len);
+
+ do {
+ if ((ret = write(fd, (char *)psbuf+bufused, sizeof packetsize - bufused)) < 0) {
+ lprintf(LOG_ERR, "Write error while sending packet size: %s\n", strerror(errno));
+ return -1;
+ }
+ bufused += ret;
+ } while (bufused < sizeof packetsize);
+
+ bufused = 0;
+ do {
+ if ((ret = write(fd, buf+bufused, len - bufused)) < 0) {
+ lprintf(LOG_ERR, "Write error while sending packet data: %s\n", strerror(errno));
+ return -1;
+ }
+ bufused += ret;
+ } while (bufused < len);
- ret = writev(fd, iovs, 2);
- }
return ret;
}